#!/usr/bin/make -f
#export DH_VERBOSE=1
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
PKD   := $(abspath $(dir $(MAKEFILE_LIST)))
DTYPE := +dfsg
PKG   := foobillardplus
UVER  := $(shell dpkg-parsechangelog -l$(PKD)/changelog | grep Version: | cut -d' ' -f2 | cut -d'-' -f1)
REV   := $(shell echo $(UVER) | awk -F"~" '{ print $$2 }' | sed -e 's/svn//' -e 's/$(DTYPE)//')
VER   ?= $(subst $(DTYPE),,$(UVER))
UURL  := http://svn.code.sf.net/p/foobillardplus/code/

%:
	dh $@ --parallel --with autoreconf

override_dh_auto_configure:
	aclocal --force
	autoconf -f
	autoheader -f
	automake -a -c -f
	./configure \
	--enable-network=no \
	--enable-fastmath=no \
	--enable-debian



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

$(PKG)_$(VER)$(DTYPE).orig.tar.xz:
	@echo "# Downloading..."
	svn export --config-option config:miscellany:use-commit-times=yes -r $(REV) \
	$(UURL) $(PKG)-$(VER)
	@echo "# Clean-up..."
	cd $(PKG)-$(VER) \
	&& $(RM) -r -v \
		data/music/*.ogg \
		data/DejaVuSans.ttf \
		data/DejaVuSans-Bold.ttf \
		data/locale/img/gpl.txt \
		osx/ \
		OFL.txt \
		debian/
	@echo "# Packing..."
	find -L "$(PKG)-$(VER)" -xdev -type f -print \
	| sort | XZ_OPT="-7v" tar -caf "$(PKG)_$(VER)$(DTYPE).orig.tar.xz" -T- --owner=root --group=root --mode=a+rX \
	&& $(RM) -r "$(PKG)-$(VER)"
