#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

%:
	dh $@ --parallel

override_dh_auto_configure:
	chmod u+x tilePlacementGames/game1/configure
	cd tilePlacementGames/game1 && platformSelection=1 ./configure

override_dh_auto_build:
	mkdir -p 256x256 128x128 64x64 32x32
	convert -scale 256x256 tilePlacementGames/game1/gameSource/iPhone/largeIcon2.png 256x256/primrose.png 
	cp -f tilePlacementGames/game1/build/macOSX/iconColor.png 128x128/primrose.png
	convert -background None -gravity center -extent 64x64 tilePlacementGames/game1/gameSource/iPhone/icon.png 64x64/primrose.png
	cp -f tilePlacementGames/game1/build/win32/icon.png 32x32/primrose.png
	convert 32x32/primrose.png 32x32/primrose.xpm
	$(MAKE) -C tilePlacementGames/game1/gameSource PLATFORM_LINK_FLAGS="-lGL -lSDL -lpthread $(LDFLAGS)" PLATFORM_COMPILE_FLAGS="$(CXXFLAGS) $(CPPFLAGS) -DETCDIR=\\\"/etc/primrose\\\" -DDATADIR=\\\"/usr/share/games/primrose/\\\""

override_dh_auto_clean:
	[ ! -f tilePlacementGames/game1/gameSource/Makefile ] || $(MAKE) -C tilePlacementGames/game1/gameSource clean
	rm -f tilePlacementGames/game1/gameSource/Makefile
	rm -f tilePlacementGames/game1/gameSource/Makefile.minorGems_dependencies
	rm -rf 256x256 128x128 64x64 32x32

override_dh_installchangelogs:
	dh_installchangelogs tilePlacementGames/game1/documentation/changeLog.txt

V=6
P=Primrose
p=primrose
sfp=primrose/primrose-game

get-orig-source:
	wget -c http://downloads.sourceforge.net/project/$(sfp)/v$(V)/$(P)_$(V)_UnixSource.tar.gz
	tar zxf $(P)_$(V)_UnixSource.tar.gz
	# Pre-built Windows libraries, unused
	rm $(P)_$(V)_UnixSource/tilePlacementGames/game1/build/win32/*.dll
	# non-free, unused
	rm -r $(P)_$(V)_UnixSource/minorGems/util/development/fortify
	rm $(P)_$(V)_UnixSource/minorGems/graphics/openGL/tga.*
	rm $(P)_$(V)_UnixSource/minorGems/graphics/openGL/texture.*
	mv $(P)_$(V)_UnixSource $(p)-$(V)+dfsg1.orig
	tar zcf ../$(p)_$(V)+dfsg1.orig.tar.gz $(p)-$(V)+dfsg1.orig
	rm -r $(P)_$(V)_UnixSource.tar.gz $(p)-$(V)+dfsg1.orig
