#!/usr/bin/make -f
# Sample debian/rules that uses debhelper. 
# GNU copyright 1997 by Joey Hess.
#
# This version is for a hypothetical package that builds an
# architecture-dependant package, as well as an architecture-independent
# package.

# This has to be exported to make some magic below work.
export DH_OPTIONS

PACKAGE         = dossizola
PKGDIR          = $(shell pwd)/debian/$(PACKAGE)
SHAREROOTDIR    = $(PKGDIR)/usr/share
DESKTOPDIR      = $(SHAREROOTDIR)/applications
ICONDIR         = $(SHAREROOTDIR)/icons

# DEB_BUILD_OPTIONS handling
CFLAGS = -g # -Wall
INSTALL = install
INSTALL_PROGRAM = $(INSTALL) -p    -o root -g root  -m  755
INSTALL_SCRIPT  = $(INSTALL) -p    -o root -g root  -m  755

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
CFLAGS += -O0
else
CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
INSTALL_PROGRAM += -s
endif

#

topdir=$(shell pwd)
debdir=${topdir}/debian
tmpdir=${debdir}/tmp
imgdir=${tmpdir}/usr/share/games/dossizola/images

configure-stamp:
	dh_testdir

	cp -vf /usr/share/misc/config.sub .
	cp -vf /usr/share/misc/config.guess .

	CFLAGS="${CFLAGS}" ./configure --datadir=/usr/share/games --bindir=/usr/games

	touch configure-stamp

build: configure-stamp build-stamp
build-stamp:
	dh_testdir

	$(MAKE)
	cd debian && docbook2man dossizola.sgml

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	[ ! -f Makefile ] || $(MAKE) clean
	rm -f config.cache config.status config.log
	rm -f Makefile
	dh_clean

install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	$(MAKE) install \
		prefix=${tmpdir}/usr/share/games \
		bindir=${tmpdir}/usr/games \
		INSTALL=${INSTALL} \
		INSTALL_PROGRAM="${INSTALL_PROGRAM}"

	dh_movefiles

	install -m 644 -D debian/$(PACKAGE).desktop $(DESKTOPDIR)/$(PACKAGE).desktop
	install -m 644 -D debian/$(PACKAGE).png $(ICONDIR)/$(PACKAGE).png

	test -z `find ${tmpdir} -type f`

# Build architecture-independent files here.
# Pass -i to all debhelper commands in this target to reduce clutter.
binary-indep: DH_OPTIONS=-i
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs AUTHORS README TODO
#	dh_installexamples
	dh_installmenu
	dh_installchangelogs # ChangeLog
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
# Pass -a to all debhelper commands in this target to reduce clutter.
binary-arch: DH_OPTIONS=-a
binary-arch: build install
	dh_testdir
	dh_testroot
#	dh_installdebconf

	mkdir -p ${debdir}/dossizola/usr/share/doc/dossizola-data
	ln -s dossizola-data ${debdir}/dossizola/usr/share/doc/dossizola
	dh_installdocs
	rm -rf ${debdir}/dossizola/usr/share/doc/dossizola-data

	dh_installexamples
	dh_installmenu
	dh_installman debian/dossizola.6
	dh_installinfo
#	dh_installchangelogs ChangeLog
	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
