#!/usr/bin/make -f
export COMPONENT_HASH=b3393cf499504df1d2a12d34b4285e5d0c02be11
 HIVE_VERSION=2.1.1+cdh6.3.2
 HIVE_PATCHED_VERSION=2.1.1-cdh6.3.2
 HIVE_BASE_VERSION=2.1.1
 HIVE_RELEASE=1605554
 CDH_CUSTOMER_PATCH=p0
 CDH_PARCEL_CUSTOM_VERSION=2.1.1+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

hive_pkg_name=hive

%:
	dh $@

override_dh_auto_build:
	mkdir -p /tmp/debian-hive/.ivy
	env FULL_VERSION=${HIVE_PATCHED_VERSION} bash debian/do-component-build
	touch $@

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

override_dh_auto_install: server server2 metastore 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/hive-${HIVE_PATCHED_VERSION} \
	  --doc-dir=debian/tmp/usr/share/doc/${hive_pkg_name} \
	  --extra-dir=debian/

	# Workaround for BIGTOP-583
	rm -f debian/tmp/usr/lib/hive/lib/slf4j-log4j12-*.jar
	rm -vf debian/tmp/usr/lib/hive/lib/hbase-common*.jar debian/tmp/usr/lib/hive/lib/hbase-client*.jar \
     debian/tmp/usr/lib/hive/lib/hbase-server*.jar debian/tmp/usr/lib/hive/lib/hbase-hadoop-compat*.jar \
     debian/tmp/usr/lib/hive/lib/hbase-hadoop2-compat*.jar debian/tmp/usr/lib/hive/lib/hbase-protocol*.jar \
     debian/tmp/usr/lib/hive/lib/htrace-core*.jar
	bash debian/generate_install_file.sh \
	   --install-file-name=hive.install \
	   --path-to-scan=debian/tmp/usr/lib/hive/lib/ \
	   --exclude-files="hive-jdbc.install hive-hbase.install" \
	   --include-file=hive.install.include \
	   --prefix=debian/tmp


	ln -s /usr/lib/hbase/hbase-common.jar /usr/lib/hbase/hbase-client.jar /usr/lib/hbase/hbase-server.jar \
	  /usr/lib/hbase/hbase-hadoop-compat.jar /usr/lib/hbase/hbase-hadoop2-compat.jar \
	  /usr/lib/hbase/hbase-protocol.jar /usr/lib/hbase/lib/htrace-core.jar debian/tmp/usr/lib/hive/lib

	# Hive source contains a directory docs/changes that is interpreted a special way in Debian 7+ packaging
	mv docs/changes docs/changes_


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
