#!/usr/bin/make -f
# You must remove unused comment lines for the released package.
#export DH_VERBOSE = 1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
export JAVA_HOME=/usr/lib/jvm/default-java
export CLASSPATH=/usr/share/java/csv.jar:/usr/share/java/debug-disable.jar:/usr/share/java/itext.jar
export GTEST_DIR=/usr/src/gtest

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

CPU=$(shell dpkg-architecture -qDEB_HOST_GNU_CPU)
# mapping i386 to x86 for Alljoyn
ifeq ($(CPU),i686) 
  export CPU = "x86"
endif
# we need to check the CPU and do not conflict with
# the already existing "arm" for cross compiling
# TODO: check whether this is ok for armel and armhf
ifeq ($(CPU),arm) 
  export CPU = "armhf"
endif
OS=linux

export VERSION := 15.04b
export SONAME := 1504
export VARIANT := release
export SCONS_ARGS := CPU=$(CPU) OS=$(OS) VARIANT=$(VARIANT) V=1 GTEST_DIR=$(GTEST_DIR)
export BUILD_DIR := $(CURDIR)/build/$(OS)/$(CPU)/$(VARIANT)/dist
export OBJ_DIR := $(CURDIR)/build/$(OS)/$(CPU)/$(VARIANT)/obj

%:
#	dh $@ --with javahelper
	dh $@ --with systemd

override_dh_auto_build:
#XXX does not build yet
#	scons BINDINGS=java $(SCONS_ARGS) \
#		WS=off BT=off ICE=off 

	dpkg-architecture -l

	scons BINDINGS=c $(SCONS_ARGS) \
		WS=off BT=off ICE=off 

	scons BINDINGS=cpp $(SCONS_ARGS) \
		WS=off BT=off ICE=off 

# not able to build js bindings yet:
# "Must specify either GECKO_BASE or CORDOVA_BASE build variable"
#	scons BINDINGS=js $(SCONS_ARGS) \
#		WS=off BT=off ICE=off 

#	scons BINDINGS=c $(SCONS_ARGS) \
#		WS=off BT=off ICE=off DOCS=html
#	scons BINDINGS=c $(SCONS_ARGS) \
#		WS=off BT=off ICE=off DOCS=pdf

	touch ./to-be.removed-now.md5
	find ./* |grep '\.md5'|xargs rm

	dh_auto_build
	ls -l $(BUILD_DIR)/..

override_dh_auto_clean:
	rm -f .sconsign.dblite
	rm -rf .sconf_temp
	rm -f config.log
	rm -rf build
	touch ./build_core/to-be-removed-now.pyc
	find ./build_core/* -print|grep "\.pyc"|xargs rm
	touch ./to-be.removed-now.md5
	find ./* |grep '\.md5'|xargs rm
	rm -f alljoyn_c/inc/alljoyn_c/DBusStdDefines.h
	rm -f alljoyn_c/inc/alljoyn_c/Status.h
	rm -f alljoyn_c/inc/qcc/posix/platform_types.h
	rm -rf build
	dh_auto_clean

override_dh_auto_test:
	./build/$(OS)/$(CPU)/$(VARIANT)/test/cpp/bin/cmtest
	dh_auto_test

override_dh_installchangelogs:
	dh_installchangelogs alljoyn_core/docs/ReleaseNotes.txt
	dh_installchangelogs 

blubber:
	rm -f alljoyn_java/bin/jar/alljoyn.jar
	rm -f alljoyn_java/bin/libs/liballjoyn_java.so
	rm -f alljoyn_java/bin/libs/liballjoyn_java.so
	rm -f alljoyn_java/samples/java/JavaSDKDoc/JavaSDKDocIntrospectWithDescriptionClient/MANIFEST.MF
	rm -f alljoyn_java/samples/java/JavaSDKDoc/JavaSDKDocIntrospectWithDescriptionService/MANIFEST.MF
	rm -f alljoyn_java/samples/java/JavaSDKDoc/JavaSDKDocMethodsClient/MANIFEST.MF
	rm -f alljoyn_java/samples/java/JavaSDKDoc/JavaSDKDocMethodsService/MANIFEST.MF
	rm -f alljoyn_java/samples/java/JavaSDKDoc/JavaSDKDocPropertiesClient/MANIFEST.MF
	rm -f alljoyn_java/samples/java/JavaSDKDoc/JavaSDKDocPropertiesService/MANIFEST.MF
	rm -f alljoyn_java/samples/java/JavaSDKDoc/JavaSDKDocSecurityLogonClient/MANIFEST.MF
	rm -f alljoyn_java/samples/java/JavaSDKDoc/JavaSDKDocSecurityLogonService/MANIFEST.MF
	rm -f alljoyn_java/samples/java/JavaSDKDoc/JavaSDKDocSecuritySRPClient/MANIFEST.MF
	rm -f alljoyn_java/samples/java/JavaSDKDoc/JavaSDKDocSecuritySRPService/MANIFEST.MF
	rm -f alljoyn_java/samples/java/JavaSDKDoc/JavaSDKDocSignalClient/MANIFEST.MF
	rm -f alljoyn_java/samples/java/JavaSDKDoc/JavaSDKDocSignalService/MANIFEST.MF
	rm -f alljoyn_java/src/org/alljoyn/bus/Status.java
	touch ./to-be.removed-now.pdf
	find ./* |grep '\.pdf'|xargs rm
	touch ./to-be.removed-now.md5
	find ./* |grep '\.md5'|xargs rm
	rm -rf alljoyn_core/docs/latex/*
	rm -rf alljoyn_core/docs/pdf/*

	dh_auto_clean

