#!/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.

# Select EXT and FC variables before building the package 
#
#    for Fujitsu Fortran Compiler
export EXT=ffc5
export FC=frt

#    for Intel Fortran Compiler
#export EXT=ifc
#export EXT=ifc6
#export EXT=ifc7
#export EXT=ifc7.1
#export EXT=ifc8
#export FC=ifc
#export FC=ifort

package=spml-$(EXT)
docpackage=spml-doc

build:
	$(checkdir)
	cp debian/control.$(EXT) debian/control
	./configure --with-ispack=/usr/lib/libisp-$(EXT).a --with-netcdf=/usr/lib/libnetcdf-$(EXT).a --with-gt4f90io=/usr/lib/gt4f90io-$(EXT)/lib/libgt4f90io.a --with-dclf90config=/usr/lib/dcl-5.2-$(EXT)/bin/dclf90config --prefix=/usr/lib/spml-$(EXT) 
	$(MAKE) 
	touch build

clean:
	$(checkdir)
	-rm -f build
	-$(MAKE) distclean
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp debian/tmp-doc debian/files* core debian/substvars
	-rm -rf debian/*.debhelper

binary-indep: checkroot build
	$(checkdir)
# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.
#	install -d debian/tmp-doc/usr/share/doc/spml-doc/
	dh_installdocs -p$(docpackage) -Pdebian/tmp-doc doc demo MEMO README
	dh_installchangelogs -p$(docpackage) -Pdebian/tmp-doc CHANGELOG 
	dh_installdeb -p$(docpackage) -Pdebian/tmp-doc
	dpkg-gencontrol -isp -p$(docpackage) -Pdebian/tmp-doc
	chown -R root.root debian/tmp-doc
	chmod -R go=rX debian/tmp-doc
	dpkg --build debian/tmp-doc ..

binary-arch: checkroot build
	$(checkdir)
	-rm -rf debian/tmp
	install -d debian/tmp
	cd debian/tmp && install -d `cat ../dirs`
	$(MAKE) install DESTDIR=`pwd`/debian/tmp
	dh_link usr/lib/spml-$(EXT)/bin/spmfrt   usr/bin/spmfrt.$(EXT)
# Must have debmake installed for this to work. Otherwise please copy
# /usr/bin/debstd into the debian directory and change debstd to debian/debstd
	#debstd 
	dh_installdocs -p$(package) -Pdebian/tmp 
	dh_strip -p$(package) -Pdebian/tmp
	dh_compress -p$(package) -Pdebian/tmp
	dh_fixperms -p$(package) -Pdebian/tmp
	dh_installdeb -p$(package) -Pdebian/tmp
	dpkg-gencontrol -isp -p$(package) -Pdebian/tmp
	chown -R root.root debian/tmp
	chmod -R go=rX debian/tmp
	dpkg --build debian/tmp ..

define checkdir
	test -f debian/rules
endef

binary: binary-arch binary-indep 

checkroot:
	$(checkdir)
	test root = "`whoami`"

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