#!/usr/bin/make -f

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
endif

ifeq (,$(NUMJOBS))
	NUMJOBS = 1
endif

BUILDDIR = builddir

CMAKEOPTS =	-DCMAKE_BUILD_TYPE=Release \
			-DWITH_WINETRIKS=ON \
			-USE_GZIP=ON \
			-DCMAKE_INSTALL_PREFIX=/usr \
			-DLIBS_ENTRY_PATH=/usr/lib/q4wine/ \
			..

config.status:
	dh_testdir
	mkdir -p $(BUILDDIR) && cd $(BUILDDIR) && cmake $(CMAKEOPTS)

build: build-stamp

build-stamp:  config.status
	dh_testdir
	cd $(BUILDDIR) && $(MAKE) -j$(NUMJOBS)
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	[ ! -f Makefile ] || ( cd $(BUILDDIR) && $(MAKE) clean )
	test ! -d $(BUILDDIR) || rm -r $(BUILDDIR)
	rm -f config.sub config.guess
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs
	cd $(BUILDDIR) && $(MAKE) install DESTDIR=$(CURDIR)/debian/q4wine

binary-indep: build install

binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
