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

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

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

%:
	dh $@ --parallel --with python2

override_dh_auto_configure:
	rm -f build.conf
	cp build.conf.example build.conf
	mkdir -p icons/48x48
	mkdir -p icons/128x128
	cp qtiplot_logo.png icons/128x128/qtiplot.png
	convert qtiplot_logo.png -resize 48x48 icons/48x48/qtiplot.png
	dh_auto_configure

override_dh_auto_install:

override_dh_python2:
	dh_python2
	dh_sip -pqtiplot

override_dh_auto_build-arch:
	$(MAKE)

override_dh_auto_build-indep:
	doxygen Doxyfile
	$(MAKE) -C manual -f Makefile all

overrid_dh_auto_clean:
	dh_auto_clean
	find -type f -name Makefile ! -path ./manual/Makefile -exec rm -f {} \;
	find -type f -name '*.qm' -exec rm -f {} \;
	rm -rf icons
	rm -f minigzip.c
	rm -f qtiplot/qtiplot
	rm -f manual/html/*.html
	rm -f manual/qtiplot-manual-en.pdf
	rm -f manual/html/qtiplot.adp
	rm -rf API
	rm -rf tmp
	rm -f qtiplot/translations/*.qm
	rm -rf 3rdparty/qwtplot3d/lib
	rm -rf 3rdparty/qwtplot3d/tmp
	rm -f build.conf
	rm -f 3rdparty/qwt/lib/libqwt.a

override_dh_install:
	dh_install -X.js

override_dh_compress:
	dh_compress --exclude=.pdf --exclude=.adp

get-orig-source:
	VER=$(shell dpkg-parsechangelog | sed -rne 's,^Version: ([^-+~]+).*,\1,p'); \
	uscan --force-download --rename --download-version=$$VER --destdir=. && (\
	tar -xj --exclude 3rdparty/liborigin --exclude manual/html/qtiplot.adp --exclude .gitignore -f qtiplot_$$VER.orig.tar.bz2 ; \
	chmod -R o-w qtiplot-$$VER ; \
	fromdos `find qtiplot-$$VER -type f |grep -v .png`; \
	find qtiplot-$$VER -type f -exec chmod a-x {} \; ;\
	rm -f qtiplot-$$VER/.gitignore ;\
	tar -czf qtiplot_$$VER.orig.tar.gz qtiplot-$$VER; \
	rm -rf qtiplot-$$VER; \
	rm -f qtiplot_$$VER.orig.tar.bz2);
