#!/usr/bin/make -f

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

## inspired from mpfr material
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS    += -O0
	CXXCFLAGS += -O0
else ifeq ($(DEB_HOST_ARCH),alpha)
	CFLAGS   += -mieee
	CXXFLAGS += -mieee
else ifeq ($(DEB_HOST_ARCH),sha4)
	CFLAGS   += -mieee
	CXXFLAGS += -mieee
else
	CFLAGS   := $(subst -O2,-O3,$(CFLAGS))
	CXXFLAGS := $(subst -O2,-O3,$(CXXFLAGS))
endif

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

%:
	dh $@ --with autoreconf --builddirectory=_build --parallel

override_dh_auto_configure:
	dh_auto_configure -- --enable-maintainer-mode

override_dh_auto_build-indep: README.implementation
	$(MAKE) -f debian/adhoc/Makefile doc

override_dh_auto_test-indep:
	true

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

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

override_dh_installdocs:
	dh_installdocs -pprimesieve-bin     --link-doc=libprimesieve6
	dh_installdocs -plibprimesieve6-dbg --link-doc=libprimesieve6
	dh_installdocs -plibprimesieve6-dev --link-doc=libprimesieve6-dev-common
	dh_installdocs --remaining-packages

override_dh_compress-indep:
	dh_compress -X.pdf -Xexamples

override_dh_strip:
	dh_strip --dbg-package=libprimesieve6-dbg

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

README.implementation:
	cp -p src/primesieve/README README.implementation
