#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
export DEB_CXXFLAGS_MAINT_APPEND  = -fvisibility=hidden

EPOCH_DATE:=$(shell date -u -d ${SOURCE_DATE_EPOCH} +%d.%m.%Y)

%:
	dh $@ --sourcedirectory=src

binary: binary-arch binary-indep

binary-indep: doc-stamp
	dh $@ --sourcedirectory=src


# Need -DUSE_KNNGraphAlphaMutualInformationMetric:BOOL=ON, otherwise
# KNN is not built, and link of elastix fails.
#
DEB_CMAKE_EXTRA_FLAGS += \
	-DCMAKE_INSTALL_PREFIX=/usr \
	-DCMAKE_BUILD_TYPE=RELEASE \
	-DCMAKE_SKIP_RPATH=ON \
	-DSOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH \
	-DELASTIX_USE_MEVISDICOMTIFF:BOOL=OFF \
	-DUSE_KNNGraphAlphaMutualInformationMetric:BOOL=ON

override_dh_auto_configure:
	dh_auto_configure -- $(DEB_CMAKE_EXTRA_FLAGS)

override_dh_installdocs-indep:
	dh_installdocs -i
	# avoid privacy breach by using local logo
	sed -i 's#http://elastix.isi.uu.nl/images/##' debian/elastix-doc/usr/share/doc/elastix-doc/help/html/*.html
	sed -i 's#http://elastix.isi.uu.nl/images/#html/#' debian/elastix-doc/usr/share/doc/elastix-doc/help/*.html
	cp -a dox/art/elastix_logo_full.gif debian/elastix-doc/usr/share/doc/elastix-doc/help/html/elastixLogo.gif

doc: doc-stamp

doc-stamp: help/html/index.html dox/manual/manual.pdf
	touch $@

# build-deps: doxygen, latex, dot
help/html/index.html: help/doxyfile.out
	doxygen $<
	rm help/html/*.md5

dox/manual/manual.pdf: dox/manual/manual.tex
	sed -ie 's/^%\\date{/\\date{'"$(EPOCH_DATE)"'/' dox/manual/manual.tex 
	sed -ie 's/\\today/'"$(EPOCH_DATE)"'/' dox/manual/manual.tex 
	cd dox/manual && latex manual && bibtex manual && latex manual && latex manual && latex manual && dvipdf manual

