#!/usr/bin/make -f

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

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk


build: build-arch build-indep

build-arch: build-arch-stamp
build-arch-stamp:
	dh_testdir
# 	Add here commands to compile the package.
	rm -f SWIG/KikiPy_wrap.cpp #force regeneration of SWIG bindings
	make -C kodilib/linux
	make -C linux \
		PYTHON_INCLUDES="$(shell python2-config --includes)" \
		PYTHONLIBS="$(shell python2-config --libs)"
	rm -f py/kiki.py
	touch $@

build-indep: build-indep-stamp
build-indep-stamp:
	dh_testdir
	oggenc --serial 0 sound/*.wav
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp patch-stamp
# 	Add here commands to clean up after the build process.
	make -C linux clean
	make -C kodilib/linux clean
	rm -f py/kiki.py SWIG/kiki.py SWIG/KikiPy_wrap.cpp
	rm -f sound/*.ogg
	dh_clean


install: install-indep install-arch

install-indep: build
	dh_testdir
	dh_testroot
	dh_prep -i
	dh_installdirs -i
	dh_install -i

install-arch: build
	dh_testdir
	dh_testroot
	dh_prep -a
	dh_installdirs -a
	install linux/kiki debian/kiki-the-nano-bot/usr/games/kiki-the-nano-bot
	dh_install -a


binary: binary-indep binary-arch

binary-indep: build install
	dh_testdir -i
	dh_testroot -i
	dh_installchangelogs -i
	dh_installdocs -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary-arch: build install
	dh_testdir -a
	dh_testroot -a
	dh_installchangelogs -a
	dh_installdocs -a
	dh_installmenu -a
	dh_installman -a debian/kiki-the-nano-bot.6
#	python stuff meeded?
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a


get-orig-source: VERSION=1.0.2

get-orig-source:
	dh_testdir
	dh_testroot
	wget http://switch.dl.sourceforge.net/sourceforge/kiki/kiki-$(VERSION)-src.tgz
	tar xfz kiki-$(VERSION)-src.tgz
	rm -f kiki/*.dll
	rm -rf kiki/py_crippled
	find kiki -type f -print0 | xargs -0 chmod -x
	rm -f ../kiki-the-nano-bot-$(VERSION)+dfsg1.orig.tar.gz
	tar cfz ../kiki-the-nano-bot-$(VERSION)+dfsg1.orig.tar.gz kiki/*
	rm -rf kiki kiki-$(VERSION)-src.tgz


.PHONY: build clean binary-indep binary-arch binary install patch get-orig-source
