#!/usr/bin/make -f

export DEB_PKG_VERSION = $(shell dpkg-parsechangelog -S Version)

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

export TOP_SRCDIR=$(CURDIR)

CMAKE ?= /usr/bin/cmake

## 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
ifeq (mipsel-linux-gnu,$(DEB_HOST_MULTIARCH))
DEB_PKG_NMZ_OPENMP=NO
else
DEB_PKG_NMZ_OPENMP=YES
endif

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

%:
	dh $@  --sourcedirectory=source --builddirectory=_build --parallel

override_dh_auto_configure:
	dh_auto_configure -- -DLIB_SUFFIX="/$(DEB_HOST_MULTIARCH)" -DNMZ_OPENMP:BOOL=$(DEB_PKG_NMZ_OPENMP)

override_dh_auto_build-indep:
	$(MAKE) -C doc pdf

override_dh_auto_test-arch:
	$(MAKE) -C test NORMALIZ=$(CURDIR)/_build/normaliz

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

override_dh_auto_install-indep:
	cd _build && DESTDIR=$(CURDIR)/debian/tmp $(CMAKE) -DCOMPONENT=headers -P cmake_install.cmake
	$(MAKE) -C doc install DESTDIR=$(CURDIR)/debian/tmp

override_dh_compress-indep:
	dh_compress -X.pdf -Xexamples

override_dh_strip:
	dh_strip --dbg-package=libnormaliz0-dbg

override_dh_auto_clean-indep:
	[ ! -f doc/Makefile ] || $(MAKE) -C doc maintainer-clean

override_dh_clean-arch:
	$(MAKE) -C test distclean
	dh_clean -a

get-orig-source:
	uscan --no-conf --download-current-version --compression xz --verbose
