#!/usr/bin/make -f

export DH_VERBOSE=1
export DEB_BUILD_MAINT_OPTIONS=hardening=+all
export QT_SELECT=qt5

# export information for the "About" screen
include /usr/share/dpkg/pkg-info.mk
include /usr/share/dpkg/vendor.mk
data=$(subst ., ,$(firstword $(subst +, ,$(lastword $(subst git, ,$(DEB_VERSION))))))
# ↑ i.e. "20170323 ec4712d"
sha1=$(lastword $(data))
build=$(DEB_VENDOR) build
timestamp=$(shell date +%Y-%m-%d -d "$(firstword $(data))")
export DEB_CXXFLAGS_MAINT_APPEND += -DGIT_EXISTS
export DEB_CXXFLAGS_MAINT_APPEND += -DGIT_CURRENT_SHA1=\"\\\"$(sha1) ($(build))\\\"\"
export DEB_CXXFLAGS_MAINT_APPEND += -DGIT_TIMESTAMP=\\\"$(timestamp)\\\"

%:
	dh $@

override_dh_clean:
	$(info building $(sha1) as $(build), timestamp $(timestamp))
	dh_clean

get-orig-source:
	dh_testdir
	git clone --depth=1 git@github.com:pencil2d/pencil.git pencil2d
	rm -rf pencil2d/3rdlib/zlib
	cd pencil2d && tar --exclude-vcs -cJf ../../pencil2d_0.5.4+git$$(git log -1 --format="%ci %h"|awk '{print $$1"."$$4}'|tr -d '-')+ds.orig.tar.xz .
	rm -rf pencil2d
