#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

include /usr/share/quilt/quilt.make

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O2
else
	CFLAGS += -O2
endif

# Use hardware floating point
ifneq (,$(findstring vfp,$(DEB_BUILD_OPTIONS)))
CFLAGS += -mfpu=vfp -mfloat-abi=softfp
endif


configure: configure-stamp
configure-stamp:
	dh_testdir
	# configure the package.
	if [ \! -e bin ] ; then mkdir bin ; fi

	touch configure-stamp


build: patch build-stamp

build-stamp: configure-stamp 
	dh_testdir

	# compile the package.
	#$(MAKE) -j2
	HAWKNL_BUILTIN=1 DEBUG=0 SYSTEM_DATA_DIR=/usr/share/games CXXFLAGS="$(CFLAGS)" ./compile.sh
	#docbook-to-man debian/openlierox.sgml > openlierox.1

	touch $@

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	rm -fr debian/openlierox-tmp
	rm -fr bin/openlierox

	# clean up after the build process.
	#$(MAKE) clean #not needed? is called in pbuilder before CMake
	# we have nothing to cleanup as compile.sh doesn't generate any temp files
	# though here some cleanups for unclean orig.sources
	find . \( -name 'Thumbs.db' \
			-o -name '*.h.old' \
			-o -name '*.cpp.old' \
			\) -exec rm -f {} \;
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs -A

	#dh_installdirs -iopenlierox-tmp

	# install the package into debian/openlierox.
	mkdir -p $(CURDIR)/debian/openlierox-tmp/usr/games
	PREFIX=$(CURDIR)/debian/openlierox-tmp BIN_DIR=usr/games SYSTEM_DATA_DIR=usr/share/games ./install.sh

	install -D debian/openlierox.service $(CURDIR)/debian/openlierox-tmp/usr/share/dbus-1/services/openlierox.service
	install --mode=755 -D debian/openlierox.sh $(CURDIR)/debian/openlierox-tmp/usr/bin/openlierox
	install -D share/OpenLieroX.128.png $(CURDIR)/debian/openlierox-tmp/usr/share/icons/hicolor/scalable/apps/openlierox.png
	install -D share/OpenLieroX.32.png $(CURDIR)/debian/openlierox-tmp/usr/share/icons/hicolor/32x32/apps/openlierox.png
	install -D share/OpenLieroX.64.png $(CURDIR)/debian/openlierox-tmp/usr/share/icons/hicolor/64x64/apps/openlierox.png
	install -D share/OpenLieroX.128.png $(CURDIR)/debian/openlierox-tmp/usr/share/icons/hicolor/128x128/apps/openlierox.png
	install -D debian/openlierox.desktop $(CURDIR)/debian/openlierox-tmp/usr/share/applications/hildon/openlierox.desktop
	install -D debian/copyright $(CURDIR)/debian/openlierox-tmp/usr/share/doc/openlierox/copyright
	install -D debian/options.cfg $(CURDIR)/debian/openlierox-tmp/usr/share/games/OpenLieroX/cfg/options.cfg
	#gzip -9 -c doc/openlierox.6 > $(CURDIR)/debian/openlierox-tmp/usr/share/man/man6/openlierox.6.gz
	echo > debian/openlierox-tmp/usr/share/games/OpenLieroX/ip_to_country.csv	

	dh_install --sourcedir=debian/openlierox-tmp
	#rm -rf debian/usr/share/games

	chown -R user.root debian/openlierox-data-all/usr/share/games/OpenLieroX/*

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir -i
	dh_testroot -i
	dh_compress -i
	dh_fixperms --exclude /usr/share/games/
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i


# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir -a
	dh_testroot -a
	dh_strip -a
	dh_compress -a
	dh_fixperms -a

	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
