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

#export DH_VERBOSE=1

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

CONFIGURE_FLAGS := --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \
		    --prefix=/usr --bindir=/usr/games --with-xpm \
		    --without-rplay --with-esound --without-nas

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
CFLAGS += -Wall

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
	true

build-motif-stamp:
	dh_testdir
	ln -sf /usr/share/misc/config.sub .
	ln -sf /usr/share/misc/config.guess .
	LDFLAGS="$(LDFLAGS)" CFLAGS="$(CFLAGS)" LIBS="-laudiofile" ./configure $(CONFIGURE_FLAGS) --with-motif
	$(MAKE)
	touch $@

build-nomotif-stamp:
	dh_testdir
	[ ! -f Makefile ] || $(MAKE) -i distclean
	LDFLAGS="$(LDFLAGS)" CFLAGS="$(CFLAGS)" LIBS="-laudiofile" ./configure $(CONFIGURE_FLAGS) --without-motif
	$(MAKE)
	touch $@

clean:
	dh_testdir
	dh_testroot
	[ ! -f Makefile ] || $(MAKE) -i distclean
	dh_clean build-motif-stamp build-nomotif-stamp config.sub config.guess

install: install-motif-stamp install-nomotif-stamp
	for INFIX in '' m ; do \
		set -e ; \
		install -D debian/x$${INFIX}abacus.desktop \
			$(CURDIR)/debian/x$${INFIX}abacus/usr/share/applications/x$${INFIX}abacus.desktop ; \
		PIXDIR=$(CURDIR)/debian/x$${INFIX}abacus/usr/share/pixmaps ; \
		install -D -m 0644 $(CURDIR)/pixmaps/abacus.t.xpm $$PIXDIR/x$${INFIX}abacus.t.xpm ; \
		install -D -m 0644 $(CURDIR)/pixmaps/abacus.m.xpm $$PIXDIR/x$${INFIX}abacus.m.xpm ; \
		rm $(CURDIR)/debian/x$${INFIX}abacus/usr/share/games/xabacus/Abacus.ps ; \
	done

install-motif-stamp: build-motif-stamp
	dh_testroot
	$(MAKE) install DESTDIR=$(CURDIR)/debian/xmabacus xapploaddir=/etc/X11/app-defaults

install-nomotif-stamp: build-nomotif-stamp
	dh_testroot
	$(MAKE) install DESTDIR=$(CURDIR)/debian/xabacus xapploaddir=/etc/X11/app-defaults

binary-indep: install
# We have nothing to do by default.

binary-arch: install
	dh_testdir -a
	dh_testroot -a
	dh_installdocs -a -A debian/README.Debian Abacus.ps README TODO
	dh_installmenu -a
	dh_installman -a
	dh_installchangelogs -a ChangeLog
	dh_strip -a
	dh_link -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary: binary-indep binary-arch
.PHONY: build build-arch build-indep build-stamp build-motif-stamp build-nomotif-stamp clean install install-motif-stamp install-nomotif-stamp binary-indep binary-arch binary
