#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

VPREREX=$(shell find . -maxdepth 1 -type d -name 'vprerex*')
PREREX=$(shell find . -maxdepth 1 -type d -name 'prerex*')

%:
	dh $@ --with autoreconf

override_dh_autoreconf:
	echo "$(PREREX)" > debian/autoreconf
	dh_autoreconf

override_dh_auto_configure:
	dh_auto_configure -D$(PREREX)
	dh_auto_configure -D$(VPREREX) -Sqmake_qt4

override_dh_auto_build:
	dh_auto_build -D$(PREREX)
	dh_auto_build -D$(VPREREX)

override_dh_auto_install:
	dh_auto_install -D$(PREREX) -- DESTDIR=$(CURDIR)/debian/prerex/
	# No install target for vprerex
	install -m 755 $(CURDIR)/$(VPREREX)/vprerex \
	    $(CURDIR)/debian/vprerex/usr/bin
	dh_auto_install

override_dh_installchangelogs:
	dh_installchangelogs -pprerex $(PREREX)/ChangeLog
	dh_installchangelogs -pvprerex $(VPREREX)/ChangeLog

override_dh_autoreconf_clean:
	dh_autoreconf_clean
	rm -f debian/autoreconf

override_dh_auto_clean:
	# Files that clean misses
	rm -fr $(PREREX)/.deps/
	dh_auto_clean -D$(PREREX)
	# This might fail because Makefile might not yet exist. Ignore errors:
	- dh_auto_clean -D$(VPREREX)
	dh_auto_clean
