#!/usr/bin/make -f

DEB_BUILDDIR = builddir

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk

DEB_BUILD_PARALLEL := 1

# Use autoreconf instead of cdbs's version which requires specific
# versions.
common-configure-arch common-configure-indep:: debian/stamp-autotools-files
debian/stamp-autotools-files:
	autoreconf -vfi
	touch $@

clean::
	rm -f debian/stamp-autotools-files

DDD_USERINFO := $(shell grep '^ -- ' debian/changelog | head -1 | \
	sed -e 's/^ -- //' -e 's/  .*$$//')

DEB_CONFIGURE_SCRIPT_ENV += RSH=rsh LPR=lpr XTERM=xterm XFONTSEL=xfontsel \
                            GCORE=gcore ice_cv_find_xp=no \
                            ac_cv_lib_Xp_XpSelectInput=no
DEB_CONFIGURE_EXTRA_FLAGS := --with-readline-libraries \
	--disable-builtin-app-defaults --disable-builtin-manual \
	--disable-builtin-news --disable-builtin-license \
	--with-userinfo="$(DDD_USERINFO)"
CFLAGS += -W -DNDEBUG
CXXFLAGS += -W -DNDEBUG
LDFLAGS += -Wl,--as-needed

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

DEB_INSTALL_DOCS_ALL :=

ifeq ($(DEB_BUILD_ARCH),powerpc)
DEB_MAKE_ENVVARS := LIBELF="-lelf"
else
DEB_MAKE_ENVVARS := LIBELF=""
endif

common-install-arch::
	rm -f $(DEB_DESTDIR)/usr/share/ddd/COPYING

clean::
	rm -f ltmain.sh aclocal.m4 configure ddd/config.h.in
	rm -f depcomp install-sh missing
	rm -f ddd/ddd.info.txt ddd/ddd.info.txt.gz
	rm -f ddd/ddd.info.txt.gz.C
	find . -name Makefile.in | xargs --no-run-if-empty rm -f

# 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.
binary-post-install/ddd::
	sed -i -e '/^\.PSPIC/d' debian/ddd/usr/share/man/man1/ddd.1
