#!/usr/bin/make -f
#export DH_VERBOSE=1
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
#export DEB_BUILD_OPTIONS=nostrip noopt
PKD    := $(abspath $(dir $(MAKEFILE_LIST)))
VER    := $(shell dpkg-parsechangelog -l$(PKD)/changelog -SVersion | cut -d- -f1)
PKG    := marsshooter
UURL   := https://github.com/jwrdegoede/M.A.R.S..git
COMMIT := 985c26889f5397db90be84f4bb8316e6ceafa75e


%:
	dh $@ --parallel

override_dh_auto_build-indep:
	convert -monitor -resize 32x32 resources/mars.xpm mars.xpm

.PHONY: get-orig-source
## http://wiki.debian.org/onlyjob/get-orig-source
get-orig-source: $(PKG)_$(VER).orig.tar.xz
	@

$(PKG)_$(VER).orig.tar.xz:
	@echo "# Cloning upstream git repository..."
	git clone $(UURL) $(PKG)-$(VER)
	cd $(PKG)-$(VER) \
	&& git checkout -b debiansource $(COMMIT) \
	&& echo "# Setting times..." \
	&& for F in $$(git ls-tree -r --name-only HEAD); \
	do touch --no-dereference -d "$$(git log -1 --format="%ai" -- $$F)" "$$F"; done \
	&& echo "# Cleaning-up..." \
	&& $(RM) -r -v \
		data/fonts/* \
		ext_libs_for_windows \
		.git/ \
	&& touch data/fonts/.dont_delete_me
	@echo "# Packing..."
	find -L "$(PKG)-$(VER)" -xdev -type f -print | sort \
	| XZ_OPT="-6v" tar -caf "$(PKG)_$(VER).orig.tar.xz" -T- --owner=root --group=root --mode=a+rX \
	&& $(RM) -r "$(PKG)-$(VER)"
