#!/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 *//')

%:
	dh $@

override_dh_auto_build:
	dh_auto_build
	cd obj-$(DEB_BUILD_GNU_TYPE); make docs

override_dh_install:
	dh_install
	# /usr/bin/join is part of coreutils package: Avoid name conflict by renaming it to seqan-join
	# This solution is withdrawn in favour of just providing a set of binaries according to upstream
	# in /usr/bin (via symlink) while others go to /usr/lib/seqan/bin (see README.Debian)
	# mv $(CURDIR)/debian/seqan-apps/usr/bin/join $(CURDIR)/debian/seqan-apps/usr/bin/seqan-join
	#
	# Formerly binaries were installed into usr/lib/seqan/bin/
	# and only some of them were made available in /usr/bin via dh_link
	# Since there is no obvious reason for this neither is there any
	# documentation that explains the motivation this is commented here.
	#for APP in `find $(CURDIR)/obj*/apps -mindepth 1 -maxdepth 1 -executable -type f` ; do \
	#  cp -a $$APP $(CURDIR)/debian/seqan-apps/usr/lib/seqan/bin/ ; done
	# ------------------------------------------------------------------
	# Formerly readmes were named README.app.  It seems more consistent
	# to keep upstream documentation layout which in addition contains
	# some example files.  So the old code is commented here.
	#for APP in `find apps -name README` ; do \
	#  app=`echo $$APP | sed 's?.*apps/\(.\+\)/README?\1?'` ; \
	#  echo $$app ; \
	#  cp -a $$APP $(CURDIR)/debian/seqan-apps/usr/share/doc/seqan-apps/README.$$app ; \
	#done
	# ------------------------------------------------------------------
	# Delete additional LICENSE files
	find $(CURDIR)/debian/seqan-apps -type f -name LICENSE -delete
	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

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_link:
	dh_link
	# we generate only those manpages where binaries are linked to /usr/bin
        # since dh_link is executed after dh_installmanpages this is done here
	$(CURDIR)/debian/generate_manpages

get-orig-source:
	uscan --verbose --force-download

