#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# begin get-orig-source stuff
MAKEFILE = $(firstword $(MAKEFILE_LIST))
DEBIAN_DIR = $(dir $(MAKEFILE))
SOURCE_DIR = $(DEBIAN_DIR)/..
PACKAGE = $(shell sed -n 's/^Source: //p' $(DEBIAN_DIR)/control)
CURRENT_VERSION = $(shell dpkg-parsechangelog -l$(DEBIAN_DIR)/changelog | \
	sed -n 's/-.*$$//; s/^Version: //p')
USCAN = uscan \
	--upstream-version $(CURRENT_VERSION) \
	--package $(PACKAGE) \
	--watchfile $(DEBIAN_DIR)/watch
VERSION ?= $(shell $(USCAN) --dehs --no-download | \
	sed -n 's/.*<upstream-version>\(.*\)<\/upstream-version>.*/\1/p')

get-orig-source:
	$(USCAN) \
		--force-download \
		--download \
		--destdir . \
		--rename
	if [ -d "$(PACKAGE)-$(VERSION)" ]; then \
		echo "$(PACKAGE)-$(VERSION) is in the way, bailing out!"; \
		exit 1; \
	fi
	tar -xzf $(PACKAGE)_$(VERSION).orig.tar.gz
	mv \
		$(PACKAGE)-$(VERSION) \
		$(PACKAGE)-$(VERSION)+dfsg
	GZIP="-9fn --rsyncable" tar \
		--exclude=src/haserl_lualib.inc \
		-czf $(PACKAGE)_$(VERSION)+dfsg.orig.tar.gz \
		$(PACKAGE)-$(VERSION)+dfsg
	rm -rf \
		$(PACKAGE)_$(VERSION).orig.tar.gz \
		$(PACKAGE)_$(VERSION)+dfsg


# end get-orig-source stuff


# Disable bash extensions because they don't compile, and haserl's default shell
# isn't bash anyway
override_dh_auto_configure:
	dh_auto_configure -- \
		--enable-luashell \
		--enable-luacshell \
		--enable-bashshell \
		--disable-bash-extensions \
		--enable-subshell=/bin/sh \
		--with-lua=lua5.1

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog

clean:
	dh $@
	debconf-updatepo

%:
	dh $@

