#!/usr/bin/make -f
#
# 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

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

zookeeper_home=/usr/lib/zookeeper
hadoop_home=/usr/lib/hadoop
hadoop_hdfs_path=/usr/lib/hadoop-hdfs
hadoop_yarn_path=/usr/lib/hadoop-yarn
hadoop_mapreduce_path=/usr/lib/hadoop-mapreduce
hbase_pkg_name=hbase

%:
	dh $@

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

	
override_dh_auto_install:
	bash -x debian/install_hbase.sh \
		--build-dir=build \
		--etc-hbase=/etc/hbase \
		--doc-dir=usr/share/doc/${hbase_pkg_name}-doc \
		--prefix=debian/tmp
	mkdir -p debian/tmp/etc/security/limits.d
	cp debian/hbase.nofiles.conf debian/tmp/etc/security/limits.d/${hbase_pkg_name}.nofiles.conf
	# Symlink in the dependency jars from their packages. Both of these packages
	# provide an unversioned symlink foo.jar -> foo-0.1.2.jar.
	rm -f debian/tmp/usr/lib/${hbase_pkg_name}/lib/{hadoop,zookeeper,slf4j-log4j12-}*.jar
	ln -f -s ${zookeeper_home}/zookeeper.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${zookeeper_home}/zookeeper-jute.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${hadoop_home}/client/hadoop-annotations.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${hadoop_home}/client/hadoop-auth.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${hadoop_home}/client/hadoop-common.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${hadoop_hdfs_path}/hadoop-hdfs.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${hadoop_mapreduce_path}/hadoop-mapreduce-client-app.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${hadoop_home}/client/hadoop-mapreduce-client-common.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${hadoop_home}/client/hadoop-mapreduce-client-core.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${hadoop_home}/client/hadoop-mapreduce-client-jobclient.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${hadoop_mapreduce_path}/hadoop-mapreduce-client-shuffle.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${hadoop_home}/client/hadoop-yarn-api.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${hadoop_home}/client/hadoop-yarn-client.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${hadoop_home}/client/hadoop-yarn-common.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -f -s ${hadoop_yarn_path}/hadoop-yarn-server-common.jar debian/tmp/usr/lib/${hbase_pkg_name}/lib/
	ln -s /var/log/${hbase_pkg_name} debian/tmp/usr/lib/${hbase_pkg_name}/logs
	ln -s /var/run/${hbase_pkg_name} debian/tmp/usr/lib/${hbase_pkg_name}/pids

	# Wage war on "executable-not-elf-or-script" warnings:
	### ruby scripts should not be executable - they require
	### hbase org.jruby.Main <script>
	find debian/tmp/usr/lib/${hbase_pkg_name}/bin debian/tmp/usr/lib/${hbase_pkg_name}/lib -name \*.rb -exec chmod 644 {} \;
	### webapps should not be executable either
	find debian/tmp/usr/lib/${hbase_pkg_name}/hbase-webapps -type f -exec chmod 644 {} \;
	bash debian/install_init_scripts.sh

override_dh_strip_nondeterminism:
