#!/usr/bin/make -f
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/simple-patchsys.mk

IS_FREMANTLE=$(shell if grep Fremantle /etc/maemo_version &> /dev/null; then echo y; else echo n; fi)

DEB_OPT_FLAG:=-O2 -pipe -fomit-frame-pointer
#DEB_SOURCE_PACKAGE:=maelstrom
DEB_TAR_SRCDIR:=Maelstrom-3.0.6.8
ifeq ($(IS_FREMANTLE),y)
DEB_CONFIGURE_NORMAL_ARGS:=--prefix=/opt/maelstrom --datarootdir=/usr/share
DEB_CONFIGURE_EXTRA_FLAGS:=--enable-maemo
else
DEB_CONFIGURE_EXTRA_FLAGS:=--enable-maemo
endif
#DEB_AUTO_UPDATE_AUTOCONF=2.59
#DEB_AUTO_UPDATE_AUTOMAKE=1.8

include /usr/share/cdbs/1/rules/tarball.mk

install/maelstrom::
	@echo "*** Fixing up things for maemo"
	install -d -m 755 debian/maelstrom/usr/bin/
ifeq ($(IS_FREMANTLE),y)
	@echo "*** Fremantle"
	sed -e s,@PREFIX@,/opt/maelstrom/bin, debian/Maelstrom.sh.in > debian/maelstrom/usr/bin/Maelstrom
	strip -g debian/maelstrom/opt/maelstrom/bin/Maelstrom
	chmod 666 debian/maelstrom/opt/maelstrom/data/Maelstrom-Scores
else
	@echo "*** Diablo/Chinook"
	mv debian/maelstrom/usr/bin/Maelstrom debian/maelstrom/usr/games/Maelstrom/Maelstrom
	sed -e s,@PREFIX@,/usr/games/Maelstrom, debian/Maelstrom.sh.in > debian/maelstrom/usr/bin/Maelstrom
	chmod 755 debian/maelstrom/usr/bin/Maelstrom
	strip -g debian/maelstrom/usr/games/Maelstrom/Maelstrom
	chmod 666 debian/maelstrom/usr/games/Maelstrom/Maelstrom-Scores
endif
	chmod 755 debian/maelstrom/usr/bin/Maelstrom

