#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

export QT_SELECT=qt5

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

%:
	dh $@

DB2MAN = /usr/share/xml/docbook/stylesheet/docbook-xsl/manpages/docbook.xsl
XP     = xsltproc -''-nonet -''-param man.charmap.use.subset "0"

%.1: debian/%.man.xml
	$(XP) $(DB2MAN) $<

override_dh_auto_clean:
	rm -fr build
	rm -fr docs/build
	rm -f *.1

override_dh_auto_configure-arch:
	mkdir build ; cd build ; qmake -qt5 ../mandelbulber2/qmake/mandelbulber-opencl.pro

override_dh_auto_build-arch:
	cd build ; make $(MAKEJFLAG)
	cd build ; mkdir language ; cd language ; cp -l ../../mandelbulber2/language/* . ; lrelease *.ts

override_dh_auto_build-indep: mandelbulber2.1
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	cd docs ; ./build.sh
endif

override_dh_auto_install-arch:
	dh_install -pmandelbulber2 mandelbulber2/deploy/linux/mandelbulber2.desktop usr/share/applications
	dh_install -pmandelbulber2 build/mandelbulber2 usr/bin
	dh_install -pmandelbulber2 build/language/*.qm usr/share/mandelbulber2/language
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	ln -s ../mandelbulber2-data/handbook.pdf.gz debian/mandelbulber2/usr/share/doc/mandelbulber2
endif

override_dh_auto_install-indep:
	dh_install -pmandelbulber2-data mandelbulber2/deploy/share/mandelbulber2 usr/share
	dh_install -pmandelbulber2-data mandelbulber2/formula usr/share/mandelbulber2
	dh_install -pmandelbulber2-data mandelbulber2/opencl usr/share/mandelbulber2

override_dh_installchangelogs:
	dh_installchangelogs mandelbulber2/deploy/NEWS
