#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
#
# Modified to make a template file for a multi-binary package with separated
# build-arch and build-indep targets  by Bill Allombert 2001

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

DPKG_EXPORT_BUILDFLAGS=1
include /usr/share/dpkg/buildflags.mk
LDFLAGS += -Wl,--as-needed

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

DEB_CONFIGURE_EXTRA_FLAGS := --with-optim=$(DEB_OPTFLAGS) --libdir=/usr/lib/$(DEB_HOST_MULTIARCH) --mandir=/usr/share/man --enable-static --enable-debug

DEB_MAKE_INSTALL_TARGET := install BUILDROOT=$(DEB_DESTDIR)
DEB_INSTALL_CHANGELOGS_ALL := CHANGES.txt

#DEB_DH_STRIP_ARGS := --dbg-package=cups-filters-dbg
DEB_DH_INSTALL_SOURCEDIR := debian/tmp
DPKG_GENSYMBOLS_CHECK_LEVEL=4
export DPKG_GENSYMBOLS_CHECK_LEVEL

post-patches::
	set -e; if dpkg --compare-versions `dpkg-query -W --showformat '$${Version}' libpoppler-dev` lt 0.18 && ! [ -e debian/patches/stamp-poppler-applied ]; then \
	    echo '---- Applying poppler < 0.18 patch'; \
	    patch -p1 --no-backup-if-mismatch < debian/patches/poppler-pre-0.18.patch; \
	    touch debian/patches/stamp-poppler-applied; \
	fi

clean::
	if [ -e debian/patches/stamp-poppler-applied ]; then \
	    echo '---- Unapplying poppler < 0.18 patch'; \
	    patch -Rp1 --no-backup-if-mismatch < debian/patches/poppler-pre-0.18.patch; \
	    rm debian/patches/stamp-poppler-applied; \
	fi

cleanbuilddir::
	[ ! -f Makedefs ] || make distclean

binary-post-install/cups-filters::
	# Ubuntu-specific stuff
	#  - Install Apport hook
	#  - Replace standard test page template by Ubuntu-branded one
	if dpkg-vendor --is ubuntu; then \
	   install -D -m 644 debian/local/apport-hook.py debian/$(cdbs_curpkg)/usr/share/apport/package-hooks/source_cups-filters.py; \
	   install -D -m 644 debian/local/default-testpage.pdf debian/$(cdbs_curpkg)/usr/share/cups/data/default-testpage.pdf; \
	fi

	# Make the serial backend run as root, since /dev/ttyS* are
	# root:dialout and thus not accessible as user lp
	chmod go-x debian/$(cdbs_curpkg)/usr/lib/cups/backend/serial
