#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

# export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# DPKG_EXPORT_BUILDFLAGS = 1
# include /usr/share/dpkg/buildflags.mk

export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
	dh $@ --parallel --with autotools-dev --with autoreconf 

#export OMPI_MCA_plm_rsh_agent=/bin/false  #workaround to start 
#MPI-applications in chroot
 
# # to avoid lintian warnings
#CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
# CFLAGS:=$(shell dpkg-buildflags --get CFLAGS)
# CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS)
#LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)
# 
 override_dh_auto_clean:
	dh_auto_clean
# 	rm -f config.log
# 	rm -f config-version.h config_LIB_INFO configure.param
# 	rm -f download/fftw/cxxflags
# 	rm -f download/hips/config.log download/ipopt/config.log
# 	rm -f download/metis/config.log download/metis/Makefile.in
# 	rm -f download/mumps/config.log download/mumps-seq/config.log
# 	rm -f download/parmetis/config.log
# 	rm -f download/parms/config.log download/parms/Makefile.in
# 	rm -f download/pastix/config-complex.in download/pastix/config.log
# 	rm -f download/scalapack/config.log
# 	rm -f download/scotch/config.log
# 	rm -f download/superludist/config.log
# 	rm -f download/tetgen/cxxflags
# 	cd src && rm -f medit/compil.date mpi/config.log mpi/ff-mpirun \
# 			lglib/lg.output
# 	cd DOC && rm -f cpfigs/*.pdf addfe.aux freefem++doc.aux \
# 			freefem++doc.idx freefem++doc.ilg freefem++doc.ind \
# 			freefem++doc.log freefem++doc.out \
# 			freefem++doc.pdfsync freefem++doc.toc
# 	cd examples++-load && rm -f *.ps *.txt *.mesh glu2D.mesh.gmsh \
# 					pippo.data pippo.dx triQA.msh \
# 					freefem++.pref config.log \
# 					WHERE_LIBRARY-config ipopt.out
# 	cd examples++-tutorial && rm -f A.matrix *.ps *.txt g.mesh toto.Th \
# 					*.gmsh toto.am_fmt toto.dbg lestables \
# 					freefem++.pref Th*.msh emptymesh-2.msh \
# 					th.msh toto.msh
# 	rm -f examples++/toto.txt
# 	cd examples++-3d && rm -f A.txt B.txt Th.mesh Th3.mesh dd.bb dd.meshb \
# 					freefem++.pref
# 	cd examples++-chapt3 && rm -f J.txt Th.mesh Th.msh graph.txt *.ps
	rm -rf examples++-mpi/*.so
# 	&& rm -f beam-deformed-mumps.mesh *.ps \
# 				   freefem++.pref *.so *.o

# #
# # To rebuild
# 	find . -name \*.o | xargs --no-run-if-empty rm
# 	find . -name \*.so | xargs --no-run-if-empty rm
#
 
# override_dh_autoreconf_clean:
# 	dh_autoreconf_clean
# 	dh_quilt_unpatch
# 
# override_dh_autoreconf:
# 	dh_quilt_patch
# 	dh_autoreconf --as-needed

override_dh_auto_configure:
	dh_auto_configure -- CC="gcc $(LDFLAGS)" \
			     CXX="g++ $(LDFLAGS)" \
			     MPICXX="mpic++ $(LDFLAGS)"
# 	   CPPFLAGS=$(CPPFLAGS) \
# 	   CFLAGS="$(CFLAGS) -lm" \
# 	   CXXFLAGS="$(CXXFLAGS)" \
# 	   CXX=mpic++
# 	cp -f examples++-load/WHERE_LIBRARY-config debian
# 	dh_auto_build
 
override_dh_auto_install:
	dh_auto_install
	mv debian/tmp/usr/bin/bamg debian/tmp/usr/bin/ffbamg
	rdfind -outputname debian/results.txt -makesymlinks true debian/tmp/usr/bin/
	symlinks -r -s -c debian/tmp/usr/bin/

# #
# # Install modified script to create plugins	
# 	cp examples++-load/WHERE_LIBRARY-config examples++-load/WHERE_LIBRARY
# 	cp -f debian/ff-c++ debian/tmp/usr/bin
# 	cp -f debian/ff-get-dep debian/tmp/usr/bin
# #
# # Fix lintian warnings
# 	chmod ugo-x debian/tmp/usr/lib/ff++/3.*/idp/*.idp
# 
 
 override_dh_auto_test:
#	$(MAKE) $(AM_MAKEFLAGS) -i check