#!/usr/bin/make -f

export DH_VERBOSE=1

uversion=$(shell uscan --report --dehs |grep upstream-version | cut -d\< -f2 | cut -d\> -f2)
keepers=icons lib steam.6 steam steam.desktop steam_install_agreement.txt
orig=../steam_$(uversion).orig.tar.xz
dest=../steam-$(uversion).orig

build-arch:
ifneq ($(DEB_BUILD_ARCH), i386)
	@echo "error: $(DEB_BUILD_ARCH) is not a supported architecture"
	@exit 1
endif

%:
	dh $@

override_dh_auto_configure:
	python debian/scripts/templates-helper

override_dh_clean:
	dh_clean -- debian/templates
	python debian/scripts/copyright-helper \
	    debian/copyright.in debian/copyright

get-orig-source:
	@test "$(uversion)" = "" && \
	    echo "There is no new upstream source file." && exit 1 || true
	uscan --force-download --no-symlink
	rm -f $(orig)
	mkdir -p $(dest)
	tar xf ../steam_$(uversion).tar.gz --strip-components=1 -C $(dest)
	rm -f $(dest)/steam
	cd $(dest) && tar xf bootstrap*.tar.* --strip-components=1
	cd $(dest) && for file in *; do \
	    echo $(keepers) | grep -q $$file || rm -rf $$file; done
	tar cJf $(orig) $(dest)
	rm -rf $(dest)
	@echo "Successfully created new upstream source file: $(orig)"
