#!/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:
#     $ H2_PARALLEL=4 dpkg-buildpackage -rfakeroot
# ...or uncomment the following line:
#H2_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 ("$(H2_PARALLEL)","")
	H2_PARALLEL_BUILDS=-j $(H2_PARALLEL)
else
	ifneq ("$(NUMJOBS)","")
		H2_PARALLEL_BUILDS=-j $(NUMJOBS)
	endif
endif

configure: 

build: build-stamp

build-stamp:
	dh_testdir

	mkdir -p $(CURDIR)/debian/hydrogen/usr/bin
	cd ..; scons $(H2_PARALLEL_BUILDS) --no-cache DESTDIR=$(CURDIR)/debian/hydrogen/ prefix=/usr/

	touch $@

clean:
	dh_testdir
	dh_testroot

	cd ..; scons -c

	dh_clean


install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	mkdir -p $(CURDIR)/debian/hydrogen/usr/bin
	cd ..; scons install
#	Clean out subversion's working copy folders (if accidentally copied
#	into the target).
	find $(CURDIR)/debian/hydrogen -type d -name '.svn' -print0 | xargs --null rm -rf

	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
