#!/usr/bin/make -f

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

# This is the debhelper compatability version to use.
export DH_COMPAT=1

# This has to be exported to make some magic below work.
export DH_OPTIONS

#PKG_VER = $(shell perl -e 'print <> =~ /\((.*)\)/' debian/changelog)

DEB_HOST_ARCH = $(shell dpkg-architecture -qDEB_HOST_ARCH)

build: build-stamp
build-stamp:
	dh_testdir
	rm -f config.cache
	rm -f debian/files
	./configure \
	  --with-db-lib=/usr/lib/ \
	  --with-db-libname=db3 \
	  --with-db-include=/usr/include \
	  --with-expat-lib=/usr/lib/ \
	  --with-expat-include=/usr/include
	$(MAKE)
	touch build-stamp

clean:
	dh_testdir
	rm -f build-stamp
	-$(MAKE) -i clean
	dh_clean

install: DH_OPTIONS=
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	# Add here commands to install the package into debian/tmp.
	install -o root -g root -m 755 cpp/grapevine debian/tmp/usr/bin/
	strip debian/tmp/usr/bin/grapevine
	install -o root -g root grapevine-config.xml debian/tmp/usr/share/grapevine/grapevine-config.xml.template
	install -o root -g root debian/init debian/tmp/etc/init.d/grapevine
	cp raisen/sys/*.xml debian/tmp/usr/share/grapevine/sys/
	cp raisen/obj.xml debian/tmp/usr/share/grapevine/
	dh_movefiles

# Build architecture-independent files here.
binary-indep: build install
	# nothing to do

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installdebconf
	dh_installdocs README COPYING WARNING README.Debian
	dh_strip
	dh_link
	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
