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

# extract version suffix from gcj
# VERSUFF=-$(shell gcj --version | sed -r -e '1s/.* ([0-9]+\.[0-9]+).*/\1/;q')

# use (temporary) fixed gcj/g++ version from debian/control
VERSUFF=$(shell grep -oP '(?<=gcj)-[0-9.]*' debian/control)

DPKG_EXPORT_BUILDFLAGS = 1
-include /usr/share/dpkg/buildflags.mk

%:
	dh $@

override_dh_auto_build:
	dh_auto_build
	$(MAKE) -C $(CURDIR)/pdftk -f Makefile.Debian VERSUFF=$(VERSUFF)

override_dh_auto_clean:
	# do not call clean target if source is unpatched
	make -C $(CURDIR)/pdftk -f Makefile.Debian clean
	rm -rf $(CURDIR)/pdftk/pdftk
	rm -rf $(CURDIR)/pdftk/*.o
	find $(CURDIR) -name "*.class" -type f -delete
	find $(CURDIR)/java -name "*.h" -type f -delete
	dh_auto_clean

override_dh_strip:
	dh_strip --dbg-package=pdftk-dbg


override_dh_auto_install:
	install -o root -g root -m 755 -d $(CURDIR)/debian/pdftk/usr/bin
	install -o root -g root -m 755 $(CURDIR)/pdftk/pdftk $(CURDIR)/debian/pdftk/usr/bin
	dh_auto_install --destdir=debian/pdftk

override_dh_installdocs:
	dh_installdocs --link-doc=pdftk

get-orig-source:
	cd $(dir $(firstword $(MAKEFILE_LIST))).. && \
	uscan --force-download --repack --rename --destdir $(CURDIR)
