#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

# This is the debhelper compatability version to use.
export DH_COMPAT=3

# To build against Mozilla CVS packages, use
# debian/rules binary MOZILLACVS=1
ifneq ($(MOZILLACVS),)
ifneq ($(shell dpkg -l mozilla-cvs-dev 2>/dev/null),)
mozilla_cvs=-cvs
else
$(error MOZILLACVS=1 specified but mozilla-cvs-dev package isn't installed)
endif
endif

mozilla_ver=$(shell dpkg -s mozilla-browser$(mozilla_cvs) | awk '{if($$0~/^Version:/)print$$2}')
mozilla_libs=/usr/lib/mozilla$(mozilla_cvs)
mozilla_includes=/usr/include/mozilla$(mozilla_cvs)

configcmd=$(shell if [ -x configure ]; then printf configure; elif [ -x autogen.sh ]; then printf autogen.sh; fi)
ifeq ($(configcmd),)
$(error neither configure nor autogen.sh found)
endif
cleantarget=$(shell [ -x autogen.sh ] && printf maintainer-clean || printf distclean)

configopts=--prefix=/usr \
	--sysconfdir=/etc --mandir=\$${prefix}/share/man \
	--disable-install-schemas \
	--enable-gnome-file-selector --enable-nautilus-view \
	--with-nspr-prefix=$(mozilla_libs) \
	--with-mozilla-libs=$(mozilla_libs) \
	--with-mozilla-includes=$(mozilla_includes) \
	--with-mozilla-home=$(mozilla_libs)
	
configure: configure-stamp
configure-stamp:
	dh_testdir

	./$(configcmd) $(configopts)

	@for m in `find . -name Makefile -a -size 0`; do \
		printf "all:\ninstall:\nclean:\n\trm -f Makefile\ndistclean: clean\nmaintainer-clean: clean\n" >$$m; done

	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	$(MAKE)

	touch build-stamp

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

	$(MAKE) $(cleantarget)

	dh_clean README.Themes

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) install prefix=`pwd`/debian/galeon-cvs/usr sysconfdir=`pwd`/debian/galeon-cvs/etc
	install -m 644 -o root -g root `pwd`/galeon.schemas `pwd`/debian/galeon-cvs/etc/gconf/schemas
	install -m 644 -o root -g root debian/Lintian.overrides debian/galeon-cvs/usr/share/lintian/overrides/galeon-cvs
	install -m 644 -o root -g root themes/README README.Themes

# Build architecture-independent files here.
binary-indep: build install

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_undocumented galeon-config-tool.1
	dh_installmenu
	dh_installmime
	dh_installchangelogs ChangeLog
	dh_link usr/share/man/man1/galeon.1.gz usr/share/man/man1/galeon-bin.1.gz
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	echo "mozilla:Depends=mozilla-browser$(mozilla_cvs) (>= $(mozilla_ver))" >> debian/galeon-cvs.substvars
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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