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

CFLAGS       := $(shell dpkg-buildflags --get CFLAGS)
CXXFLAGS     := $(shell dpkg-buildflags --get CXXFLAGS)
CPPFLAGS     := $(shell dpkg-buildflags --get CPPFLAGS)
LDFLAGS      := $(shell dpkg-buildflags --get LDFLAGS)
# options needed for qmake (called by ./configure)
# (set _RELEASE and _DEBUG empty to avoid those overriding what we give,
#  pass CPPFLAGS and CFLAGS and CXXFLAGS,
#  pass CXXFLAGS and LDFLAGS in LFLAGS (it's LFLAGS, not LDFLAGS!)):
QMAKEOPTIONS := QMAKE_CXXFLAGS_RELEASE='' QMAKE_CXXFLAGS_DEBUG='' \
                QMAKE_CFLAGS_RELEASE='' QMAKE_CFLAGS_DEBUG='' \
                QMAKE_CFLAGS='-Wall $(CFLAGS) $(CPPFLAGS)' \
                QMAKE_CXXFLAGS='-Wall $(CFLAGS) $(CPPFLAGS)' \
                QMAKE_LFLAGS='$(CXXFLAGS) $(LDFLAGS)'

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	MAKEFLAGS += -j$(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
endif


configure-stamp: configure
	dh_testdir
	QTDIR=/usr/lib/qt4 ./configure $(QMAKEOPTIONS)
	touch $@

build build-arch: build-stamp
build-indep:

build-stamp:  configure-stamp
	dh_testdir
	$(MAKE)
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp
	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f Makefile usage_text.h
	dh_clean

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

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

# Build architecture-dependent files here.
binary-arch: install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	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 build-indep build-arch clean binary-indep binary-arch binary install
