#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

export SED=sed # work-around for broken libtool

# Stuff taken from autotools-dev
export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
	confflags += --build $(DEB_HOST_GNU_TYPE)
else
	confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif

build: configure build-stamp
build-stamp:
	dh_testdir

	./configure $(confflags) --prefix=/usr --bindir=/usr/games --localstatedir=/var/games
	$(MAKE)

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	rm -f intl/libintl.h
	rm -f po/*.gmo

	[ ! -f Makefile ] || $(MAKE) distclean
	[ ! -f Makefile ] || $(MAKE) clean

	dh_clean

#       Update config.sub and config.guess
	-test -r /usr/share/misc/config.sub && \
		cp -f /usr/share/misc/config.sub config.sub
	-test -r /usr/share/misc/config.guess && \
		cp -f /usr/share/misc/config.guess config.guess

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	$(MAKE) install DESTDIR=$(CURDIR)/debian/dopewars
	rm -rf $(CURDIR)/debian/dopewars/var
	mv $(CURDIR)/debian/dopewars/usr/share/ $(CURDIR)/debian/dopewars-data/usr/

	mkdir -p $(CURDIR)/debian/dopewars/usr/share/applications/
	cp $(CURDIR)/dopewars.desktop $(CURDIR)/debian/dopewars/usr/share/applications/

	rm -rf $(CURDIR)/debian/dopewars-data/usr/share/gnome
	rm $(CURDIR)/debian/dopewars-data/usr/share/doc/dopewars/html/LICENCE

	chmod -x $(CURDIR)/debian/dopewars/usr/lib/dopewars/*.so
	chrpath -d $(CURDIR)/debian/dopewars/usr/games/dopewars
	chrpath -d $(CURDIR)/debian/dopewars/usr/lib/dopewars/*

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

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installman doc/dopewars.6
	rm -rf debian/dopewars/usr/man
	dh_installchangelogs ChangeLog
	dh_installmenu
	dh_strip
	dh_compress
	chmod 2755 debian/dopewars/usr/games/dopewars
	chgrp games debian/dopewars/usr/games/dopewars
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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