#!/usr/bin/make -f

DPKG_EXPORT_BUILDFLAGS = 1
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

include /usr/share/dpkg/pkg-info.mk
include /usr/share/dpkg/buildflags.mk

UPSTREAM_VERSION := $(shell echo $(DEB_VERSION_UPSTREAM) | sed 's/+.*//')
LEVEL_DIR := /usr/share/games/rocksndiamonds

%:
	dh $@ --no-parallel

override_dh_auto_build:
	touch src/conf_*.h
	dh_auto_build -- BASE_PATH=$(LEVEL_DIR)

override_dh_auto_install:
	set -e; \
	for file in postinst preinst prerm; do \
		cp debian/$$file.in debian/$$file; \
		perl -pi -e 's/#VERSION#/$(UPSTREAM_VERSION)/g' \
			debian/$$file; \
	done
	mv rocksndiamonds rocksndiamonds-bin
	install -m 0755 debian/start_binary.sh rocksndiamonds

override_dh_auto_clean:
	make clean
	rm -fr src/confhash.h src/conftime.h rocksndiamonds-bin \
		debian/postinst debian/preinst debian/prerm
	debconf-updatepo
