#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk

# Add here any variable or target overrides you need.

# Note that hdf5 dir has to be specified due to a bug into fortran/Makefile.am which causes
# skipping of fort-nc4.c without that.
#
# Remote sites could be not available at check time, so disabling some tests...
DEB_CONFIGURE_EXTRA_FLAGS := --enable-shared --enable-pic --enable-docs-install --enable-netcdf-4  --with-hdf5=/usr --with-libcf --enable-dap 
# This is useful to avoid remote Nap checks
#DEB_CONFIGURE_EXTRA_FLAGS := --enable-shared --enable-pic --enable-docs-install --enable-netcdf-4  --with-hdf5=/usr --with-libcf --enable-dap --disable-dap-remote-tests
DEB_CONFIGURE_SCRIPT_ENV += FC="gfortran"
DEB_CONFIGURE_SCRIPT_ENV += CXX="g++"
DEB_CONFIGURE_SCRIPT_ENV += CC="gcc"
DEB_CONFIGURE_SCRIPT_ENV += CPPFLAGS="-DgFortran"

# Test fails under buildds currently
DEB_MAKE_CHECK_TARGET = check

#DEB_INSTALL_CHANGELOGS_ALL = $(CURDIR)/build-tree/$(DEB_TAR_SRCDIR)/RELEASE_NOTES

# Any makebuilddir/binary would do, /source doesn't:
#makebuilddir/libnetcdf4::
#	autoreconf -vfi

install/libnetcdf7::
	find debian/tmp/usr/lib/ ! -type d -a ! -name '*.so' -a ! -name '*.a' -a ! -name '*.la' -a ! -name '*.pc' -a ! -name 'libcf*' \
			-exec cp {} debian/libnetcdf7/usr/lib/ \;

install/libcf0::
	find debian/tmp/usr/lib/ -name "libcf*" -a ! -name '*.so' -a ! -name '*.a' -a ! -name '*.la' \
			-exec cp {} debian/libcf0/usr/lib/ \;

install/libnetcdf-dev::
	cp debian/tmp/usr/include/* debian/libnetcdf-dev/usr/include/.
	install -m 644 -o root -g root  $(CURDIR)/netcdf.pc debian/libnetcdf-dev/usr/lib/pkgconfig/.
	# removes an erroneous libpath due to an upstream oversight in configure.ac
	sed -i -e 's,-L/usr ,,' -e 's,@FLIBS@,,' debian/libnetcdf-dev/usr/lib/pkgconfig/netcdf.pc
	# move links and files
	find debian/tmp/usr/lib/ -type l -a -name "libnetcdf*" -a -name '*.so' -exec cp -P {} debian/libnetcdf-dev/usr/lib/. \;
	find debian/tmp/usr/lib/ -type f -a -name "libnetcdf*" -a -name '*.a' -exec cp {} debian/libnetcdf-dev/usr/lib/. \;

install/libcf-dev::
	cp debian/tmp/usr/include/libcf.h debian/libcf-dev/usr/include/.
	# move links and files
	find debian/tmp/usr/lib/ -type l -a -name "libcf*" -a -name '*.so' -exec cp -P {} debian/libcf-dev/usr/lib/. \;
	find debian/tmp/usr/lib/ -type f -a -name "libcf*" -a -name '*.a' -exec cp {} debian/libcf-dev/usr/lib/. \;

install/netcdf-bin::
	mv debian/tmp/usr/bin/* debian/netcdf-bin/usr/bin/

install/netcdf-doc::
	install -d debian/tmp/doc
	install -d debian/tmp/usr/share/doc/netcdf
	install -d debian/tmp/usr/share/info
	install -m 644 -o root -g root $(CURDIR)/man4/*.html debian/tmp/doc/.
	install -m 644 -o root -g root $(CURDIR)/man4/*.pdf debian/tmp/usr/share/doc/netcdf/.
	install -m 644 -o root -g root $(CURDIR)/man4/*.txt debian/tmp/usr/share/doc/netcdf/.
	install -m 644 -o root -g root $(CURDIR)/man4/*.ps debian/tmp/usr/share/doc/netcdf/.
	install -m 644 -o root -g root $(CURDIR)/man4/*.info debian/tmp/usr/share/info/.

