DIR	= `pwd`

ifeq ($(shell expr "$(MAEMO_VERSION)" "<" 5), 1)
	MAEMODATADIR=/media/mmc2/share/vultures
	EXTRACFLAGS=-Os -DSCREEN_DEPTH=16
else
	MAEMODATADIR=/opt/vultures
	EXTRACFLAGS=-Os -DSCREEN_DEPTH=32
endif

all:
	make build

build:
	make --directory=../.. PREFIX=$(DIR) GAMEDIR=$(DIR)/vultures.dir \
	SHELLDIR=$(DIR) GAMEPERM=0755 CHOWN=true CHGRP=true \
	EXTRACFLAGS="$(EXTRACFLAGS)" \
	-C nethack install

clean:
	make --directory=../.. clean
	rm -f ../../nethack/src/vultureseye
	rm -rf vultureseye vultures.dir debian/vultures

install:
	# Replace game directory name and install startup script
	sed -e 's/^HACKDIR=.*/HACKDIR=$(subst /,\/,$(MAEMODATADIR))/' vultureseye >tmp
ifeq ($(shell expr "$(MAEMO_VERSION)" "<" 5), 1)
	# On Diablo, we will install the binary in rootfs
	sed -e 's/^HACK=.*/HACK=\/usr\/games\/vultureseye\.bin/' tmp >tmp2
	mv tmp2 tmp
endif
	install -m 755 -D tmp $(DESTDIR)/usr/bin/vultureseye
	# Replace screen parameters in the default config
	cat vultures.dir/config/vultures.conf | \
	  sed -e 's/^screen_xsize=.*/screen_xsize=800/' | \
	  sed -e 's/^screen_ysize=.*/screen_ysize=480/' | \
	  sed -e 's/^fullscreen=.*/fullscreen=1/' >tmp
	mv tmp vultures.dir/config/vultures.conf
	# Replace game graphics with Maemo versions
	cp -r graphics/* vultures.dir/graphics
	# Install game data
	install -m 755 -dD vultures.dir $(DESTDIR)$(MAEMODATADIR)
	cp -r vultures.dir/* $(DESTDIR)$(MAEMODATADIR)
ifeq ($(shell expr "$(MAEMO_VERSION)" "<" 5), 1)
	# On Diablo, install the binary in rootfs
	install -m 755 -d $(DESTDIR)/usr/games
	mv $(DESTDIR)$(MAEMODATADIR)/vultureseye $(DESTDIR)/usr/games/vultureseye.bin
endif
	# Install icons, etc
	install -m 644 -D vultures-26x26.png $(DESTDIR)/usr/share/icons/hicolor/26x26/hildon/vultures.png
	install -m 644 -D vultures-40x40.png $(DESTDIR)/usr/share/icons/hicolor/40x40/hildon/vultures.png
	install -m 644 -D vultures-64x64.png $(DESTDIR)/usr/share/icons/hicolor/scalable/hildon/vultures.png
	install -m 644 -D vultures.desktop $(DESTDIR)/usr/share/applications/hildon/vultures.desktop

uninstall:
	rm -rf $(DESTDIR)$(MAEMODATADIR)
	rm -f $(DESTDIR)/usr/bin/vultureseye
	rm -f $(DESTDIR)/usr/share/applications/hildon/vultures.desktop
	rm -f $(DESTDIR)/usr/share/icons/hicolor/26x26/hildon/vultures.png
	rm -f $(DESTDIR)/usr/share/icons/hicolor/40x40/hildon/vultures.png
	rm -f $(DESTDIR)/usr/share/icons/hicolor/scalable/hildon/vultures.png
