#!/usr/bin/make -f

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

# Droping -fstack-protector flag helps **drastically** reducing memory consumption when building the package!!!!
# export CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS | sed 's/-fstack-protector *//')  ## this simply tiggers #759978
export DEB_BUILD_MAINT_OPTIONS = hardening=-stackprotector
# alternatively: export DEB_CXXFLAGS_STRIP='-fstack-protector'

include /usr/share/dpkg/architecture.mk

ifneq (,$(filter $(DEB_BUILD_ARCH),mips mipsel))
    export CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS | sed 's/-O[1-9]//') -O0 -mxgot
endif

export DEB_CXXFLAGS_MAINT_APPEND  += -DNDEBUG

%:
	dh $@

override_dh_install:
	dh_install
	# ------------------------------------------------------------------
	# Delete additional LICENSE files
	if [ -d $(CURDIR)/debian/seqan-dev ] ; then \
	    find $(CURDIR)/debian/seqan-dev  -type f -name LICENSE -delete ; \
	    # Delete *.pyc files that somehow end up in seqan-dev documentation \
	    find $(CURDIR)/debian/seqan-dev -type f -name "*.pyc" -delete ; \
	fi

override_dh_auto_clean:
	dh_auto_clean
	find . -type f -name "*.pyc" -delete
	if [ -d orig ] ; then \
	  for header in `find orig -name "*generated_forwards.h"` ; do \
	    mv $${header} `echo $$header | sed 's?orig/??'` ; \
	  done ; \
	fi
	rm -rf orig

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
# Run test suite only on powerfull architectures (amd64) at build time
ifneq (,$(filter $(DEB_HOST_ARCH),amd64 kfreebsd-amd64))
	dh_auto_test
else
	echo "Do not run test suite when building on architecture $(DEB_HOST_ARCH)"
endif
endif

override_dh_fixperms:
	dh_fixperms
	find debian/*/usr/lib/cmake -type f -exec chmod -x \{\} \;
