#!/usr/bin/make -f
#export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@

# by default build is not verbose enough to check build flags:
override_dh_auto_configure:
	dh_auto_configure -- --disable-silent-rules

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

VER_FULL = $(shell dpkg-parsechangelog | grep '^Version' | cut -d' ' -f2 | cut -f1 -d-)

# it should be possible to simplify the following:
properties.html:
	wget -O $@ http://openslide.org/docs/properties/
aperio.html:
	wget -O $@ http://openslide.org/formats/aperio/
hamamatsu.html:
	wget -O $@ http://openslide.org/formats/hamamatsu/
leica.html:
	wget -O $@ http://openslide.org/formats/leica/
mirax.html:
	wget -O $@ http://openslide.org/formats/mirax/
philips.html:
	wget -O $@ http://openslide.org/formats/philips/
sakura.html:
	wget -O $@ http://openslide.org/formats/sakura/
trestle.html:
	wget -O $@ http://openslide.org/formats/trestle/
ventana.html:
	wget -O $@ http://openslide.org/formats/ventana/
generic-tiff.html:
	wget -O $@ http://openslide.org/formats/generic-tiff/

%.xml: %.html
	xsltproc --nonet --output $<.dummy.xml --html debian/process.xsl $<
	sed -i -e 's/BEGIN SECTION/<refsection>/g' -e 's@END SECTION@</refsection>@g' $<.dummy.xml
	xmllint --nonet --output $@ --format $<.dummy.xml
	rm $<.dummy.xml

debian/openslide-formats.3: properties.xml aperio.xml hamamatsu.xml leica.xml mirax.xml philips.xml sakura.xml trestle.xml ventana.xml generic-tiff.xml debian/openslide-formats.3.xml
	(cd debian && sed -e 's@VER_FULL@$(VER_FULL)@g' openslide-formats.3.xml > openslide.tmp.xml)
	(cd debian && xsltproc --xinclude openslide.tmp.xml)

# DO NOT USE for now
#debian/openslide-quickhash1sum.1: debian/openslide-quickhash1sum.1.in
#	help2man --include=$< --output=$@ \
#		--no-info `basename $@ .1` --version-string=$(VER_FULL) --no-discard-stderr
#
#debian/openslide-write-png.1: debian/openslide-write-png.1.in
#	help2man --include=$< --output=$@ \
#		--no-info `basename $@ .1` --version-string=$(VER_FULL) --no-discard-stderr