#!/usr/bin/make -f
include /usr/share/dpkg/pkg-info.mk

export DH_VERBOSE = 1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
CMAKE_FLAGS := -DENABLE_STATIC_LIB=0 -DDOXYGEN_FOUND=ON -DCMAKE_C_FLAGS="-g -O2 -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -D_FORTIFY_SOURCE=2"

define genman =
help2man \
	--no-info \
	--source=debian\
	--help-option='-h' \
	--no-discard-stderr \
	--version-string=$(DEB_VERSION) \
	--name=$(2) \
	--section=$(3) \
	--output man/man$(3)/$(2).$(3) \
	$(1)
endef

%:
	dh $@ -Scmake

override_dh_auto_build:
	dh_auto_build
	dh_auto_build -- doc

override_dh_auto_configure:
	dh_auto_configure -- $(CMAKE_FLAGS)

# Remove RPATH for e_smi_tool
override_dh_install:
	mkdir -p man/man1
	@for exe in `find -type f -name e_smi_tool`; do \
		chrpath -d $$exe; \
		$(call genman,$$exe,e_smi_tool,1); \
	done
	dh_install
	# Remove extra-license-file
	find debian -name COPYING -exec rm -f {} \;

override_dh_auto_clean:
	dh_auto_clean
	rm -f include/e_smi/e_smi64Config.h *.pdf
	rm -rf man

