#!/usr/bin/make -f
#Ubuntu doesn't have dh_xulrunner yet
xul:=$(shell which dh_xulrunner)
qul:=$(shell which dh_quilt_patch)
ppa:=$(shell sed -n "1s/.*~.*/yes/p" debian/changelog)

ifneq ($(qul),)
args:=quilt
else
include /usr/share/quilt/quilt.make
clean: unpatch
build: $(QUILT_STAMPFN)
endif
ifneq ($(xul),)
args:=$(args),xulrunner
endif
ifneq ($(args),)
with=--with $(args)
endif

%:
	dh $(with) --parallel $@
override_dh_auto_configure:
	./waf configure --nocache --prefix=/usr
override_dh_auto_build:
	./waf build --nocache
override_dh_auto_install:
	./waf install --nocache --destdir=debian/tmp
override_dh_strip:
	dh_strip --dbg-package=xiphos-dbg
override_dh_auto_clean:
	./waf distclean --nocache
override_dh_shlibdeps:
	dh_shlibdeps
# dh_xulrunner replacement when not available
ifeq ($(xul),)
	sed -i "s/\(shlibs:.*\)/\1, $(shell dpkg-query -W xulrunner-1.9* \
	| sed -n "/xulrunner-1.9.*-dev\t./s/\(xulrunner-1.9.*\)-dev\t.*/\1/p")/" \
	debian/xiphos.substvars
endif
override_dh_clean:
	dh_clean
	rm -rf .waf*
	rm -rf waffles/*.pyc
ifeq ($(ppa),)
	echo "3.0 (quilt)" > debian/source/format
else
	echo "1.0" > debian/source/format
endif


# build lzma compressed debs on Launchpad ;-)
override_dh_builddeb:
ifeq ($(ppa),)
	dh_builddeb
else
	dh_builddeb -- -Zlzma
endif
