#!/usr/bin/make -f
# -*- makefile -*-

#export DH_VERBOSE=1
export DESTDIR=$(CURDIR)/debian/tmp
export DH_ALWAYS_EXCLUDE=.gitignore
export PATH := $(CURDIR)/debian/strip-nondeterminism:$(PATH)

include /usr/share/dpkg/default.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

DARCH:=$(shell dpkg-architecture | fgrep DEB_TARGET_ARCH= | cut -f 2 -d'=')
BITS:=$(shell dpkg-architecture | fgrep DEB_TARGET_ARCH_BITS= | cut -f 2 -d'=')

ifeq ($(DARCH),x32)
  X32:=yes
else
  X32:=no
endif

ifeq ($(BITS),64)
  64BIT:=yes
else
  64BIT:=no
endif

# check whether faketime can be used
ifeq ($(shell faketime 'last friday' date > /dev/null 2> /dev/null; echo $$?),0)
  FAKETIME:=faketime -f "`TZ=UTC date -d @$(SOURCE_DATE_EPOCH) +'%Y-%m-%d %H:%M:%S'`"
endif

%:
	dh $@ --with python3

override_dh_auto_clean:
	mkdir -p obj
	$(MAKE) cleanup
	cd doc/manuals; $(MAKE) cleanup
	# should be deleted inside doc/manuals/Makefile
	rm -f doc/manuals/annotationsketch.out \
	      doc/manuals/api_reference.tex    \
	      doc/manuals/gtscript_reference.tex
	find doc . -name "*.toc" -delete
	find testdata \( -name '*.ois' -or -name '*.sds' -or -name '*.esq' -or \
	      -name '*.ssp' -or -name '*.des' -or -name "*.md5"  \) -and \( -not \
	      -name '*foo.32.*' -not -name '*foo.64.*' \) -delete
	rm -f www/genometools.org/htdocs/images/callbacks.png \
	      www/genometools.org/htdocs/images/parsed.png    \
	      www/genometools.org/htdocs/images/constructed.png \
	      doc/manuals/annotationsketch.pdf
	rm -f www/genometools.org/htdocs/examples.html \
	      www/genometools.org/htdocs/libgenometools.html
	rm -rf gtpython/build
	rm -rf obj

override_dh_auto_build:
	cp debian/doc-imgs/*png www/genometools.org/htdocs/images
	$(FAKETIME) dh_auto_build -- verbose=yes useshared=yes x32=$(X32) 64bit=$(64BIT) errorcheck=no all docs manuals

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	bin/gt -test
	cd testsuite; ./testsuite.rb -keywords 'gt_sketch and not gt_python and not gt_ruby'
endif

override_dh_auto_install:
	dh_auto_install -- installmanpages useshared=yes \
	  x32=$(X32) 64bit=$(64BIT) errorcheck=no prefix=$(DESTDIR)/usr
	dh_auto_install --sourcedirectory=gtpython --buildsystem=pybuild \
	  --destdir=$(CURDIR)/debian/python3-genometools

override_dh_missing:
	dh_missing --list-missing
