#!/usr/bin/make -f
#export DH_VERBOSE=1
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
DPATH := $(abspath $(dir $(MAKEFILE_LIST)))
DTYPE := +dfsg
PKG := foobillardplus
VER ?= 3.43~svn168
REV := $(shell echo $(VER) | awk -F"~" '{ print $$2 }' | sed 's/svn//' )


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

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
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) \
	"https://foobillardplus.svn.sourceforge.net/svnroot/foobillardplus" \
	$(PKG)-$(VER)
	@echo "# Clean-up..."
	cd $(PKG)-$(VER) \
	&& $(RM) -r -v \
		data/music/*.ogg \
		data/*.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)"
