#!/usr/bin/make -f
# You must remove unused comment lines for the released package.
export DH_VERBOSE = 1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

#here and at dh_auto_configure. here not working
#export DEB_MAKE_INVOKE += NOOCONVTEST=1
#export DEB_MAKE_ENVVARS = NOOCONVTEST=1

%:
	dh $@
# --with autoreconf

#dist is xenial to go back to bionic:
#	unique name append a letter at version
#	in control          debhelper-compat (= 11)
#      here                --with autoreconf
#      remove compat file

#because etchelper in src/Makefile is forged like in install
override_dh_auto_build:
	dh_auto_build -- prefix=/usr

override_dh_auto_install:
	#also to modify at Makefile if changed
	echo src/files/headers/logs.oh usr/include/ocompiler/ > debian/ocompiler-dev.install
	echo src/files/headers/log.oh usr/include/ocompiler/ >> debian/ocompiler-dev.install
	echo src/files/headers/xfilecore.oh usr/include/ocompiler/ >> debian/ocompiler-dev.install
	echo src/files/headers/xfile.oh usr/include/ocompiler/ >> debian/ocompiler-dev.install

	#and, at least local, (since 2 debs?), will ignore make install to deb
	echo src/o usr/bin/ > debian/ocompiler.install
	#if [ -e ocompiler_is_o ]; then echo src/ocompiler usr/bin/ >> debian/ocompiler.install; fi
	echo ounused/ounused usr/bin/ >> debian/ocompiler.install
	if [ "$(shell dpkg-architecture -qDEB_HOST_ARCH)" = "amd64" ]; then echo ostrip/ostrip usr/bin/ >> debian/ocompiler.install; fi
	echo otoc/otoc usr/bin/ >> debian/ocompiler.install
	echo ocompiler.conf etc/ >> debian/ocompiler.install

	dh_auto_install -- prefix=/usr

ifeq ($(shell dpkg-architecture -qDEB_HOST_ARCH), amd64)
override_dh_gencontrol:
	dh_gencontrol
	echo -n "Depends: ocompiler (= " >> debian/ocompiler-dev/DEBIAN/control
	echo -n `cat debian/changelog | head -1 | grep -Poe "[^(]*(?=\))"` >> debian/ocompiler-dev/DEBIAN/control
	echo ")" >> debian/ocompiler-dev/DEBIAN/control
endif
