#!/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=spooles

# Support multiple makes at once
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
NJOBS := $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
else
NJOBS := 1
endif

clean:
	dh_testdir
	for bakfile in Chv/doc/simple.eps.bak FrontMtx/doc/intro.tex.bak \
	    MPI/doc/proto.tex.bak Tree/doc/proto.tex.bak; do \
	  mv $$bakfile $$bakfile.save; \
	done
	dh_clean
	make clean
	for bakfile in `find . -name \*.save`; do \
	  mv $$bakfile `echo $$bakfile | sed s/.save//`; \
	done
	rm -f */*/*.lo libspooles.so libspooles.so.2.2
	rm -f `find . -name \*.ps | grep -v A2/doc/main.ps`
	rm -f `find . -name \*.dvi`
	rm -f stamp-*
	if [ -d .pc ]; then \
	  QUILT_PATCHES=debian/patches quilt pop -a -R || test $$? = 2; \
	  rm -rf .pc; \
	fi

stamp-patch:
	if [ ! -d .pc ]; then \
	  QUILT_PATCHES=debian/patches quilt push -a || test $$? = 2; \
	fi
#	Move aside these files so clean can restore them to their original state
	if [ ! -e A2/doc/main.log.save ]; then \
	  for bakfile in `find . -name \*.aux` `find . -name \*.log` \
	      `find . -name \*.idx` `find . -name \*.toc` \
	      `find . -name \*.lof`; do \
	    mv $$bakfile $$bakfile.save; \
	  done; \
	fi
	touch $@

build: build-arch
build-arch:stamp-build-arch
stamp-build-arch: stamp-patch
	make lib
	touch $@

build-indep: stamp-build-indep
stamp-build-indep: stamp-patch
	for texdocdir in AllInOne FrontTrees ReferenceManual; do \
	  (cd documentation/$$texdocdir; \
	   latex main; \
	   latex main; \
	   latex main; \
	   dvips main -o $$texdocdir.ps); \
	done
	for module in A2 BKL BPG Chv ChvList ChvManager Coords DSTree DV \
	    DenseMtx Drand EGraph ETree FrontMtx GPart Graph I2Ohash IIheap \
	    IV IVL Ideq InpMtx Lock MSMD Network PatchAndGoInfo Pencil Perm \
	    SemiImplMtx SolveMap SubMtx SubMtxList SubMtxManager SymbFac Tree \
	    Utilities ZV misc MPI MT Eigen LinSol; do \
	  (cd $$module/doc; \
	   latex main; \
	   latex main; \
	   latex main; \
	   dvips main -o $$module.ps); \
	done
	touch $@

install-arch: build
	dh_testdir
	install -d debian/tmp/usr/lib
	cp -a libspooles* debian/tmp/usr/lib/
	for headerfile in `find . -name \*.h -print`; do \
	  install -D $$headerfile debian/tmp/usr/include/spooles/$$headerfile;\
	done

install-indep: build-indep

binary-indep: install-indep
	dh_testdir -i
	dh_testroot -i
	dh_installdirs -i
#	dh_movefiles -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

binary-arch: install-arch
	dh_testdir -a
	dh_testroot -a
	dh_installdirs -a
	dh_movefiles -a
	dh_installdocs -a
	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 install-arch install-indep build build-arch build-indep
