#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
# Modified for ttf-freefont by Peter Hawkins 2002.

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

# This is the debhelper compatibility version to use.
export DH_COMPAT=3

PACKAGE=$(shell dh_listpackages | grep -- -udeb$$)
VERSION=$(shell dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2)
ARCH=$(shell dpkg --print-architecture)
UFILENAME=$(PACKAGE)_$(VERSION)_all.udeb


ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -g
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

configure: configure-stamp
configure-stamp:
	dh_testdir

	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir
	
	tar xvf freefont-sfd.tar
	(cd sfd \
	 && patch -p1 < ../debian/fontforge-bug-workaround.patch \
	 && make -f ../Makefile)

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	-rm -f README AUTHORS CREDITS INSTALL ChangeLog
	-rm -fr sfd

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/ttf-freefont.
	cp sfd/*.ttf debian/ttf-freefont/usr/share/fonts/truetype/freefont/
	cp sfd/*.ttf debian/ttf-freefont-udeb/usr/share/fonts/truetype/freefont/
	cp debian/XftConfig.udeb debian/ttf-freefont-udeb/etc/X11/XftConfig

# Build architecture-dependent files here.
binary-arch: build install
# We have nothing to do by default.

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf
	dh_installdefoma -Nttf-freefont-udeb
	dh_installdocs README -Nttf-freefont-udeb
	dh_installexamples -Nttf-freefont-udeb
	dh_installmenu -Nttf-freefont-udeb
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_installinit
	dh_installcron -Nttf-freefont-udeb
	dh_installman -Nttf-freefont-udeb
	dh_installinfo -Nttf-freefont-udeb
#	dh_undocumented
	dh_installchangelogs -Nttf-freefont-udeb
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
	#No conffile caretaking in udebs
	rm -f debian/ttf-freefont-udeb/DEBIAN/conffiles
#	dh_perl
	dh_shlibdeps
	dh_gencontrol -Nttf-freefont-udeb
	dh_gencontrol -pttf-freefont-udeb -- -fdebian/files~
	dpkg-distaddfile $(UFILENAME) debian-installer optional
	dh_md5sums -Nttf-freefont-udeb
	dh_builddeb -Nttf-freefont-udeb
	dh_builddeb  -pttf-freefont-udeb --filename=$(UFILENAME)

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