#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

ifeq (sh4,$(shell dpkg-architecture -qDEB_HOST_ARCH))
  # Renesas SH(sh4) need -mieee option.
  # Without this option the fmtspcl test fails.
  export DEB_CFLAGS_MAINT_APPEND = -mieee
endif

LOCPATH=$(CURDIR)/debian/build/locales
LOCALIAS=/usr/share/locale/locale.alias

%:
	SBOX_REDIRECT_IGNORE=/usr/bin/automake:/usr/bin/autoconf:/usr/bin/autom4te:/usr/bin/aclocal:/usr/bin/autom4te:/usr/bin/m4
	export SBOX_REDIRECT_IGNORE
	#export LIBTOOLIZE=/usr/bin/libtoolize  /usr/bin/libtoolize:
	export AUTOM4TE=/usr/bin/autom4te
	export AUTOCONF=/usr/bin/autoconf
	export ACLOCAL=/usr/bin/aclocal
	export AUTOMAKE=/usr/bin/automake
	dh $@ --with autotools-dev

override_dh_auto_configure:
	dh_auto_configure -- --disable-rpath
	touch --date="Jan 01 2000" \
            doc/gawktexi.in doc/gawk.texi doc/gawkinet.texi \
            doc/gawk.info doc/gawkinet.info doc/sidebar.awk

override_dh_auto_test:
	# Only run the testsuite if it's wanted.
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Generate locales used in testsuite.
	#mkdir -p $(LOCPATH)
	#localedef -i en_US -c -f ISO-8859-1 -A $(LOCALIAS) $(LOCPATH)/en_US.ISO-8859-1
	#localedef -i en_US -c -f UTF-8      -A $(LOCALIAS) $(LOCPATH)/en_US.UTF-8
	#localedef -i ja_JP -c -f UTF-8      -A $(LOCALIAS) $(LOCPATH)/ja_JP.UTF-8
	#localedef -i ru_RU -c -f UTF-8      -A $(LOCALIAS) $(LOCPATH)/ru_RU.UTF-8
	# Run actual test suite.
	#LOCPATH=$(LOCPATH) make check
endif

override_dh_auto_install:
	dh_auto_install
	# Remove unwanted files.
	rm -f debian/gawk/usr/bin/*awk-*
	rm -f debian/gawk/usr/bin/awk
	# Remove fake info files (see README.source).
	rm -rf debian/gawk/usr/share/info

override_dh_auto_clean:
	dh_auto_clean
	rm -rf debian/build

override_dh_compress:
	# Don't compress awk examples.
	dh_compress --exclude=.awk
