#!/usr/bin/make -f
# Based on the sample rules file written by Joey Hess.

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

CFLAGS = -Wall -g

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

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


build: build-stamp
build-stamp:
	dh_testdir
	# Set HOME to an existent directory as a workaround for #544835. Note that
	# HOME isn't actually used, but some buildds set it to a non-existent
	# directory, and PhysicsFS currently fails if the directory doesn't exist
	# (see #553174).
	$(MAKE) $(MAKEFLAGS) \
		DATADIR=/usr/share/games/neverball \
		LOCALEDIR=/usr/share/locale \
	        HOME=$(CURDIR)
	# Rename icons for .desktop files.
	cp dist/neverball_128.png dist/neverball.png
	cp dist/neverputt_128.png dist/neverputt.png
	touch $@

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	[ ! -f Makefile ] || $(MAKE) clean
	rm -f dist/neverball.png dist/neverputt.png
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	dh_install

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir -i
	dh_testroot -i
	dh_installchangelogs -i CHANGES
	dh_installdocs -i
	dh_link -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir -a
	dh_testroot -a
	dh_installchangelogs -a CHANGES
#	dh_installman -a
#	dh_installmenu -a
	dh_strip -a --dbg-package=neverball-dbg
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_shlibdeps -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

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