#!/usr/bin/make -f

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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

include /usr/share/dpkg/default.mk

%:
	dh $@ --with python2

# override_dh_auto_install:
# 	dh_auto_install --destdir=debian/tmp

override_dh_auto_configure:
	dh_auto_configure -- --enable-sparsehash --enable-bam \
	         --with-bam-include-path=/usr/include/samtools \
		 --with-bam-lib-path=/usr/lib

override_dh_install:
	cp php/constants.php.dist ./constants.php
	dh_install
	# Skip this bit if not building stacks
	! cd debian/$(DEB_SOURCE)/usr/lib/$(DEB_SOURCE)/bin || \
	  for f in *.pl ; do \
	    ln -s "$$f" "`basename $$f .pl`" ; \
	  done
	# Skip this bit if not building stacks-web
	# Note - directory perms will be set in postinst
	dh_installdirs -pstacks-web /var/lib/stacks/export
	if [ -e debian/stacks-web/usr/share/stacks/php ] ; then \
	    rmdir debian/stacks-web/usr/share/stacks/php/export ; \
	    ln -s /var/lib/stacks/export \
		debian/stacks-web/usr/share/stacks/php/export ; \
	fi

override_dh_link:
	dh_link
	mkdir -p debian/$(DEB_SOURCE)/usr/lib/debian-med/bin
	cd debian/$(DEB_SOURCE)/usr/lib/debian-med/bin && \
	for f in `ls $(CURDIR)/debian/$(DEB_SOURCE)/usr/lib/$(DEB_SOURCE)/bin` ; do \
	    ln -s ../../$(DEB_SOURCE)/bin/$$f ; \
	done

override_dh_auto_test:
	#ln -s /usr/share/automake-1.14/tap-driver.sh tests/tap-driver.sh
	#dh_auto_test
	#  Does not work even after this trick.  See
	#   https://groups.google.com/forum/#!msg/stacks-users/TA2tMEqb4Mg/pQy4fUCYi9kJ
	true

override_dh_clean:
	dh_clean
	rm -f ./constants.php
