#!/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
	rm $(CURDIR)/debian/qtikz/usr/share/qtikz/LICENSE.GPL2
	# Make icons for Debian menu
	convert -background none -geometry 32x32 ./app/icons/ktikz.svg \
	  $(CURDIR)/debian/ktikz/usr/share/pixmaps/ktikz32.xpm
	convert -background none -geometry 16x16 ./app/icons/ktikz.svg \
	  $(CURDIR)/debian/ktikz/usr/share/pixmaps/ktikz16.xpm
	convert -background none -geometry 32x32 ./app/icons/qtikz.svg \
	  $(CURDIR)/debian/qtikz/usr/share/pixmaps/qtikz32.xpm
	convert -background none -geometry 16x16 ./app/icons/qtikz.svg \
	  $(CURDIR)/debian/qtikz/usr/share/pixmaps/qtikz16.xpm

.PHONY: override_dh_auto_clean override_dh_auto_configure override_dh_auto_build override_dh_auto_install
