#!/usr/bin/make -f

# DH_VERBOSE := 1

export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

include /usr/share/dpkg/default.mk

# a few ISO-8859-1 files needing conversion to UTF-8
ISOFILES  = res/TemplateBatchFiles/PARRIS.bf
ISOFILES += res/TemplateBatchFiles/TemplateModels/MEC.mdl
ISOFILES += res/TemplateBatchFiles/TemplateModels/models.lst

%:
	dh $@ --buildsystem=cmake

override_dh_auto_clean:
	dh_auto_clean

override_dh_auto_configure:
	dh_auto_configure -- -DINSTALL_PREFIX=/usr -DNOAVX=ON -DNOSSE3=ON

override_dh_auto_build:
	# convert a few ISO-8859-1 files to address national-encoding
	set -e \
	; for file in $(ISOFILES) \
	; do    iconv -f ISO-8859-1 -t UTF-8 < $${file} > "$${file}.new" \
	;	mv "$${file}.new" "$${file}" \
	; done
	# no idea about the purpose of the dynamic library - executables are not simply linked against it
	dh_auto_build -- MP MPI
	# LIB

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	find "obj-$(DEB_HOST_GNU_TYPE)/" \
		-not -path "*/CMakeFiles/*" \
		-type f,l \
		-executable \
		-exec cp -v '{}' . \;
	./run_unit_tests.sh
endif

override_dh_installdocs-arch:
	dh_installdocs -a
	for news in debian/NEWS.Debian.* ; do \
	    pkg=`echo $${news} | sed 's/.*NEWS.Debian.//'` ; \
	    cp -a $${news} debian/$${pkg}/usr/share/doc/$${pkg}/NEWS.Debian ; \
	done

override_dh_installdocs-indep:
	dh_installdocs -i
