#!/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 -*-

# 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

hive_pkg_name=hive

%:
	dh $@

override_dh_auto_build:
	mkdir -p /tmp/debian-hive/.ivy
	bash debian/do-component-build
	touch $@

.PHONY: server2
.PHONY: metastore
.PHONY: hcatalog-server
.PHONY: webhcat-server
server2 metastore hcatalog-server webhcat-server:
	bash debian/init.d.tmpl debian/hive-$@.svc deb debian/${hive_pkg_name}-$@.init

override_dh_strip_nondeterminism:
	# This step is part of https://wiki.debian.org/ReproducibleBuilds
	# Due to some big jars, the build times are 4/5x higher compared
	# to a normal build. The aim of the project is really valuable
	# so we should re-enable this at some point in the future,
	# but for now it is better to concentrate on the rest of the packaging.

override_dh_auto_install: server2 metastore hcatalog-server webhcat-server
	cp debian/hive-site.xml .
	cp debian/hive.1 .
	cp debian/hive-hcatalog.1 .
	bash debian/install_hive.sh \
	  --prefix=debian/tmp \
	  --build-dir=build/dist \
	  --doc-dir=/usr/share/doc/${hive_pkg_name}
	# We need to get rid of jars that happen to be shipped in other CDH packages
	rm -f debian/tmp/usr/lib/hive/lib/hbase-*.jar debian/tmp/usr/lib/hive/lib/zookeeper-*.jar
	ln -s /usr/lib/hbase/hbase-common.jar /usr/lib/hbase/hbase-client.jar /usr/lib/hbase/hbase-hadoop-compat.jar /usr/lib/hbase/hbase-hadoop2-compat.jar debian/tmp/usr/lib/hive/lib
	ln -s /usr/lib/hbase/hbase-procedure.jar /usr/lib/hbase/hbase-protocol.jar /usr/lib/hbase/hbase-server.jar debian/tmp/usr/lib/hive/lib/
	ln -s /usr/lib/zookeeper/zookeeper.jar debian/tmp/usr/lib/hive/lib
	ln -s /usr/lib/zookeeper/zookeeper-jute.jar debian/tmp/usr/lib/hive/lib
	# Workaround for BIGTOP-583
	rm -f debian/tmp/usr/lib/hive/lib/slf4j-log4j12-*.jar
	bash debian/build-hive-install-file.sh >> debian/hive.install
