#!/usr/bin/make -f

tmpDirMatplotLib = $(CURDIR)/debian/matplotlib
tmpInstall = $(CURDIR)/debian/inst
CXXFLAGS := -Wall $(shell dpkg-buildflags --get CXXFLAGS)

%:
	dh $@

override_dh_auto_clean:
	rm -rf debian/build
	rm -rf doc/sphinx/_build
	rm -rf tags
	rm -f scons.*
	rm -f *.1
	rm -rf $(tmpDirMatplotLib)
	rm -rf $(tmpInstall)
	find . -name '*.pyc' -print0 | xargs -0 rm -f
	dh_clean 

override_dh_auto_configure:
	mkdir -p $(tmpDirMatplotLib)
	mkdir -p $(tmpInstall)

override_dh_auto_build:
	# remove the profile, if existing, to have clean config
	rm -f scons.*
	#Output an information about available memory and CPU
	-cat /proc/meminfo
	-cat /proc/cpuinfo
	#optimized build
	export MPLCONFIGDIR=$(tmpDirMatplotLib) HOME=$(tmpDirMatplotLib)$ ; NO_SCONS_GET_RECENT= scons profile=deb buildPrefix=debian runtimePREFIX=/usr version='' brief=0 chunkSize=2 features=vtk,gts,opengl,qt4,openmp PREFIX=$(tmpInstall) variant='' CXXFLAGS='$(CXXFLAGS)' optimize=1 -j1 march= debug=0 
	# generate manpages
	export MPLCONFIGDIR=$(tmpDirMatplotLib) HOME=$(tmpDirMatplotLib) ; YADE_PREFIX=$(tmpInstall) $(tmpInstall)/bin/yade --generate-manpage yade.1
	export MPLCONFIGDIR=$(tmpDirMatplotLib) HOME=$(tmpDirMatplotLib) ; YADE_PREFIX=$(tmpInstall) $(tmpInstall)/bin/yade-batch --generate-manpage yade-batch.1

override_dh_auto_test:
	export MPLCONFIGDIR=$(tmpDirMatplotLib) HOME=$(tmpDirMatplotLib) ; YADE_PREFIX=$(tmpInstall) $(tmpInstall)/bin/yade --test
	export MPLCONFIGDIR=$(tmpDirMatplotLib) HOME=$(tmpDirMatplotLib) ; YADE_PREFIX=$(tmpInstall) $(tmpInstall)/bin/yade --check
	#Delete all pyc files
	find . -name '*.pyc' -print0 | xargs -0 rm -f

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog

override_dh_installman:
	dh_installman -p yade yade.1 yade-batch.1

override_dh_compress:
	dh_compress --all -X.py -X.stl -X.gts -X.geo -X.mesh -X.msh -X.pdf -X.png -X.svg -X.txt -X.js -X.inv

binary-indep: 
	dh --until dh_auto_build $@
	#Generate docs
	export MPLCONFIGDIR=$(tmpDirMatplotLib) HOME=$(tmpDirMatplotLib) ; cd doc/sphinx; PYTHONPATH=. YADE_PREFIX=$(tmpInstall) $(tmpInstall)/bin/yade yadeSphinx.py;
	dh --after dh_auto_build $@
	
binary-arch: 
	dh $@

binary: binary-indep binary-arch
