#!/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 --nocache --prefix=/usr --cflags="$(CFLAGS)" configure $(ml_opt)
	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir

	# Add here commands to compile the package.
	./waf --nocache --cflags="$(CFLAGS)" 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/tear.1

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	# Add here commands to install the package into debian/tear.
	./waf --nocache --cflags="$(CFLAGS)" --destdir=$(CURDIR)/debian/tear install
	dh_install #Installs files not covered by waf. Look at debian/install for the files installed by this command.
	#chmod -x debian/tear/usr/share/applications/hildon/tear.desktop debian/tear/usr/share/tear/tear_empty_star.png debian/tear/usr/share/tear/tear_full_star.png #Suppress lintian warning of +x on files that don't need it. 


# 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/tear.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
	- maemo-optify
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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