#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH)

BUILD_ARCH_OS :-= $(shell dpkg-architecture -qDEB_BUILD_ARCH_OS)
BUILD_ARCH_CPU := $(shell dpkg-architecture -qDEB_BUILD_ARCH_CPU)

NETCDF_LIBS ?= $(shell pkg-config --libs heimdal-gssapi netcdf libffi)

%:
	dh $@ --with python2 

override_dh_auto_configure:
	autoreconf -fiv
	ln -sf  /usr/share/misc/config.sub 
	dh_auto_configure -- --disable-color --enable-verbose-test   \
		UUIDLDFLAGS="-lossp-uuid" UUIDFLAGS="-I/usr/include/ossp" SZLIBFLAGS=nosz   \
		EXTRA_NCLDFLAGS="-lhdf5 -lm -lcurl $(NETCDF_LIBS) -lz -lidn -lrtmp -lgcrypt \
		-lgnutls -lgssapi_krb5 -llber -lldap_r -lgpg-error -ltasn1 -lp11-kit        \
		-lk5crypto -lkrb5support -lsasl2 -lkeyutils -lsqlite3"

override_dh_auto_clean:
	rm -rf config.sub config.log config.status libcmor.a libcmor.so.2 build test_grid

override_dh_auto_build:
	$(MAKE) FC=gfortran

ifeq ( $(BUILD_ARCH_OS)-$(BUILD_ARCH_CPU), kfreebsd-i386)
override_dh_auto_test:
	@echo "Tests disabled; see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=598745"
endif

override_dh_auto_install:
	$(MAKE) install DESTDIR=`pwd`/debian/tmp
	$(MAKE) install_shlib DESTDIR=`pwd`/debian/tmp
	for p in `pyversions --supported` ; do \
		$$p ./setup.py install --prefix=`pwd`/debian/python-cmor/usr ; \
		done
	dh_numpy
	dh_install -p libcmor2 libcmor.so.2    $(LIBDIR)
	dh_install -p libcmor-dev debian/tmp/usr/lib/libcmor.a $(LIBDIR)
	dh_install -p libcmor-dev debian/tmp/usr/lib/pkgconfig/cmor.pc  $(LIBDIR)/pkgconfig
	dh_link -p libcmor-dev $(LIBDIR)/libcmor.so.2   $(LIBDIR)/libcmor.so
