#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@


override_dh_auto_configure:
	dh_auto_configure -- --enable-generic --disable-download --disable-hpddmFreeFEM-documentation.pdf

override_dh_auto_build:
	# Discard blhc false positive with ff-c++:
	@echo 'blhc: ignore-line-regexp: eval\ \./ff-c\+\+\ .*\.cpp.*'
	@echo 'blhc: ignore-line-regexp: eval\ \.\./seq/ff-c\+\+\ .*\.cpp.*'
	@echo 'blhc: ignore-line-regexp: \.\./seq/ff-c\+\+\ .*\.cpp.*'
	dh_auto_build

wrong_encoding_files = \
$(CURDIR)/debian/tmp/usr/share/FreeFEM/4.*/examples/bug/SegmentationFault.edp \
$(CURDIR)/debian/tmp/usr/lib/ff++/4.*/include/AFunction.hpp \
$(CURDIR)/debian/tmp/usr/lib/ff++/4.*/include/FESpacen.hpp

override_dh_auto_install:
	dh_auto_install
	rm $(CURDIR)/debian/tmp/usr/lib/ff++/4.*/include/config.h
	for ifile in  $(wrong_encoding_files); do \
	    iconv --from-code=iso-8859-1 --to-code=utf-8 --output=$$ifile.tmp $$ifile; \
	    mv $$ifile.tmp $$ifile; \
	done
	mv debian/tmp/usr/bin/bamg debian/tmp/usr/bin/ffbamg
	rdfind -outputname debian/results.txt -makesymlinks true debian/tmp/usr/bin/
	symlinks -r -s -c debian/tmp/usr/bin/
	# Fix reproductibility issue:
	sed --in-place -re "s/-ffile-prefix-map=\S*=. //" debian/tmp/usr/bin/ff-c++

override_dh_install:
	dh_install
	# Fix config.h path:
	if [ -d debian/libfreefem++-dev ]; then \
	    sed --in-place "s/<config.h>/<FreeFEM-config.h>/" debian/libfreefem++-dev/usr/include/freefem++/*.hpp ; \
	fi

override_dh_auto_test:
#	$(MAKE) $(AM_MAKEFLAGS) -ik --trace --debug=v check
