#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@ --buildsystem=autoconf

override_dh_auto_configure:
	dh_auto_configure -- \
		--disable-dependency-tracking \
		--disable-openmp \
		--disable-test \
		--disable-benchmark \
		--disable-examples \
		--disable-cuda \
		--disable-debug \
		--disable-optimization \
		--disable-gmp \
		--enable-mpfr \
		--disable-qd \
		--disable-dd \
		--disable-double \
		--disable-binary128 \
		--disable-binary80 \
		--enable-gmpfrxx-mkII \
		--with-gmpfrxx-mkII=/usr \
		--with-system-gmp=yes \
		--with-system-mpfr=yes \
		--with-system-mpc=yes
	# Do not embed the standard Debian library directory as RUNPATH.
	sed -i \
		-e 's|-Wl,-rpath,\$$(libdir)||g' \
		mplapack/reference/Makefile \
		mpblas/optimized/mpfr/Makefile

override_dh_auto_install:
	dh_auto_install
	# libmpc-dev intentionally has no mpc.pc.  Replace upstream Requires with
	# explicit system link flags; never synthesize a pkg-config module.
	for pc in debian/tmp/usr/lib/*/pkgconfig/mplapack_mpfr*.pc; do \
		test -f "$$pc" || continue; \
		sed -i \
			-e 's/^Requires:.*/Requires:/' \
			-e '/^Libs:/s/[[:space:]]*$$//' \
			-e 's/^Libs: \(.*\)$$/Libs: \1 -lmpc -lmpfr -lgmp/' \
			"$$pc"; \
	done
