#!/usr/bin/make -f
# This file was originally written by Joey Hess and Craig Small.

#export DH_VERBOSE=1

CFLAGS = -Wall -g

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

#ifneq (,$(findstring maemo-launcher,$(DEB_BUILD_OPTIONS)))
#       ml_opt := --maemo-launcher
#endif

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	./waf configure --nocache --prefix=/usr
	#$(ml_opt)
	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir

	# Add here commands to compile the package.
	./waf --nocache build -p
	#Generate manpage. Pointless as Maemo deletes it, but let's keep Lintian happy (in one way at least...). :)
	-xsltproc --nonet \
              --param make.year.ranges 1 \
              --param make.single.year.ranges 1 \
              --param man.charmap.use.subset 0 \
              -o debian/ \
              /usr/share/xml/docbook/stylesheet/nwalsh/manpages/docbook.xsl \
              debian/manpage.xml


	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	-./waf --nocache distclean
	rm -rf _build_
	rm -f debian/echognomix.1

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	# Add here commands to install the package into debian/echognomix.
	./waf install --nocache --destdir=$(CURDIR)/debian/echognomix
#	./waf dist
#	dpkg -x ../echognomix-0.1-1_armel.deb $(CURDIR)/debian/echognomix
	dh_install #Installs files not covered by waf. Look at debian/install for the files installed by this command.
	strip $(CURDIR)/debian/echognomix/usr/bin/echognomix

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	-dh_installman debian/echognomix.1
	dh_link #Adds symlinks. Look at debian/links for the links covered by this command.
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
#ifneq (,$(findstring maemo-launcher,$(DEB_BUILD_OPTIONS)))
#	dh_maemolauncher
#endif
	dh_gencontrol
	dh_md5sums
	-maemo-optify
	dh_builddeb

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