#!/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

VARS=$(shell dpkg-buildflags --export=configure | sed -e 's/LDFLAGS="/LFLAGS="'"`dpkg-buildflags --get CPPFLAGS` `dpkg-buildflags --get CXXFLAGS`"' /g;s/\(CFLAGS="\)/\1'"`dpkg-buildflags --get CPPFLAGS` /;"'s/\(CXXFLAGS="\)/\1'"`dpkg-buildflags --get CPPFLAGS` /")

Makefile: main.pro
	dh_testdir
	# The real configuration
	dh_auto_configure --buildsystem=qmake_qt4 -- VERSION_NUMBER=`./VERSION` main.pro

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp: Makefile
	dh_testdir
	dh_auto_build --buildsystem=qmake_qt4
	# Force rebuild with proper build flags
	rm evolvotron/evolvotron
	cd evolvotron; $(MAKE) -j1 $(VARS)
	rm evolvotron_render/evolvotron_render
	cd evolvotron_render; $(MAKE) -j1 $(VARS)
	rm evolvotron_mutate/evolvotron_mutate
	cd evolvotron_mutate; $(MAKE) -j1 $(VARS)
	touch $@

clean:
	dh_testdir
	dh_testroot
	dh_auto_clean
	rm -rf libevolvotron/moc
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	$(MAKE) prefix=$(CURDIR)/debian/evolvotron/usr install
	cp $(shell find evolvotron* -perm /u+x -type f) $(CURDIR)/debian/evolvotron/usr/bin
	cp debian/evolvotron.desktop debian/evolvotron/usr/share/applications/

# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs NEWS
	dh_installdocs
	dh_installmenu
	dh_installman
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
