#! /usr/bin/make -f
#
# debian/rules file for d1x-rebirth
# zico <zico@dxx-rebirth.com>
# Thu, 05 May 2011 01:22:39 +0100
#

package = d1x-rebirth

SCONS = scons -Q
SCONSFLAGS = prefix=/usr
BINARY = d1x-rebirth

PREFIX = /usr
BIN_DIR = $(PREFIX)/games
SHARE_DIR = $(PREFIX)/share
DATA_DIR = $(SHARE_DIR)/games/$(package)
DEBIAN_TMP = debian/tmp

patch:	patch-stamp
patch-stamp:
	test -d debian/patches
	@for patch in debian/patches/*.diff; do \
                echo "Applying $$patch"; \
                patch < $$patch; \
        done
	touch $@

build:	patch build-stamp
build-stamp:
	$(SCONS) $(SCONSFLAGS)
	strip $(BINARY)
	touch $@

clean:
	$(SCONS) -c
	rm -rf patch-stamp build-stamp *~ $(DEBIAN_TMP) debian/*~ debian/files* debian/substvars

binary-indep:   checkroot
        $(checkdir)

# There are no architecture-independent files to be uploaded
# generated by this package.  If there were any they would be
# made here.

TMP_BIN_DIR = $(DEBIAN_TMP)/$(BIN_DIR)
TMP_SHARE_DIR = $(DEBIAN_TMP)/$(SHARE_DIR)
TMP_DATA_DIR = $(DEBIAN_TMP)/$(DATA_DIR)

binary-arch:    checkroot build
	$(checkdir)
	rm -rf $(DEBIAN_TMP)
	install -d $(DEBIAN_TMP)/DEBIAN $(TMP_BIN_DIR) $(TMP_DATA_DIR)
	install -d $(TMP_DATA_DIR)/missions $(TMP_DATA_DIR)/demos $(TMP_DATA_DIR)/screenshots $(TMP_DATA_DIR)/Music
	install -d $(TMP_SHARE_DIR)/applications $(TMP_SHARE_DIR)/pixmaps
	install -m 755 debian/postinst debian/prerm $(DEBIAN_TMP)/DEBIAN
	install -m 755 $(BINARY)      $(TMP_BIN_DIR)
	install -m 644 d1x.ini        $(TMP_DATA_DIR)
	install -m 644 CHANGELOG.txt  $(TMP_DATA_DIR)
	install -m 644 COPYING.txt    $(TMP_DATA_DIR)
	install -m 644 README.txt     $(TMP_DATA_DIR)
	unzip d1xr-hires.zip -d $(TMP_DATA_DIR)
	install -m 644 d1x-rebirth.desktop $(TMP_SHARE_DIR)/applications
	install -m 644 d1x-rebirth.xpm $(TMP_SHARE_DIR)/pixmaps
	dpkg-shlibdeps $(TMP_BIN_DIR)/$(BINARY)
	dpkg-gencontrol -isp
	chown -R root:root $(DEBIAN_TMP)
	chmod -R u+w,go=rX $(DEBIAN_TMP)
	dpkg --build $(DEBIAN_TMP) ..

define checkdir
        test -f SConstruct -a -f debian/rules
endef

binary: binary-indep binary-arch

checkroot:
	$(checkdir)
	test $$(id -u) = 0

.PHONY: binary binary-arch binary-indep clean checkroot

