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

#EXT=ffc
#EXT=ffc3
#EXT=ffc4
#EXT=ffc5

#FC=frt
#CC=fcc
#CXX=FCC
#CPPFLAGS=-DNAGf90Fortran
#F90FLAGS=-Am

#EXT=ifc
#EXT=ifc6
#EXT=ifc7
#EXT=ifc7.1
#EXT=ifc8
EXT=ifc8.1
#export FC=ifc
export FC=ifort
export CC=gcc
export CXX=g++
export CPPFLAGS=-DNAGf90Fortran
export F90FLAGS=

package=netcdf-$(EXT)
export DESTDIR=$(shell expr `pwd`/debian/tmp/usr)


build:
	$(checkdir)
	(cd src && export CC=$(CC) FC=$(FC) CXX=$(CXX) CPPFLAGS=$(CPPFLAGS) F90FLAGS=$(F90FLAGS) ; ./configure --prefix=$(DESTDIR))
	(cd src && $(MAKE))
	touch build

clean:
	cp debian/control.$(EXT) debian/control
	$(checkdir)
	-rm -f build
	(cd src && $(MAKE) distclean)
	-rm -f `find . -name "*~"`
	-rm -rf debian/tmp debian/files* core debian/substvars
	-rm -f src/work.* src/f90/*.d src/f90/work.*

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.

binary-arch: checkroot build
	$(checkdir)
	-rm -rf debian/tmp
	install -d debian/tmp
	cd debian/tmp && install -d `cat ../dirs`
	cp src/libsrc/libnetcdf.a debian/tmp/usr/lib/libnetcdf-$(EXT).a
#	cp src/cxx/libnetcdf_c++.a debian/tmp/usr/lib/libnetcdf-$(EXT)_c++.a
#	(cd src/libsrc && $(MAKE) install)
# 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 -m -p$(package)
	(export CC=gcc ; dh_installdocs ; dh_installchangelogs ; dh_installdeb)
	dh_compress
	dpkg-gencontrol -isp -p$(package)
	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-indep binary-arch

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

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