#!/usr/bin/make -f

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

# magic debhelper rule
%:
	dh $@ --with python2

# To aid reproducible builds
LC_ALL=C
export LC_ALL

ARCH:=$(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
LIBDIR:=/usr/lib/$(ARCH)
INSTALLDIR:=$(CURDIR)/debian/tmp

override_dh_auto_build:
	sed -e 's%@ARCH@%${ARCH}%' \
                -e 's%@LIBDIR@%${LIBDIR}%' \
		-e 's%@CURDIR@%${CURDIR}%' \
                -e 's%@INSTALLDIR@%${INSTALLDIR}%' \
                < debian/site_specific.mk.in > site_specific.mk
	cp site_specific.mk external_functions/ef_utility
	cp debian/platform_specific.mk.debian .
	cp debian/ef_utility/platform_specific.mk.debian external_functions/ef_utility/platform_specific.mk.debian
	$(MAKE) HOSTTYPE=debian all

override_dh_auto_install:
	$(MAKE) HOSTTYPE=debian install
	# libpyferret.so needs a link because its linked by externally loaded modules
	dh_link -p python-ferret /usr/lib/python2.7/dist-packages/pyferret/libpyferret.$(ARCH).so $(LIBDIR)/libpyferret.so
	dh_numpy

override_dh_auto_test:
	# @echo "Tests bypassed for the moment."
	# First build necessary files
	$(MAKE) -C bench make_stream_file
	# (cd bench && ./run_all )

override_dh_auto_clean:
	# use system xpm.h, not supplied ones
	rm -f fer/gui/xpm*.h
	find . -type l  -delete 
	find . -name '*.o' -delete
	find . -name '*.so' -delete
	find external_functions -type l -delete
	[ ! -f platform_specific_flags.mk.debian ]  || $(MAKE)  clean HOSTTYPE=debian 

