#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# based on the sample debian/rules file for GNU hello by Ian Jackson.

package=illuminator

stamp-configure:
	dh_testdir
	./configure --prefix=/usr
	touch $@

build: stamp-configure
	dh_testdir
	$(MAKE)
	touch $@

clean:
	dh_testdir
	rm -f stamp-configure build debian/libluminate-dev.substvars
	if [ -e Makefile ]; then $(MAKE) distclean; fi
	make debian/rules
	chmod +x debian/rules
	rm -rf illuminator illuminator-doc-0.11.0
	dh_clean

stamp-doc: stamp-configure
	$(MAKE) $@
	rm -f illuminator-doc-0.11.0/illuminator.ps \
	  `find illuminator-doc-0.11.0 -empty -print`
	sed s/pdf/pdf.gz/ < illuminator-doc-0.11.0/index.html > illuminator-doc-0.11.0/index.html.new
	mv -f illuminator-doc-0.11.0/index.html.new illuminator-doc-0.11.0/index.html
	sed s/dvi/dvi.gz/ < illuminator-doc-0.11.0/index.html > illuminator-doc-0.11.0/index.html.new
	mv -f illuminator-doc-0.11.0/index.html.new illuminator-doc-0.11.0/index.html
	grep -v ">PostScript<" illuminator-doc-0.11.0/index.html > illuminator-doc-0.11.0/index.html.new
	mv -f illuminator-doc-0.11.0/index.html.new illuminator-doc-0.11.0/index.html

binary-indep: stamp-doc
	dh_testdir -i
	dh_testroot -i
	dh_installdirs -i
	dh_installdocs -i
	dh_installchangelogs -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

install: build
	$(MAKE) install prefix=`pwd`/debian/tmp/usr

binary-arch: install
	dh_testdir -a
	dh_testroot -a
	# Generate petsc-dev substvar (yes, this is a kludge...)
	echo petsc-dev=libpetsc`grep "define PETSC_VERSION_MAJOR" /usr/include/petsc/petscversion.h | cut -b 34-`.`grep "define PETSC_VERSION_MINOR" /usr/include/petsc/petscversion.h | cut -b 34-`.`grep "define PETSC_VERSION_SUBMINOR" /usr/include/petsc/petscversion.h | cut -b 34-`-dev > debian/libluminate-dev.substvars
	dh_installdirs -a
	dh_movefiles -a
	dh_installdocs -a
	dh_installman -pilluminator-demo 3dgf.1 chts.1 chui.1 tsview.1 tsview-ng.1
	dh_installchangelogs -a
	dh_strip -a
	dh_makeshlibs -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary: binary-indep binary-arch

.PHONY: binary binary-arch binary-indep clean checkroot
