#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/ruby-pkg-tools/1/class/ruby-setup-rb.mk

DEB_RUBY_CONFIG_ARGS = --installdirs=std --datadir=/usr/share/libprawn-ruby/
DEB_INSTALL_EXAMPLES_libprawn-ruby-common = examples/*
DEB_INSTALL_DOCS_ALL = README debian/README.missing_images
clean::
	# Until we get clearance for upstream's images' copyrights, we
	# will replace them with others that are redistributable. 
	[ $$(md5sum data/images/barcode_issue.png | cut -f 1 -d ' ')      = d99fb09eb471c6bfa99b7d87dcb8292b ] || false
	[ $$(md5sum data/images/dice.png | cut -f 1 -d ' ')               = 1f2831c87ff266dd0ebce7bd83051297 ] || false
	[ $$(md5sum data/images/fractal.jpg | cut -f 1 -d ' ')            = 88cc7b1697fe238c62ae8d96a8a096d5 ] || false
	[ $$(md5sum data/images/pigs.jpg | cut -f 1 -d ' ')               = b0cbf86feceea0ae3ee2d9567793a21f ] || false
	[ $$(md5sum data/images/rails.png | cut -f 1 -d ' ')              = 4a11793ba4308f93643907d9f5dd2a78 ] || false
	[ $$(md5sum data/images/ruport.png | cut -f 1 -d ' ')             = a97752e8cddd5a89f870bfb0437a4b19 ] || false
	[ $$(md5sum data/images/ruport_transparent.png | cut -f 1 -d ' ') = 1a7a8ada7c931cb0c266a20dcfaf28b2 ] || false
	[ $$(md5sum data/images/ruport_type0.png | cut -f 1 -d ' ')       = 5bf488feae3dc48374ecbed8f60d69f1 ] || false
	[ $$(md5sum data/images/stef.jpg | cut -f 1 -d ' ')               = 3bbc20e6a17f0d0130184fc3da8111a3 ] || false
	rm -f lib/ttfunk lib/ttfunk.rb lib/pdf 

makebuilddir/libprawn-ruby::
	if ! [ -d ttfunk/ -a -d pdfinspector/ ] ; then \
		echo " *!*This package needs the 'ttfunk' and 'pdfinspector'"\
		"tarballs in order to be built.\n" \
		"*!*Please see the README.source file for further details."; \
		exit 1; \
	fi
	[ -e lib/ttfunk    ] || ln -s ../ttfunk/lib/ttfunk lib/
	[ -e lib/ttfunk.rb ] || ln -s ../ttfunk/lib/ttfunk.rb lib/
	[ -e lib/pdf       ] || ln -s ../pdfinspector/lib/pdf lib/

install/libprawn-ruby1.8::
	# Files common to 1.8 and 1.9 versions are moved to libprawn-ruby-common
	mkdir -p ./debian/libprawn-ruby-common/usr/share/doc/libprawn-ruby-common
	mv ./debian/$(cdbs_curpkg)/usr/share/libprawn-ruby/ ./debian/libprawn-ruby-common/usr/share/
	# Examples are provided by libprawn-ruby-common
	mkdir -p ./debian/$(cdbs_curpkg)/usr/share/doc/$(cdbs_curpkg)/
	ln -s ../libprawn-ruby-common/examples/ ./debian/$(cdbs_curpkg)/usr/share/doc/$(cdbs_curpkg)/examples

install/libprawn-ruby1.9::
	# The relevant files were moved to libprawn-ruby-common in
	# install/libprawn-ruby1.8
	rm -rf ./debian/$(cdbs_curpkg)/usr/share/libprawn-ruby/
	# Examples are provided by libprawn-ruby-common
	mkdir -p ./debian/$(cdbs_curpkg)/usr/share/doc/$(cdbs_curpkg)/
	ln -s ../libprawn-ruby-common/examples/ ./debian/$(cdbs_curpkg)/usr/share/doc/$(cdbs_curpkg)/examples

install/libprawn-ruby-common::
	# Instead of copying fonts that are often found in Debian
	# systems, recommend the relevant packages and symlink
	# them. That way, lintian will be happier.
	rm ./debian/$(cdbs_curpkg)/usr/share/libprawn-ruby/fonts/DejaVuSans.ttf
	ln -s ../../fonts/truetype/ttf-dejavu/DejaVuSans.ttf \
		./debian/$(cdbs_curpkg)/usr/share/libprawn-ruby/fonts/DejaVuSans.ttf
	rm ./debian/$(cdbs_curpkg)/usr/share/libprawn-ruby/fonts/Dustismo_Roman.ttf
	ln -s ../../fonts/truetype/dustin/Dustismo_Roman.ttf \
		./debian/$(cdbs_curpkg)/usr/share/libprawn-ruby/fonts/Dustismo_Roman.ttf
	rm ./debian/$(cdbs_curpkg)/usr/share/libprawn-ruby/fonts/gkai00mp.ttf
	ln -s ../../fonts/truetype/arphic/gkai00mp.ttf \
		./debian/$(cdbs_curpkg)/usr/share/libprawn-ruby/fonts/gkai00mp.ttf
