#!/usr/bin/make -f

# Path to the debian directory
DEBIAN_DIR := $(shell echo ${MAKEFILE_LIST} | awk '{print $$1}' | xargs dirname )
UPSTREAM_VERSION ?=$(shell uscan --dehs | sed -n 's/.*<upstream-version>\(.*\)<\/upstream-version>.*/\1/p')
DFSG = dfsg1
PKG = $(shell dpkg-parsechangelog | sed -ne 's/^Source: //p')
DATE := $(shell date -u -d "$$(dpkg-parsechangelog -SDate)" +"%Y/%m/%d")

CPPFLAGS+=-DBUILD_DATE='"$(DATE)"'
CXXFLAGS+=-std=c++11
LDFLAGS+=-Wl,--as-needed

%:
	dh $@ --parallel --with autoreconf,autotools-dev

override_dh_autoreconf:
	./autogen.sh
	dh_autoreconf

override_dh_auto_configure:
	dh_auto_configure -- --target=linux

override_dh_auto_test:
	@echo home: $(HOME)
	HOME=/tmp dh_auto_test -a || (grep . test-suite.log giada_test.log; false)
	#make check      || (grep . test-suite.log giada_test.log; false)

get-orig-source:
	uscan --noconf --force-download --rename --download-current-version --destdir=.
	tar -xf $(PKG)_$(UPSTREAM_VERSION).orig.tar.gz
	mv $(PKG)-$(UPSTREAM_VERSION) $(PKG)-$(UPSTREAM_VERSION)~$(DFSG)
	rm -rf $(PKG)-$(UPSTREAM_VERSION)~$(DFSG)/src/rtaudio-mod/include
	rm -rf $(PKG)-$(UPSTREAM_VERSION)~$(DFSG)/src/vst
	rm -rf $(PKG)-$(UPSTREAM_VERSION)~$(DFSG)/src/*.dll
	rm -rf $(PKG)-$(UPSTREAM_VERSION)~$(DFSG)/.gitignore
	XZ_OPT=-9 tar cJf ../$(PKG)_$(UPSTREAM_VERSION)~$(DFSG).orig.tar.xz $(PKG)-$(UPSTREAM_VERSION)~$(DFSG)
	rm -rf $(PKG)-$(UPSTREAM_VERSION)~$(DFSG)
	rm -rf $(PKG)_$(UPSTREAM_VERSION).orig.tar.gz

