#!/usr/bin/make -f

DEB_CFLAGS_MAINT_APPEND = -DNDEBUG
DEB_CXXFLAGS_MAINT_APPEND = -DNDEBUG
DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
	dh $@ --builddirectory=builddir

override_dh_auto_configure:
	RSH=rsh LPR=lpr XTERM=xterm XFONTSEL=xfontsel \
        GCORE=gcore ice_cv_find_xp=no ac_cv_lib_Xp_XpSelectInput=no \
	dh_auto_configure -- --with-readline-libraries \
	    --disable-builtin-app-defaults --disable-builtin-manual \
	    --disable-builtin-news --disable-builtin-license

override_dh_auto_test:
	# Disable the make check command, which wants to run ddd interactively

execute_before_dh_auto_build:
	# Upstream ships pre-built .info files but omits fdl-1.3.texi, which makeinfo
	# requires when regenerating documentation. Vendor the GNU FDL source so
	# builds work without adding gnulib as a dependency.
	cp -f debian/vendor/fdl-1.3.texi ddd/fdl-1.3.texi

override_dh_auto_build:
	# Build documentation serially through the Makefile first; automake's makeinfo
	# rules race when multiple targets depend on the same .info file and make runs
	# with parallel jobs. After this the files are up-to-date and the remainder
	# of the build can safely use -jN.
	cd builddir/ddd && $(MAKE) -j1 ../../ddd/ddd.info ../../ddd/ddd-themes.info
	dh_auto_build

override_dh_auto_install:
	dh_auto_install
	rm -f debian/tmp/usr/share/ddd/COPYING

override_dh_auto_clean:
	dh_auto_clean
	rm -f ddd/ddd.info.txt ddd/ddd.info.txt.gz
	rm -f ddd/ddd.info.txt.gz.C
	# Remove the vendored file copied into the source tree before build
	rm -f ddd/fdl-1.3.texi

execute_after_dh_install-arch:
	# The manpage installed contains a reference to a logo .eps file in the
	# build directory which isn't even created; remove this reference to
	# eliminate man warnings.
	sed -i -e '/^\.PSPIC/d' debian/ddd/usr/share/man/man1/ddd.1
