#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS

DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)

# Hardened flags
DPKG_EXPORT_BUILDFLAGS = 1
-include /usr/share/dpkg/buildflags.mk

# Don't accidentally build the lorene plug-in
unexport HOME_LORENE

configure_flags = --with-yorick=/usr/bin/yorick --with-udunits --with-xerces \
	--without-lorene --enable-static --enable-shared \
	--with-boost --enable-c++11 --enable-release \
	--with-mpi --without-virtualenv --enable-doc

%:
	dh $@ --with python2,python3,autoreconf

override_dh_auto_install-arch:
	dh_auto_install -a
	sh debian/install_for_all_pythons
	dh_numpy -a
	dh_numpy3 -a

override_dh_auto_install-indep:

override_dh_install-arch:
	dh_install -a -N yorick-gyoto
	dh_installyorick --no-make-install -pyorick-gyoto
	dh_makeshlibs -a

override_dh_install-indep:
	dh_install -i

override_dh_auto_build-arch:
	$(MAKE) COPT_DEFAULT="" \
	     Y_CFLAGS="$(CFLAGS) $(CPPFLAGS)" \
	     Y_LDFLAGS="$(LDFLAGS)" \
	     lib bin yorick
	for badflag in -g -O2 -Werror=format-security -Wformat ; do \
	 sed s/$${badflag}// -i lib/gyoto.pc ; \
	done
	set -e; \
	for python in `pyversions -s` `py3versions -s`; do \
	 make -C python PYTHON=$$python ; \
	done

override_dh_auto_build-indep:
	$(MAKE) doc

override_dh_auto_configure:
	dh_auto_configure -- $(configure_flags)

override_dh_auto_clean:
	[ ! -f python/Makefile ] || make -C python clean
	dh_auto_clean

override_dh_auto_test-indep:

override_dh_auto_test-arch:
ifeq (,$(filter $(DEB_HOST_ARCH), kfreebsd-i386 kfreebsd-amd64 mips))
# skip the test suite on kfreebsd-any as gyoto package not beeing built
# skip on mips as lucatelli2 fails on it (but the binary works on other boxes)
	LC_ALL=C.UTF-8 dh_auto_test
endif

override_dh_strip:
	dh_strip --dbg-package=gyoto-dbg
