#!/usr/bin/make -f
# Made with the aid of debmake, by Christoph Lameter,
# games on the sample debian/rules file for GNU hello by Ian Jackson.

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

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

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

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE       ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE      ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

objdir = $(CURDIR)/obj-$(DEB_BUILD_GNU_TYPE)

ifeq ($(DEB_BUILD_GNU_TYPE),alpha-linux)
  export CFLAGS += -O0 -mieee
  export CXXFLAGS += -O0 -mieee
  COMPILER_FLAGS=CFLAGS="-O0 -mieee" CXXFLAGS="-O0 -mieee"
endif

ifeq ($(DEB_BUILD_GNU_TYPE),i386-linux)
  # Uncomment the following 2 lines to enable i686 optimziation
  # You may want to tweak the settings to your likings
  #export CFLAGS=-O3 -march=i686 -ffast-math -finline-functions
  #export CXXFLAGS=-O3 -march=i686 -ffast-math -finline-functions
  XINERAMA=--with-xinerama
endif

-include debian/debiandirs
export kde_bindir=/usr/games

debian/debiandirs: admin/debianrules
	perl -w admin/debianrules echodirs > debian/debiandirs

configure: configure-stamp
configure-stamp:
	dh_testdir

# KDE CVS does not have aclocal.m4 or configure
	if test ! -f configure; then \
		$(MAKE) -f admin/Makefile.common ;\
	fi

# make build directory
	mkdir $(objdir)

# run configure with build tree $(objdir)
	cd $(objdir) && \
	../configure $(configkde) --enable-shared --enable-static $(XINERAMA)

	touch configure-stamp

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

	$(MAKE) -C $(objdir)

	touch build-stamp

clean:
	dh_testdir
	dh_testroot

	-rm -f build-stamp configure-stamp debian/debiandirs

# Remove build tree
	rm -rf $(objdir)
	dh_clean

install: build-stamp
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	$(MAKE) -C $(objdir) install DESTDIR=$(CURDIR)/debian/tmp/

# Put full paths to games into desktop files
	perl -pi -e 's:^Exec=:Exec=/usr/games/:' \
		`find debian/tmp/usr/share/applnk -name \*.desktop -print`

	dh_install

# Generate man pages for the games
	set -e; while read package binary; do \
		install -d -m755 debian/$$package/usr/share/man/man6; \
		soelim -Idebian debian/$$binary.man \
		 >debian/$$package/usr/share/man/man6/$$binary.6; \
	done <debian/manpages.in

# Install upstream changelogs here, so they can be different for each
# package.
	dh_installchangelogs -pkenolaba kenolaba/ChangeLog
	dh_installchangelogs -pkasteroids kasteroids/ChangeLog
	dh_installchangelogs -pkatomic
	dh_installchangelogs -pkbattleship kbattleship/ChangeLog
	dh_installchangelogs -pkblackbox kblackbox/CHANGES
	dh_installchangelogs -pkjumpingcube kjumpingcube/ChangeLog
	dh_installchangelogs -pklines
	dh_installchangelogs -pkmahjongg kmahjongg/ChangeLog
	dh_installchangelogs -pkmines kmines/CHANGELOG
	dh_installchangelogs -pkonquest konquest/ChangeLog
	dh_installchangelogs -pkpat kpat/CHANGES
	dh_installchangelogs -pkpoker kpoker/ChangeLog
	dh_installchangelogs -pkreversi kreversi/ChangeLog
	dh_installchangelogs -pksame ksame/ChangeLog
	dh_installchangelogs -pkshisen kshisen/ChangeLog
	dh_installchangelogs -pksirtet ksirtet/CHANGELOG
	dh_installchangelogs -pksmiletris
	dh_installchangelogs -pksnake ksnake/ChangeLog
	dh_installchangelogs -pksokoban
	dh_installchangelogs -pkspaceduel kspaceduel/ChangeLog
	dh_installchangelogs -pktron ktron/ChangeLog
	dh_installchangelogs -pktuberling
	dh_installchangelogs -plskat
	dh_installchangelogs -pkbounce
	dh_installchangelogs -pkwin4
	dh_installchangelogs -plibkdegames1
	dh_installchangelogs -plibkdegames-dev
	dh_installchangelogs -pkbackgammon
	dh_installchangelogs -pkdegames ChangeLog
	dh_installchangelogs -pkdecarddecks

# Now generate shlibs files
	dh_makeshlibs -plibkdegames1 -V'libkdegames1 (>= 4:3.0.1)'
	dh_makeshlibs -pksirtet -V

# One doc file has to be renamed because there are 2 TODO files
# in libkdegames-dev.  dh_installdocs will take care of generating
# scripts for this directory later.
	install -d -m 755 debian/libkdegames-dev/usr/share/doc/libkdegames-dev
	install -m 644 libkdegames/kgame/TODO \
		debian/libkdegames-dev/usr/share/doc/libkdegames-dev/TODO.kgame

# This single target is used to build all the packages, all at once, or
# one at a time. So keep in mind: any options passed to commands here will
# affect _all_ packages. Anything you want to only affect one package
# should be put in another target, such as the install target.
binary-common:
	dh_testdir
	dh_testroot
#	dh_installchangelogs  (Already done above)
	dh_installdocs
#	dh_installexamples
	dh_installmenu
#	dh_installdebconf
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
	dh_installmime
#	dh_installinit
#	dh_installcron
#	dh_installinfo
	dh_undocumented
	dh_installman
	dh_strip
	dh_link
	dh_compress -X.docbook -X.css -X-license -X.dcl -X.bz2
	dh_fixperms
#	dh_makeshlibs -V   (Also done above.)
	dh_installdeb
#	dh_perl
	dh_shlibdeps -ldebian/libkdegames1/usr/lib:debian/ksirtet/usr/lib
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture independant packages using the common target.
binary-indep: build install
	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: build install
	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

# Any other binary targets build just one binary package at a time.
binary-%: build install
	$(MAKE) -f debian/rules binary-common DH_OPTIONS=-p$*

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