#!/usr/bin/make -f

#export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@ -- -Dsrc

override_dh_auto_build-arch:
	$(MAKE) -C src arch

override_dh_auto_build-indep:
	$(MAKE) -C src indep

override_dh_auto_install-arch:
	$(MAKE) -C src install-arch DESTDIR=$(CURDIR)/debian/tmp

override_dh_auto_install-indep:
	$(MAKE) -C src install-indep DESTDIR=$(CURDIR)/debian/tmp

override_dh_installdocs-arch:
	( cd debian/html; for img in ../images/*.uue; do uudecode $$img; done )
	ln -sf tex4ht_doc.html debian/html/index.html
	dh_installdocs -a

override_dh_install-arch:
	dh_install -a -Xtex4ht.jar

litbuild: clean
	dh_testdir

	# Apply some patches to lit/
	QUILT_PATCHES=debian/lit/patches quilt push -a || test $?=2

# If the LITK variable is defined the avoid bootstrap
ifdef LITK
	debian/lit/rebuild.sh -k | tee -a debian/lit/litbuild.log
else
	debian/lit/rebuild.sh | tee -a debian/lit/litbuild.log
endif

	# Reverse the patches to lit/
	QUILT_PATCHES=debian/lit/patches quilt pop -a || test $?=2
	rm -rf .pc

	# Diff ignore regular expression matching date strings
	# also ignore the exit level 1 indicating that differences are found
	-diff -ur -B -b -I '[[:space:]]*%.*' \
	-I '.*[^0-9][0-9]\{4\}-[0-9][0-9]-[0-9][0-9][^0-9].*' \
	texmf/ dest/texmf/ > debian/lit/texmf.diff.log 
	-diff -ur -B -b \
	-I '.*[^0-9][0-9]\{4\}-[0-9][0-9]-[0-9][0-9][^0-9].*' \
	src/ dest/src/ > debian/lit/src.diff.log 
	-diff -ur -B -b  \
	-I '.*[^0-9][0-9]\{4\}-[0-9][0-9]-[0-9][0-9][^0-9].*' \
	bin/unix/ dest/bin/unix/ > debian/lit/scripts.diff.log 
	@echo "Look in debian/lit/litbuild.log for a copy of the litbuild"
	@echo "output. The significant differences are in .diff.log"
	@echo "files the same directory. The documentation for the"
	@echo "literate source is in dest/litdoc."
