#!/usr/bin/make -f

ifneq (,$(filter noopt,$(DEB_BUILD_OPTIONS)))
	QMAKECONFIG = -config noopt
	CXXFLAGS += -O0
else
	CXXFLAGS += -O2
endif

%:
	# specify both --with and --buildsystem so that the options filter through overridden calls to the helper
	dh $@ --with=kde --buildsystem=kde

QTBUILD=buildqt

override_dh_auto_clean:
	# Clean up the KDE build (cmake)
	dh_auto_clean
	# Clean up the Qt build (qmake)
	[ ! -f Makefile ] || make distclean
	rm -rf app/qtikz.desktop $(QTBUILD)

override_dh_auto_configure:
	# configure the KDE version (cmake)
	dh_auto_configure
	# configure the Qt version (qmake)
	mkdir $(QTBUILD)
	cd $(QTBUILD) && qmake-qt4 $(QMAKECONFIG) ../qtikz.pro

override_dh_auto_build:
	# build the KDE version (cmake)
	dh_auto_build
	# build the Qt version (qmake)
	make -C $(QTBUILD)

override_dh_auto_install:
	# install the KDE version (cmake)
	dh_auto_install
	# install the Qt version (qmake)
	INSTALL_ROOT=$(CURDIR)/debian/qtikz make -C $(QTBUILD) install
	./debian/icons/mkicons install
	rm $(CURDIR)/debian/qtikz/usr/share/qtikz/LICENSE.GPL2

# The following target is for the maintainer to rebuild the icons
build-icons:
	./debian/icons/mkicons convert

.PHONY: override_dh_auto_clean override_dh_auto_configure override_dh_auto_build override_dh_auto_install
