#!/usr/bin/make -f

# Debian 'rules' file for the Hydrogen Drum Machine.
#
# To make the build more verbose, uncomment the following line:
#export DH_VERBOSE=1
#
# To enable scons PARALLEL BUILDS (e.g. -j 4), run like this:
#     $ COMPOSITE_PARALLEL=4 dpkg-buildpackage -rfakeroot
# ...or uncomment the following line:
#COMPOSITE_PARALLEL=4
# ...or invoke dpkg-buildpackage like this:
#     $ dpkg-buildpackage -j4 -rfakeroot
# However, the -j4 here will run more than gcc in parallel.

# Check for parallel builds.
# NUMJOBS script goodie courtesy of http://lists.debian.org/debian-policy/2007/08/msg00005.html
, := ,
NUMJOBS=$(patsubst parallel=%,%,$(filter parallel=%,$(subst $(,), ,$(DEB_BUILD_OPTIONS))))
ifneq ("$(COMPOSITE_PARALLEL)","")
	COMPOSITE_PARALLEL_BUILDS=-j $(COMPOSITE_PARALLEL)
else
	ifneq ("$(NUMJOBS)","")
		COMPOSITE_PARALLEL_BUILDS=-j $(NUMJOBS)
	endif
endif

BUILDDIR=$(CURDIR)/build
DESTDIR=$(CURDIR)/debian/composite

configure: configure-stamp

configure-stamp:
	if [ ! -d $(BUILDDIR) ] ; then mkdir $(BUILDDIR) ; fi
	cd $(BUILDDIR) ; \
		cmake \
		-DCMAKE_INSTALL_PREFIX=/usr/ \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DWANT_LRDF=ON \
		../..
	touch $@

build: build-stamp

build-stamp: configure-stamp
	dh_testdir
	cd $(BUILDDIR) && make $(COMPOSITE_PARALLEL_BUILDS)
	touch $@

clean:
	dh_testdir
	dh_testroot

	rm -rf $(BUILDDIR) $(DESTDIR) build-stamp configure-stamp

	dh_clean


install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	mkdir -p $(DESTDIR)/usr/bin
	cd $(BUILDDIR) && make install DESTDIR=$(DESTDIR)

	touch $@

docs:

docs_install:

# Build architecture-independent files here.
binary-indep: build install docs docs_install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installman
	dh_link
#	dh_strip
	dh_compress
	dh_compress -X.py
	dh_fixperms
#	dh_python
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb




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