#!/usr/bin/make -f

derives_from_ubuntu := $(shell (dpkg-vendor --derives-from Ubuntu && echo "yes") || echo "no")

%:
	dh $@ --with autoreconf --with pyppd

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp

override_dh_install:
	dh_install
	
	# Generate PPD files for the HP LaserJet 3500 and 3600
	for n in 3500 3600; do \
		perl -p -e "s:3550(?!\&quot):$${n}:g" $(CURDIR)/debian/printer-driver-pxljr/usr/share/ppd/pxljr/HP-Color_LaserJet_3550-pxljr.ppd > $(CURDIR)/debian/printer-driver-pxljr/usr/share/ppd/pxljr/HP-Color_LaserJet_$${n}-pxljr.ppd ; \
	done
	
	# Allow also PDF as input data format
	perl -p -i -e 's,^\*cupsFilter:\s*\"application/vnd.cups-postscript\s+0\s+foomatic-rip\",*cupsFilter: "application/vnd.cups-postscript 100 foomatic-rip"\n*cupsFilter: "application/vnd.cups-pdf 0 foomatic-rip",' $(CURDIR)/debian/printer-driver-pxljr/usr/share/ppd/pxljr/*.ppd
	
	# Make the page rendering by Ghostscript faster
	perl -p -i -e 's,(\-sDEVICE=ijs),-dNOINTERPOLATE \1,' $(CURDIR)/debian/printer-driver-pxljr/usr/share/ppd/pxljr/*.ppd
	
ifeq ($(derives_from_ubuntu),yes)
	# Install Apport hook on Ubuntu and derivatives
	install -D -m 644 debian/local/apport-hook.py $(CURDIR)/debian/printer-driver-pxljr/usr/share/apport/package-hooks/source_pxljr.py
endif