#!/usr/bin/make -f
# -*- makefile -*-

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/patchsys-quilt.mk


#FONT_PATH = $(shell fc-match --verbose 'DejaVu Sans' | grep 'file:' | sed -e 's/.*file: "\(.*\)"(s)/\1/')
#DEB_CONFIGURE_EXTRA_FLAGS += --bindir=\$${prefix}/games --with-datadir-name=\$${prefix}/share/games/wormux --with-localedir-name=\$${prefix}/share/locale --with-font-path=$(FONT_PATH)
DEB_CONFIGURE_EXTRA_FLAGS += --bindir=\$${prefix}/games --with-datadir-name=\$${prefix}/share/games/wormux-data --with-localedir-name=\$${prefix}/share/locale --enable-maemo
DEB_DH_INSTALL_SOURCEDIR = debian/tmp
DEB_FIXPERMS_EXCLUDE = /usr/share/games/

# Use hardware floating point (using CPPFLAGS because everything else get overwritten)
ifeq ($(DEB_BUILD_ARCH), armel)
#CPPFLAGS += -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -mfpu=vfp -mfloat-abi=softfp -DNDEBUG
CPPFLAGS +=  -mfpu=vfp -mfloat-abi=softfp
endif

srcpkg = $(shell dpkg-parsechangelog | sed -ne 's/Source: *//p')
srcver = $(shell dpkg-parsechangelog | sed -ne 's/Version: *\(.*:\)\?\(.*\)-.*$$/\2/p')

#{{{ generic rules

../$(srcpkg)_$(srcver).orig.tar.gz:
	@if git rev-parse --git-dir >/dev/null 2>&1; then                 \
	    pristine-tar checkout $@;                                     \
	fi

check-tarball: ../$(srcpkg)_$(srcver).orig.tar.gz

.PHONY: check-tarball

#}}}
#{{{ maintainer stuff

refresh-patches: check-tarball
	@dh_testdir
	@echo 'refreshing debian/patches:'
	@rm -rf '$(CURDIR)'/debian/patches
	@mkdir -p '$(CURDIR)'/debian/patches
	@cd '$(CURDIR)'/debian/patches && git format-patch upstream..upstream+patches
	@echo .

#}}}

install/wormux::
	#mkdir -p debian/tmp/usr/share/pixmaps
	#cp debian/wormux_*.xpm debian/tmp/usr/share/pixmaps
	mkdir -p debian/tmp/usr/games
	cp debian/warmux.sh debian/tmp/usr/games
	mkdir -p debian/tmp/usr/share/applications/hildon
	cp debian/warmux.desktop debian/tmp/usr/share/applications/hildon
	mkdir -p debian/tmp/usr/share/dbus-1/services
	cp debian/warmux.service debian/tmp/usr/share/dbus-1/services
	mkdir -p debian/tmp/usr/share/icons/hicolor/32x32/apps
	cp data/icon/warmux_32x32.png debian/tmp/usr/share/icons/hicolor/32x32/apps/warmux.png
	#mkdir -p debian/tmp/usr/share/icons/hicolor/128x128/apps
	#cp data/wormux_128x128.png debian/tmp/usr/share/icons/hicolor/128x128/apps/warmux.png
	mkdir -p debian/tmp/usr/share/icons/hicolor/scalable/apps
	cp data/icon/warmux_64x64.png debian/tmp/usr/share/icons/hicolor/scalable/apps/warmux.png

install/wormux-data::
	#rm -r debian/tmp/usr/share/games/wormux/font
	#rm debian/tmp/usr/share/games/wormux-data/*.xpm
	#rm debian/tmp/usr/share/games/wormux-data/*.svg
	#rm debian/tmp/usr/share/games/wormux-data/*.png
	chown -R user.root debian/wormux-data/usr/share/games/*
	chown -R user.root debian/tmp/usr/share/games/*

# use this rule manually to update the build dependencies
# updating them automatically is evil and is a reason for
# rejects for NEW processing;
# see why in this bug:
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=311724
update_control::
	debian/update_control

#binary-predeb/wormux::
#	maemo-optify wormux

#binary-predeb/wormux-data::
#	maemo-optify wormux-data
