#!/usr/bin/make -f

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

CPPFLAGS := $(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS := $(shell dpkg-buildflags --get CFLAGS)
CXXFLAGS := $(shell dpkg-buildflags --get CXXFLAGS)
LDFLAGS := $(shell DEB_LDFLAGS_MAINT_APPEND="-Wl,-z,defs -Wl,--as-needed" dpkg-buildflags --get LDFLAGS)
# SCons passes $LINKFLAGS to the compiler as a single argument
# so we build up a single -Wl argument
LINKFLAGS = -Wl$(shell for arg in $(subst -Wl,,$(LDFLAGS)); do echo -n $$arg; done)
export CPPFLAGS CFLAGS CXXFLAGS LINKFLAGS

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp:
	dh_testdir
	scons \
		prefix=/usr \
		resources_dir=/usr/share/jstest-gtk \
		lib_dir="$(CURDIR)"
	touch $@

clean: 
	dh_testdir
	dh_testroot
	rm -f build-stamp config-stamp
	-scons -c
	rm -f config.log options.cache
	rm -f rm .sconsign.dblite
	rm -rf .sconf_temp build
	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

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

# Build architecture-dependent files here.
binary-arch: install
	dh_testdir
	dh_testroot
	dh_installchangelogs NEWS
	dh_installdocs
	dh_installexamples
	dh_install
	cp data/generic.png debian/jstest-gtk/usr/share/pixmaps/jstest-gtk.png
	dh_installmenu
	dh_installman debian/jstest-gtk.1
	dh_link
	dh_strip --dbg-package=jstest-gtk-dbg
	dh_compress
	dh_fixperms
	[ ! -e /usr/bin/dh_buildinfo ] || dh_buildinfo
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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