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

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

# Extract the current version number and package name
DEBIAN  := $(shell dpkg-parsechangelog | grep ^Version: | cut -d' ' -f2)
DEBVERS := $(shell echo '$(DEBIAN)' | cut -d- -f1)
VERSION := $(shell echo '$(DEBVERS)' | sed -e 's/[+-].*//' -e 's/~//g')
name := $(shell dpkg-parsechangelog | sed -n 's/^Source: //p')

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

QMAKE_GENERIC := \
		LIBS+=-lz \
		VERSION=$(VERSION) \
		LIB_ARCH="$(DEB_HOST_MULTIARCH)"

QMAKE_STATIC := CONFIG+=staticlib -o Makefile.Static

%:
	dh $@ --buildsystem=qmake_qt4 --parallel --dbg-package=libquazip0-dbg

override_dh_auto_configure:
	dh_auto_configure -- $(QMAKE_GENERIC) $(extra_configure_opts)
	dh_auto_configure -- $(QMAKE_GENERIC) $(QMAKE_STATIC) $(extra_configure_opts)
	cp NEWS.txt NEWS

override_dh_auto_clean:
	rm -Rf quazip/.obj
	rm -Rf quazip/.moc
	rm -Rf quazip/libquazip.so.*
	rm -Rf quazip/libquazip.so
	rm -Rf quazip/libquazip.a
	find . -name Makefile -delete
	rm -Rf NEWS
	rm -Rf Makefile.Static quazip/Makefile.Static
	dh_auto_clean

override_dh_auto_build:
	# Build the static lib
	dh_auto_build -Smakefile -- -f Makefile.Static
	rm -Rf quazip/.obj
	rm -Rf quazip/.moc
	# Build the dynamic lib
	dh_auto_build -Smakefile

override_dh_auto_install:
	dh_auto_install -Smakefile -- INSTALL_ROOT=$(CURDIR)/debian/tmp
	cp -a quazip/libquazip.a $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)

override_dh_installchangelogs:
	dh_installchangelogs -plibquazip0 NEWS upstream
	dh_installchangelogs -plibquazip0-dev NEWS upstream
	dh_installchangelogs -plibquazip0-dbg NEWS upstream
	#dh_installchangelogs -plibquazip0-headers NEWS upstream
	dh_installchangelogs
