#!/usr/bin/make -f
include /usr/share/dpkg/pkg-info.mk
export DEB_VERSION

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

export TOP_SRCDIR=$(CURDIR)

## At the time of coding, GOMP is poorly supported on alpha architecture
## machine --- see https://github.com/Normaliz/Normaliz/issues/168
## -- Jerome Benoit <calculus@rezozer.net>  Fri, 26 Jan 2018
## At the time of coding, GOMP emits random `Bus error' during test on mipsel
## architecture machines --- see bugreport #806769 for further information.
## -- Jerome Benoit <calculus@rezozer.net>  Tue, 01 Dec 2015
ifneq (,$(filter $(DEB_HOST_MULTIARCH), alpha-linux-gnu mipsel-linux-gnu))
DEB_PKG_NMZ_OPENMP=no
else
DEB_PKG_NMZ_OPENMP=yes
endif

ifneq (,$(filter $(DEB_HOST_MULTIARCH), m68k-linux-gnu sh4-linux-gnu x86_64-linux-gnux32))
DEB_PKG_NMZ_FLINT=no
DEB_PKG_NMZ_EANTIC=no
else
DEB_PKG_NMZ_FLINT=yes
DEB_PKG_NMZ_EANTIC=yes
endif

default:
	@uscan --no-conf --dehs --report || true

%:
	dh $@ --builddirectory=_build

override_dh_auto_configure:
	dh_auto_configure -- \
		--enable-openmp=$(DEB_PKG_NMZ_OPENMP) \
		--enable-flint=$(DEB_PKG_NMZ_FLINT) \
		--enable-enfnormaliz=$(DEB_PKG_NMZ_EANTIC)

override_dh_auto_build-indep:
	$(MAKE) -C doc -f $(CURDIR)/debian/adhoc/Makefile doc

override_dh_auto_build-arch:
	dh_auto_build -a

override_dh_auto_test-indep:

override_dh_prep-arch:
	$(MAKE) -f $(CURDIR)/debian/adhoc/Makefile manpages

override_dh_auto_install-indep:
	$(MAKE) -C _build/source install-data-am DESTDIR=$(CURDIR)/debian/tmp

override_dh_auto_install:
	dh_auto_install
	find debian/tmp/ -name "*.la" -delete

override_dh_compress-indep:
	dh_compress -X.pdf -Xexamples
