#!/usr/bin/make -f

# Keep this list of folders that are not included in the
# orig syncronized with the one in debian/source/local-options!
ORIG_CONTENT := $(shell git ls-tree --name-only HEAD | grep -Ev '^(Android|Editor|iOS|OSX|PSP|Windows|debian|\.git.*)')
VERSION := $(shell dpkg-parsechangelog | grep -x "Version:.*" | sed 's@Version: \(.\+\)-.\+@\1@')
MAKE = make --directory=Engine
GENCONTROL_SUBSTVARS = -Vbuildinfo:Date="$(shell date -R)" -Vbuildinfo:Git-Object="$(shell git show HEAD | head -n1)"

ifneq (,$(filter rpath=%,$(DEB_BUILD_OPTIONS)))
  RPATH = $(patsubst rpath=%,%,$(filter rpath=%,$(DEB_BUILD_OPTIONS)))
  export RPATH
endif

%:
	dh $@ --parallel

override_dh_auto_clean:
	$(MAKE) clean

override_dh_auto_build:
	$(MAKE)

override_dh_auto_install:
	$(MAKE) install PREFIX=$(CURDIR)/debian/tmp/usr

override_dh_clean:
	dh_clean --exclude=Editor/*

get-orig-source:
	git archive --prefix=ags_$(VERSION)/ --format=tar HEAD $(ORIG_CONTENT) | gzip > ../ags_$(VERSION).orig.tar.gz

override_dh_gencontrol:
	dh_gencontrol -- $(GENCONTROL_SUBSTVARS)

.PHONY: override_dh_strip
override_dh_strip:
	dh_strip --dbg-package=ags-dbg
