#!/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)
HOST_MULTIARCH ?= $(shell gcc -print-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.04
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
export DIST_INCLUDE_DIR := "build/$(OS)/$(CPU)/$(VARIANT)/dist/common/inc"
export APP_COMMON_DIR := /usr/bin

%:
	dh $@

override_dh_auto_build:
	mkdir -p $(DIST_INCLUDE_DIR)
	cp /usr/include/$(HOST_MULTIARCH)/alljoyn/Status.h $(DIST_INCLUDE_DIR)

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

override_dh_auto_clean:
	rm -f .sconsign.dblite
	rm -rf .sconf_temp
	touch ./to-be.removed-now.md5
	find ./* |grep '\.md5'|xargs rm
	rm -rf build
	dh_auto_clean

override_dh_installchangelogs:
	dh_installchangelogs ReleaseNotes.txt
	dh_installchangelogs

override_dh_install:
	dh_install
#	# improve stuff
#	chmod 644 debian/alljoyn-services-1504/etc/alljoyn/*.conf
