#!/usr/bin/make -f

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

configure: configure-stamp
configure-stamp:
	dh_testdir
	touch configure-stamp

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp: configure-stamp
	dh_testdir
	cd debian/local/jbigkit-libjbig85/; \
	$(MAKE); \
	cd ../../..
	$(MAKE) OPTIM_CXXFLAGS="$(CXXFLAGS) -I`pwd`/debian/local/jbigkit-libjbig85/" rastertoqpdl_LDFLAGS="$(LDFLAGS) -L`pwd`/debian/local/jbigkit-libjbig85/" V=1
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	# We must specify the paths to the local libjbig85 files also for "make
	# clean" as the Makefile always recalculates the dependencies of the
	# source code files. Without libjbig85 files "make" would fall into an
	# infinite loop
	$(MAKE) OPTIM_CXXFLAGS="$(CXXFLAGS) -I`pwd`/debian/local/jbigkit-libjbig85/" rastertoqpdl_LDFLAGS="$(LDFLAGS) -L`pwd`/debian/local/jbigkit-libjbig85/" V=1 clean
	cd debian/local/jbigkit-libjbig85/; \
	$(MAKE) clean; \
	cd ../../..
	rm -rf optimized .defs.mk
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	# Also supply paths to libjbig85 here, as otherwise "make" falls into
	# infinite loop
	$(MAKE) OPTIM_CXXFLAGS="$(CXXFLAGS) -I`pwd`/debian/local/jbigkit-libjbig85/" rastertoqpdl_LDFLAGS="$(LDFLAGS) -L`pwd`/debian/local/jbigkit-libjbig85/" V=1 DESTDIR=$(CURDIR)/debian/printer-driver-splix CUPSPPD=/usr/share/ppd/splix install
	# Remove the PPD files for the Samsung CLP-610 and CLP-610ND, these
	# printers do not work with SpliX
	rm debian/printer-driver-splix/usr/share/ppd/splix/samsung/clp610*.ppd
	# Compress the PPD files with pyppd
	dh_pyppd -pprinter-driver-splix
	# Install the ppd updater data file so that CUPS can update the
	# PPDs of the already existing queues after each update of the 
	# splix package
	install -D --mode=644 debian/splix.ppd-updater $(CURDIR)/debian/printer-driver-splix/usr/share/cups/ppd-updaters/splix.ppd-updater
	# Install Apport hook
	install -D -m 644 debian/local/apport-hook.py $(CURDIR)/debian/printer-driver-splix/usr/share/apport/package-hooks/source_splix.py

# Build architecture-dependent files here.
binary-arch: install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
