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

# This has to be exported to make some magic below work.
export DH_OPTIONS

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

%:
	dh $@

override_dh_auto_configure:
	cd $(PREREX) && ./configure --prefix=/usr
	cd $(VPREREX) && qmake .

override_dh_auto_build:
	cd $(PREREX) && $(MAKE)
	cd $(VPREREX) && $(MAKE)

override_dh_auto_install:
	cd $(PREREX) && $(MAKE) install 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_auto_clean:
	# It may be that we've already cleaned, in which case the Makefiles
	# won't exist. Ignore errors.
	- cd $(PREREX) && $(MAKE) clean
	- cd $(VPREREX) && $(MAKE) clean
	# Files that clean misses
	rm -fr prerex-6.2/Makefile \
	    prerex-6.2/config.h \
	    prerex-6.2/config.log \
	    prerex-6.2/config.status \
	    prerex-6.2/src/.deps/ \
	    prerex-6.2/src/Makefile \
	    prerex-6.2/stamp-h1 \
	    vprerex-6.2/Makefile \
	    vprerex-6.2/vprerex
	dh_auto_clean
