#!/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

export DEB_BUILD_HARDENING=1
# http://www.cups.org/str.php?L3765
export LC_MESSAGES=C

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
LDFLAGS := -Wl,--as-needed
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::
	# Install Apport hook on Ubuntu
	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; \
	fi

	# Modify the cost factor for the Poppler-based pdftoraster filter of
	# the PDF filter add-on so that Ghostscript's gstoraster gets preferred.
	# (This will get merged upstream in 1.0b2)
	sed -i -r -e '/\spdftoraster$$/ { s/66/100/ }' \
	  $(DEB_DESTDIR)/../cups-filters/usr/share/cups/mime/cupsfilters.convs

	# Install documentation of the PDF CUPS filters
	# (This will get merged upstream in 1.0b2)
	mkdir -p $(DEB_DESTDIR)/../cups-filters/usr/share/doc/cups-filters/examples/
	install -m 644 debian/local/README.pdf-filters $(DEB_DESTDIR)/../cups-filters/usr/share/doc/cups-filters/
	#install -m 644 filter/test.sh $(DEB_DESTDIR)/../cups-filters/usr/share/doc/cups-filters/examples/texttopdf-text.sh
	install -m 644 ppd/HP-PhotoSmart_Pro_B8300-hpijs-pdftoijs.ppd $(DEB_DESTDIR)/../cups-filters/usr/share/doc/cups-filters/examples/

	# 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

binary-post-install/libcupsfilters-dev::
	mkdir -p debian/$(cdbs_curpkg)/usr/include/cups-filters/
	install -m 644 cupsfilters/driver.h debian/$(cdbs_curpkg)/usr/include/cups-filters/
	install -m 644 cupsfilters/image.h debian/$(cdbs_curpkg)/usr/include/cups-filters/
	mkdir -p debian/$(cdbs_curpkg)/usr/lib/$(DEB_HOST_MULTIARCH)/
	cp -d cupsfilters/libcupsfilters.so debian/$(cdbs_curpkg)/usr/lib/$(DEB_HOST_MULTIARCH)/
	install -m 644 cupsfilters/libcupsfilters.a debian/$(cdbs_curpkg)/usr/lib/$(DEB_HOST_MULTIARCH)/
