#!/usr/bin/make -f

export DEB_LDFLAGS_MAINT_APPEND := -Wl,--as-needed
export DEB_CFLAGS_MAINT_APPEND := -Wall -Wno-format-contains-nul
DATECHLOG := $(shell date \
	-d "`dpkg-parsechangelog | \
	sed -n '/^Date: /s/^Date: //p'`" \
	+%Y-%m-%d)

override_dh_auto_configure:
	dh_auto_configure --verbose -- \
		--disable-silent-rules \
		--with-libxml2-libs="$(shell pkg-config --libs libxml-2.0)" \
		--with-libxml2-cflags="$(shell pkg-config --cflags libxml-2.0)"

override_dh_auto_build:
	dh_auto_build --verbose
	$(MAKE) -C doc info
ifneq (,$(filter autogen-doc, $(shell dh_listpackages)))
	$(MAKE) -C doc autogen.ps
	cd doc && texi2html -split=chapter -subdir=html autogen.texi
endif


override_dh_auto_clean:
	rm -Rf doc/html
	rm -vf agen5/test/defs autoopts/test/*.o autoopts/test/*.c \
		autoopts/test/*.h autoopts/test/getopt.def getdefs/opts.c \
		snprintfv/snv.c snprintfv/snprintfv.h xml2ag/fork.c \
		xml2ag/xmlopts.c xml2ag/xmlopts.h autoopts/autoopts.pc \
		autoopts/pathfind.3 autoopts/*.tar.gz
	dh_auto_clean --verbose

override_dh_auto_install:
	dh_auto_install  --verbose
	mv -v $(CURDIR)/debian/tmp/usr/share/pkgconfig \
		`dirname $(CURDIR)/debian/tmp/usr/lib/*/libopts.la`
	rm -vf $(CURDIR)/debian/tmp/usr/share/info/dir \
		$(CURDIR)/debian/tmp/usr/lib/*/libopts.la
	find debian/tmp/usr/share/man/ -type f -exec \
		sed -i -e "s:\(^\.TH .*\) 2[[:digit:]][[:digit:]][[:digit:]]-[01][[:digit:]]-[0123][[:digit:]] :\1 $(DATECHLOG) :" \
		{} +


override_dh_install:
	dh_install --fail-missing

override_dh_makeshlibs:
	dh_makeshlibs -V

%:
	dh $@ --with autoreconf
