#!/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 MATRIXLIB for eigenvalue problem library subroutine. 
#
#   for SSL II 
#
export MATRIX=ssl2-
WITHMATRIX=--with-ssl2=/usr/FFC/lib/libssl2.a
export LDFLAGS=  	# ssl2 $B$@$1$G(B OK
export LDLIBS=		# ssl2 $B$@$1$G(B OK

#
#   for LAPACK
#
#export MATRIX=lapack-
#WITHMATRIX=--with-lapack=/usr/lib/liblapack.a
#export LDFLAGS=-L/usr/lib/gcc-lib/i386-linux/2.95.4  	# for LAPACK
#export LDFLAGS=-L/usr/lib/gcc-lib/i486-linux/3.3.5  	# for LAPACK
#export LDLIBS=-lblas -lg2c -lgcc			# for LAPACK
#export LDLIBS=-lblas-2 -lg2c -lgcc			# for LAPACK

#
#   not using eigenvalue problem routines
#
#export MATRIX=
#WITHMATRIX=
#export LDFLAGS=
#export LDLIBS=

######################################################################
# Select PRIORITY for the update-altenatives command. 
# This parameter is used for automatic generation of *.postinst script.
#
#export PRIORITY=10
#export PRIORITY=20
export PRIORITY=30
#export PRIORITY=50

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

export FC=frt

#export FFLAGS=-O
export FFLAGS=-Kfast -v95d,95o,95s

#
#    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

#export FFLAGS=-fast

export PACKAGEEXT=$(MATRIX)$(EXT)
package=spml-$(PACKAGEEXT)
docpackage=spml-doc

build:
	$(checkdir)
	cp debian/control.$(PACKAGEEXT) debian/control
	(cd debian ; ./spml-postinst-gen.sh ; ./spml-prerm-gen.sh)
	./configure --with-ispack=/usr/lib/libisp-$(EXT).a --with-netcdf=/usr/lib/libnetcdf-$(EXT).a --with-gt4f90io=/usr/lib/gt4f90io-$(EXT)/lib/libgt4f90io.a $(WITHMATRIX) --prefix=/usr/lib/spml-$(PACKAGEEXT)
	$(MAKE) 
	touch build

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

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/$(package)/bin/spmfrt   usr/bin/spmfrt.$(PACKAGEEXT)
# 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
