#!/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 --mandir=/usr/share/man \
		    --with-xpm --without-rplay --with-esound --without-nas

CFLAGS = -Wall -g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
        CFLAGS += -O0
else
        CFLAGS += -O2
endif

build:
	true

build-motif-stamp:
	dh_testdir
	CFLAGS="$(CFLAGS)" ./configure $(CONFIGURE_FLAGS) --with-motif
	$(MAKE)
	touch $@

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

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

install: install-motif-stamp install-nomotif-stamp
	install -D debian/xabacus.desktop \
		$(CURDIR)/debian/xabacus/usr/share/applications/xabacus.desktop;
	install -D debian/xmabacus.desktop \
		$(CURDIR)/debian/xmabacus/usr/share/applications/xmabacus.desktop;
	for INFIX in '' m ; do \
		set -e ; \
		PIXDIR=$(CURDIR)/debian/x$${INFIX}abacus/usr/share/pixmaps ; \
		install -D -m 0644 $(CURDIR)/icons/abacus.t.xpm $$PIXDIR/x$${INFIX}abacus.t.xpm ; \
		install -D -m 0644 $(CURDIR)/icons/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
	dh_installmenu -a
	dh_installman -a
	dh_installchangelogs -a
	dh_strip -a
	dh_link -a
	dh_desktop -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 clean binary-indep binary-arch binary
