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

CFLAGS  ?= $(shell dpkg-buildflags --get CFLAGS) -DUNIX
CFLAGS  += $(shell dpkg-buildflags --get CPPFLAGS)
LDFLAGS ?= $(shell dpkg-buildflags --get LDFLAGS) -Wl,--as-needed

%:
	dh $@ --parallel

override_dh_auto_build-arch:
	dh_auto_build -- CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" DESTDIR=/usr PLATFORM=-DUNIX latex2rtf

override_dh_auto_build-indep:
	$(MAKE) -C doc all latex2rtf.html web/manpage.html web/latex2png.html
	for file in doc/latex2pn.txt doc/latex2rtf.info doc/latex2rtf.pdf doc/latex2rtf.texi \
	            doc/latex2rtf.txt doc/web/latex2png.html doc/web/manpage.html; do \
		cp -a $$file $$file.orig; \
	done
	fromdos doc/latex2rtf.texi
	dh_auto_build -- CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" DESTDIR=/usr PLATFORM=-DUNIX doc

override_dh_auto_install:
	mkdir --parents $(CURDIR)/debian/tmp/usr/share/doc/latex2rtf-doc/
	dh_auto_install -- SUPPORTDIR=/share/doc/latex2rtf-doc/ DESTDIR=$(CURDIR)/debian/tmp/usr
	chmod a-x $(CURDIR)/debian/tmp/usr/share/latex2rtf/cfg/*

override_dh_auto_clean:
	dh_auto_clean -- realclean

override_dh_clean:
	for file in doc/latex2pn.txt doc/latex2rtf.info doc/latex2rtf.pdf doc/latex2rtf.texi \
	            doc/latex2rtf.txt doc/web/latex2png.html doc/web/manpage.html; do \
		test ! -f $$file.orig || mv $$file.orig $$file; \
	done
	dh_clean test/hyperref.out

override_dh_install:
	dh_install --list-missing

override_dh_installdocs:
	dh_installdocs -A

override_dh_installchangelogs:
	dh_installchangelogs -A ChangeLog
