#!/usr/bin/make -f

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

export AUTOMAKE = automake-1.11
export ACLOCAL = aclocal-1.11
include /usr/share/cdbs/1/rules/autoreconf.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-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-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"

ifneq ($(wildcard /usr/lib/$(DEB_HOST_MULTIARCH)/hdf5/serial/libhdf5.so),)
  CFLAGS += -I/usr/include/hdf5/serial
  LDFLAGS += -Wl,-L/usr/lib/$(DEB_HOST_MULTIARCH)/hdf5/serial
endif

DEB_MAKE_CHECK_TARGET = check

DEB_INSTALL_CHANGELOGS_ALL = $(CURDIR)/RELEASE_NOTES

DEB_SHLIBDEPS_INCLUDE := debian/tmp/usr/lib/

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

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

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

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

install/libcf0::
	find debian/tmp/usr/lib/ -name 'libcf.*' -a ! -type d \
		-a ! -name '*.so' -a ! -name '*.a' -a ! -name '*.la' -a ! -name '*.pc' \
		-exec cp -d {} 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 -d {} debian/libnetcdf-dev/usr/lib/. \;
	find debian/tmp/usr/lib/ -type f -a -name "libnetcdf*" -a -name '*.a' -exec cp -d {} debian/libnetcdf-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/.

