#!/usr/bin/make -f
export DH_VERBOSE=1
%:
	dh $@

XUL_VERSION = $(shell pkg-config --modversion libxul | cut -d '.' -f1,2)

override_dh_auto_build:
	cd src; make -f Makefile.debian

override_dh_auto_install:
	mkdir -p debian/chmsee/usr/share/chmsee debian/chmsee/usr/lib/chmsee debian/chmsee/usr/bin debian/chmsee/usr/share/applications
	cp -r application.ini chrome.manifest chrome/ data/ defaults/ components/ debian/chmsee/usr/share/chmsee
	mv debian/chmsee/usr/share/chmsee/data/icons debian/chmsee/usr/share/icons
	chrpath -d debian/chmsee/usr/share/chmsee/components/libxpcomchm.so
	mv debian/chmsee/usr/share/chmsee/components/libxpcomchm.so debian/chmsee/usr/lib/chmsee/
	sed "s/@XUL_VERSION@/${XUL_VERSION}/g" debian/chmsee.sh > debian/chmsee/usr/bin/chmsee
	sed "s/_Name/Name/g" data/chmsee.desktop.in > debian/chmsee/usr/share/applications/chmsee.desktop
	sed -i "s/_Comment/Comment/g" debian/chmsee/usr/share/applications/chmsee.desktop

override_dh_auto_clean:
	cd src; make -f Makefile.debian clean || true

override_dh_gencontrol:
	dh_gencontrol -- -Vxulrunner-binversion="xulrunner-${XUL_VERSION}"

# to re-generate debian/control, invoke
# fakeroot debian/rules debian/control DEB_AUTO_UPDATE_DEBIAN_CONTROL:=yes

#include /usr/share/cdbs/1/rules/debhelper.mk
#include /usr/share/cdbs/1/class/cmake.mk
#
#INSTROOT = $(CURDIR)/debian/chmsee
#DEB_CONFIGURE_SCRIPT_ENV += LDFLAGS=" -Wl,--as-needed"
#DEB_CONFIGURE_EXTRA_FLAGS += --with-gecko=libxul
#DEB_INSTALL_CHANGELOGS_ALL += ChangeLog
#
## copy from /usr/share/cdbs/1/class/gnome.mk
#clean::
#	cd $(DEB_BUILDDIR) && \
#	  rm -f intltool-extract intltool-merge intltool-update po/.intltool-merge-cache; \
#	  if test -d doc; then find doc -name '*.omf.out' -exec rm -f \{\} \; ; fi; \
#	  if test -d help; then find help -name '*.omf.out' -exec rm -f \{\} \; ; fi
#
#binary-predeb/chmsee::
#	dh_xulrunner -pchmsee
