#!/usr/bin/make -f
#export DH_VERBOSE = 1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export DEB_CFLAGS_MAINT_APPEND = -std=gnu17

DEB_CONFIGURE_USER_FLAGS = --with-readline --with-value-type="$(if $(filter $(DEB_BUILD_ARCH_BITS),64),long) int" --with-value-sizeof=$$(( $(DEB_BUILD_ARCH_BITS) / 8 ))

dev_extras = debian/tmp -name install-aliases -o -name rep_config.h -o -name *.a -o -name *.jl

rep_extras = debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/rep debian/tmp/usr/share/rep -name *.jlc -o -name *.so

dh_install_auto = xargs dh_install --autodest

%:
	dh $@

override_dh_auto_clean:
	! [ -f Makefile ] || $(MAKE) gitclean

override_dh_auto_configure:
	dh_auto_configure -- $(DEB_CONFIGURE_USER_FLAGS)

override_dh_auto_build:
	LC_ALL=C dh_auto_build

execute_after_dh_auto_install:
	find debian -name '*.la' -delete

override_dh_installchangelogs:
	dh_installchangelogs NEWS

execute_after_dh_install:
	find $(dev_extras) | $(dh_install_auto) -plibrep-dev
	find $(rep_extras) | $(dh_install_auto) -prep
	rm -f debian/tmp/usr/share/info/dir
	# Replace build path with placeholder string for reproducible builds
	f=debian/librep-dev/usr/lib/$(DEB_HOST_MULTIARCH)/rep/libtool; ! [ -f "$$f" ] || sed -i -e "s,$(CURDIR),BUILDPATH,g" "$$f"

override_dh_makeshlibs:
	dh_makeshlibs -Xusr/lib/$(DEB_HOST_MULTIARCH)/rep/

override_dh_missing-indep:
	dh_missing -i --list-missing

override_dh_shlibdeps:
	dh_shlibdeps -- --warnings=2
