#!/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 --localstatedir=/home/user/.dopewars
	$(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_clean -k
	dh_installdirs

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

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

	install -d $(CURDIR)/debian/dopewars/usr/share/icons/hicolor/26x26/hildon/
	install -d $(CURDIR)/debian/dopewars/usr/share/icons/hicolor/40x40/hildon/
	install -d $(CURDIR)/debian/dopewars/usr/share/icons/hicolor/scalable/hildon/

	install -m 644 $(CURDIR)/debian/26x26.png $(CURDIR)/debian/dopewars/usr/share/icons/hicolor/26x26/hildon/dopewars-pill.png
	install -m 644 $(CURDIR)/debian/40x40.png $(CURDIR)/debian/dopewars/usr/share/icons/hicolor/40x40/hildon/dopewars-pill.png
	install -m 644 $(CURDIR)/debian/64x64.png $(CURDIR)/debian/dopewars/usr/share/icons/hicolor/scalable/hildon/dopewars-pill.png

	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/bin/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_strip
	dh_compress
	chown root:root debian/dopewars/usr/bin/dopewars
	chmod 755 debian/dopewars/usr/bin/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
