#!/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 head -1 debian/changelog | sed 's/.*(\(.*\)).*/\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 --buildsystem makefile

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:
	mkdir -p ../orig_temp/ags_$(VERSION)
	debian/git-archive-all.sh ../orig_temp/ags_$(VERSION)/orig_temp.tar
	cd ../orig_temp/ags_$(VERSION) && tar -xf orig_temp.tar $(ORIG_CONTENT)
	rm ../orig_temp/ags_$(VERSION)/orig_temp.tar
	cd ../orig_temp && tar -pczf ../ags_$(VERSION).orig.tar.gz ags_$(VERSION)
	rm -rf ../orig_temp

override_dh_gencontrol:
	dh_gencontrol -- $(GENCONTROL_SUBSTVARS)

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