#!/usr/bin/make -f
export COMPONENT_HASH=9aff20de3b5ecccf3c19d57f71b214fb4d37ee89
 HADOOP_VERSION=3.0.0+cdh6.3.2
 HADOOP_PATCHED_VERSION=3.0.0-cdh6.3.2
 HADOOP_BASE_VERSION=3.0.0
 HADOOP_RELEASE=1605554
 CDH_CUSTOMER_PATCH=p0
 CDH_PARCEL_CUSTOM_VERSION=3.0.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 -*-

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

%:
	dh $@

hadoop_version=${HADOOP_BASE_VERSION}

ifeq (${DEB_BUILD_ARCH},amd64)
  native_dir=Linux-amd64-64
endif
ifeq (${DEB_BUILD_ARCH},i386)
  native_dir=Linux-i386-32
endif

override_dh_auto_build:
	env FULL_VERSION=${HADOOP_PATCHED_VERSION} HADOOP_VERSION=${HADOOP_VERSION} HADOOP_ARCH=${native_dir} \
	    bash debian/do-component-build

hadoop_svcs=hdfs-namenode hdfs-secondarynamenode hdfs-datanode hdfs-zkfc hdfs-journalnode hdfs-nfs3\
            yarn-resourcemanager yarn-nodemanager yarn-proxyserver \
            mapreduce-historyserver httpfs \
            kms-server

$(hadoop_svcs): debian/init.d.tmpl
	bash $< debian/hadoop-$@.svc deb debian/hadoop-$@.init
	cp debian/$(firstword $(subst -, ,$@)).default debian/tmp/etc/default/hadoop-$@
	echo /etc/default/hadoop-$@ >> debian/hadoop-$@.install
	# FIXME: workaround for BIGTOP-105
	[ -f debian/hadoop-$@.postinst ] || cp debian/hadoop.daemon.postinst.tpl debian/hadoop-$@.postinst
	sed -i -e "s|@HADOOP_DAEMON@|$@|" debian/hadoop-$@.postinst

override_dh_auto_install:
	bash debian/install_hadoop.sh \
	  --prefix=debian/tmp/ \
	  --distro-dir=debian \
          --source-dir=${PWD} \
          --build-dir=${PWD}/build/hadoop-${HADOOP_PATCHED_VERSION} \
          --hadoop-version=${HADOOP_PATCHED_VERSION} \
	  --httpfs-dir=debian/tmp/usr/lib/hadoop-httpfs \
	  --httpfs-etc-dir=debian/tmp/etc/hadoop-httpfs \
	  --system-lib-dir=debian/tmp/usr/lib/ \
	  --system-libexec-dir=debian/tmp/usr/lib/hadoop/libexec/ \
	  --system-include-dir=debian/tmp/usr/include \
	  --doc-dir=debian/tmp/usr/share/doc/hadoop-doc \
          --man-dir=debian/tmp/usr/share/man \
	  --example-dir=debian/tmp/usr/share/doc/hadoop/examples \
	  --native-build-string=${native_dir} \
	  --installed-lib-dir=/usr/lib/hadoop \
	  --kms-dir=debian/tmp/usr/lib/hadoop-kms \
	  --kms-etc-dir=debian/tmp/etc/hadoop-kms
	# Forcing Zookeeper dependency to be on the packaged jar
	ln -sf /usr/lib/zookeeper/zookeeper.jar debian/tmp/usr/lib/hadoop/lib/zookeeper*.jar
	# Workaround for BIGTOP-583
	rm -f debian/tmp/usr/lib/hadoop*/lib/slf4j-log4j12-*.jar
	ln -fs /usr/lib/zookeeper/lib/slf4j-log4j12.jar debian/tmp/usr/lib/hadoop/lib/slf4j-log4j12.jar
	# FIXME: BIGTOP-463
	mkdir -p debian/tmp/etc/default
	echo 'export JSVC_HOME=/usr/lib/bigtop-utils' >> debian/hadoop.default
	cp debian/hadoop.default debian/tmp/etc/default/hadoop
	# Refactored from install-arch
	cp debian/hadoop-fuse.default debian/tmp/etc/default/hadoop-fuse
	mkdir -p debian/tmp/etc/security/limits.d
	cp debian/hdfs.conf debian/yarn.conf debian/mapreduce.conf debian/tmp/etc/security/limits.d
	# MR1 hack
	cp debian/mapreduce.conf debian/tmp/etc/security/limits.d/mapred.conf
	# Copy in defaults for KMS service
	cp debian/kms.default debian/tmp/etc/default/hadoop-kms

override_dh_install: $(hadoop_svcs)
	dh_install
	# Drop misc fuse_dfs directories
	rm -Rf debian/hadoop/usr/lib/hadoop/bin/fuse_dfs 
	rm -Rf debian/hadoop/usr/lib/hadoop/contrib/fuse-dfs
	rm -Rf debian/hadoop/usr/lib/hadoop/hdfs/contrib/fuse-dfs

override_dh_builddeb:
	dh_builddeb -- -Zgzip

override_dh_strip_nondeterminism:
	# Disable dh_strip_nondeterminism to speed up the build

override_dh_strip:
	dh_strip --no-automatic-dbgsym
