#!/usr/bin/make -f
export COMPONENT_HASH=2f4242a6c67c15054154dc3eff3a11474d94f544
 HUE_VERSION=4.2.0+cdh6.3.2
 HUE_PATCHED_VERSION=4.2.0-cdh6.3.2
 HUE_BASE_VERSION=4.2.0
 HUE_RELEASE=1605554
 CDH_CUSTOMER_PATCH=p0
 CDH_PARCEL_CUSTOM_VERSION=4.2.0+cdh6.3.2-1605554.bionic
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# -*- makefile -*-

SHELL=/bin/bash

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

#Needed so that we do not encounter 
#ERROR ld.so object 'libfakeroot-sysv.so' from LD_PRELOAD cannot be preloaded
#and
#dpkg-shlibdeps: error: couldn't find library xxx  needed by yyy
# Note: LIB_FAKEROOT - Since some debian flavors has libfakeroot and others fakeroot we need to check which one
# actually works
LIB_FAKEROOT=$(shell dirname `dpkg -L fakeroot libfakeroot 2> /dev/null | grep 'libfakeroot.*.so' | head -n 1`)
export ORACLE_HOME=/opt/toolchain/oracle_11g_instantclient
export LD_LIBRARY_PATH:=$(LD_LIBRARY_PATH):$(LIB_FAKEROOT):$(ORACLE_HOME)

# Implicit targets
SHELL := /bin/bash

APPS=$(shell find apps -maxdepth 2 -name "src" -type d|cut -d "/" -f2|sort)

%:
	dh $@

override_dh_auto_build:
	env FULL_VERSION=${HUE_PATCHED_VERSION} bash -x debian/do-component-build -Dmaven.repo.local=${HOME}/.m2/repository${M2_REPO_SUFFIX}

override_dh_auto_install: build
	bash -x debian/install_hue.sh --build-dir=${PWD}/build/release/prod/hue-${HUE_PATCHED_VERSION} --prefix=${PWD}/debian/tmp
	cp ${PWD}/build/release/prod/hue-*/README ${PWD}/
	sed -e 's,^,build:,;' debian/tmp/usr/lib/hue/Makefile.buildvars \
	  | tr _ - >> debian/hue.substvars

override_dh_installinit:
	dh_installinit --name=hue --no-start

override_dh_fixperms:
	dh_fixperms
	chown -R hue:hue /var/log/hue /var/lib/hue /usr/lib/hue || true

override_dh_auto_test:
	@echo Tests are disabled

override_dh_builddeb:
	dh_builddeb -- -Zgzip

#Added to avoid errors of form
# dpkg-shlibdeps: error: no dependency information found for /opt/toolchain/oracle_11g_instantclient/libclntsh.so.11.1
#which pop up when building the cx_oracle egg
override_dh_shlibdeps:
	dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info

override_dh_strip_nondeterminism:
	# Disable dh_strip_nondeterminism to speed up the build

override_dh_strip:
	dh_strip --no-automatic-dbgsym
