#!/usr/bin/make -f
# -*- makefile -*-

export DEB_BUILD_MAINT_OPTIONS := hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
-include /usr/share/dpkg/buildflags.mk

export CFLAGS += -DGMP_DESC -DLTM_DESC -DUSE_LTM

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

override_dh_auto_configure:
	mkdir -p debian/libtool
	cp debian/configure.ac debian/libtool/
	env -C debian/libtool LIBTOOLIZE='libtoolize -i' autoreconf -f -i
	dh_auto_configure --sourcedirectory=debian/libtool

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	$(MAKE) coverage EXTRALIBS="-lgmp -ltommath"
endif

override_dh_auto_build:
	$(MAKE) V=1 docs
	dh_auto_build -- -f makefile.shared EXTRALIBS="-lgmp -ltommath" LIBTOOL="$(CURDIR)/debian/libtool/libtool"

override_dh_auto_install:
	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp INSTALL_GROUP=root LIBPATH=/usr/lib/$(DEB_HOST_MULTIARCH) PREFIX=/usr install -f makefile.shared LIBTOOL="$(CURDIR)/debian/libtool/libtool"

override_dh_auto_clean:
	rm -Rf debian/libtool
	rm -f doc/crypt.pdf
	dh_autoreconf_clean
	dh_auto_clean --

%:
	dh $@
