#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS	 = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
# Because upstream does not support CFLAGS easily, use CPPFLAGS
export DEB_CPPFLAGS_MAINT_APPEND = $(shell dpkg-buildflags --get CFLAGS)
export DEB_CPPFLAGS_MAINT_APPEND += -Wall -pedantic -fPIC

# Due to autoreconf
KEEP_FILES = \
 INSTALL \
 Makefile.am \
 Makefile.in \
 aclocal.m4 \
 config.guess \
 config.h.in \
 config.sub \
 configure \
 configure.in \
 depcomp \
 install-sh \
 intl/plural.c \
 ltmain.sh \
 missing \
 mkinstalldirs \
 src/Makefile.in

override_dh_auto_configure:
	# Save original files
	for f in $(KEEP_FILES); do [ -f $$f.orig ] || cp -va $$f $$f.orig ; done
	autoreconf -vfi
	dh_auto_configure

override_dh_auto_clean:
	# Don't run: would cause running autoconf again
	# [ ! -f Makefile ] || $(MAKE) distclean

	# Instead, clean manually. Skip .git DVCS directory.
	find -type d \
		\( -name .git \) -prune \
	        -a ! -name .git \
	     -o -type f \
		-name "*.o" \
		-o -name "*.Po" \
		-o -name "*.gmo" \
		-o -name "*~" \
		-o -name "stamp*" \
		-o -name "POTFILES" \
		-o -name "Makefile" \
		| xargs --no-run-if-empty rm
	# Directories
	rm -rf src/.deps m4/
	# Configs
	rm -f config.log config.h config.status po/Makefile.in
	# binaries
	rm -f libtool src/gsetroot

override_dh_auto_install:
	$(MAKE) install DESTDIR=$(CURDIR)/debian/gsetroot
	# Restore original files
	for f in $(KEEP_FILES); do [ ! -f $$f.orig ] || mv -v $$f.orig $$f; done

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog

%:
	dh $@

# End of file
