#!/usr/bin/make -f
# Based on the initial work of Joey Hess and Craig Small.

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

DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)


PACKAGE=cb2bib

BUILDDIR=$(CURDIR)/debian/build


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

$(info "---------------------------------------")
$(info NUMJOBS: $(NUMJOBS))
$(info MAKEFLAGS: $(MAKEFLAGS))
$(info DEB_BUILD_OPTIONS: $(DEB_BUILD_OPTIONS))
$(info "---------------------------------------")


.PHONY: clean
clean: 
	dh_testdir
	dh_testroot

	dh_clean

	rm -rf $(BUILDDIR)
	rm -f debian/cb2bib.xpm


configure-stamp: 
	dh_testdir

	mkdir -p $(BUILDDIR)
	cp -rpf cb2bib.pro cb2bib.rc configure src $(BUILDDIR)
	cd $(BUILDDIR) && ./configure --qmakepath /usr/bin/qmake-qt4	\
	--prefix /usr --bindir /usr/bin --datadir /usr/share		\
	--desktopdatadir /usr/share/applications --icondir		\
	/usr/share/pixmaps --disable-lzo

	touch configure-stamp


build-arch-stamp: configure-stamp 
	dh_testdir
	dh_prep -a

	$(MAKE) -C $(BUILDDIR)
	convert src/icons/cb2bib.png -resize 32x32 debian/cb2bib.xpm

	touch build-arch-stamp


.PHONY: build-indep
build-indep:


.PHONY: build-arch
build-arch: build-arch-stamp


.PHONY: build
build: build-indep build-arch


# Build architecture-independent files here.
.PHONY: binary-indep
binary-indep: 


# Build architecture-dependent files here.
.PHONY: binary-arch
binary-arch: build-arch-stamp
	dh_testdir -a
	dh_testroot -a
	dh_installchangelogs -a
	dh_installdocs -a
	dh_installexamples -a
	dh_install -a
	dh_installmenu -a cb2bib.menu
	dh_installman -a
	dh_link -a usr/share/man/man1/cb2bib.1 usr/share/man/man1/c2bimport.1
	dh_link -a usr/share/man/man1/cb2bib.1 usr/share/man/man1/c2bciter.1
	dh_strip -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a


.PHONY: binary
binary: binary-indep binary-arch



