#!/usr/bin/make -f
# -*- makefile -*-
# debian/rules file for simutrans

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
#export VERBOSE  = 1

export CFLAGS   = $(shell dpkg-buildflags --get CFLAGS)
export CCFLAGS  = $(CFLAGS)
export CXXFLAGS = $(shell dpkg-buildflags --get CXXFLAGS)
export LDFLAGS  = $(shell dpkg-buildflags --get LDFLAGS)

include /usr/share/hardening-includes/hardening.make
CFLAGS   += $(HARDENING_CFLAGS)
CXXFLAGS += $(HARDENING_CFLAGS)
LDFLAGS  += $(HARDENING_LDFLAGS)

TARGETS := binary binary-arch binary-indep build build-arch build-indep clean
.PHONY: $(TARGETS)
$(TARGETS):
	dh $@ --parallel

override_dh_auto_build:
	dh_auto_build
	$(MAKE) -C makeobj
	$(MAKE) -C nettools

	convert simutrans.ico -alpha on debian/simutrans.xpm

	[ -d skin ] || mkdir skin
	./build/default/makeobj/makeobj pak ./skin/ ./skins.src/

override_dh_auto_clean:
	dh_auto_clean
	$(MAKE) -C makeobj clean
	$(MAKE) -C nettools clean
	$(RM) -r skin

# These languages will be excluded
BROKEN_LANG = ce cn id tr

override_dh_install:
	dh_install

	install -m 755 build/default/sim $(CURDIR)/debian/simutrans/usr/games/simutrans
	install -m 755 build/default/nettool/nettool $(CURDIR)/debian/simutrans/usr/games/simutrans-nettool

	for lang in $(BROKEN_LANG); do \
	  $(RM) $(CURDIR)/debian/simutrans-data/usr/share/games/simutrans/text/$$lang.tab ; \
	done

override_dh_installchangelogs:
	dh_installchangelogs simutrans/history.txt

override_dh_builddeb:
	dh_builddeb -- -Zxz

# SVN revision and package version to use when building .orig.tar.gz
SVNREV  = 4913
VERSION = 111.0
SVNROOT = svn://tron.homeunix.org/simutrans/simutrans/trunk

get-orig-source:
	svn export --username anon --password "" -r $(SVNREV) $(SVNROOT) simutrans-$(VERSION)

	# source is skins.src/*, only removed to make sure we rebuild it.
	$(RM) simutrans-$(VERSION)/simutrans/skin/menu.WindowSkin.pak
	# freeware, cf. http://www.packetizer.com/security/sha1/ [2011-02-15]
	$(RM) simutrans-$(VERSION)/utils/sha1.cc simutrans-$(VERSION)/utils/sha1.h

	tar c simutrans-$(VERSION) | xz >simutrans_$(VERSION).orig.tar.xz
	$(RM) -r simutrans-$(VERSION)

update-translations:
	dh_testdir
	wget --post-data "version=0&choice=all&submit=Export!" --delete-after "http://simutrans-germany.com/translator/script/main.php?page=wrap"
	wget -N http://simutrans-germany.com/translator/data/tab/language_pack-Base+texts.zip
	unzip -o -d debian/translations language_pack-Base+texts.zip "*.tab"
	$(RM) language_pack-Base+texts.zip
