#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk
include /usr/share/dpkg/buildtools.mk
include /usr/share/dpkg/architecture.mk

ifneq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
CONFIGURE_FLAGS = --=$(DEB_HOST_GNU_CPU)-$(DEB_HOST_ARCH_OS) CC=$(CC) CXX=$(CXX) AR=$(AR)
endif

MAKE_OVERRIDE = AT= QUIET_CXX= QUIET_CC= QUIET_AR= \
		INCS='-I$(CURDIR) -I$(CURDIR)/build' ABI_FLAG='$(LDFLAGS)'

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@ --with sphinxdoc

# upstream Makefile has only CFLAGS, not CPPFLAGS so inject flags using configure.
# Let's hope CFLAGS will always be good enough even for $(CXX)
override_dh_auto_configure:
	./configure --prefix="/usr" --with-ntl CC='$(CC)' CXX='$(CXX)' CFLAGS='$(CPPFLAGS) $(CFLAGS)'
	sed -i Makefile -e "s|LIBDIR=lib|LIBDIR=lib/$(DEB_HOST_MULTIARCH)|g"

override_dh_auto_build:
	dh_auto_build --parallel -- $(MAKE_OVERRIDE)
	make -C doc html
	make -C doc latexpdf

override_dh_auto_install:
	dh_auto_install
	find . -name libflint.a -delete

override_dh_auto_test:
	dh_auto_test -- $(MAKE_OVERRIDE)

override_dh_installchangelogs:
	dh_installchangelogs NEWS
