#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.
#
# Modified to make a template file for a multi-binary package with separated
# build-arch and build-indep targets  by Bill Allombert 2001

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

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

CFLAGS = -Wall -g

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

# To build testcases as well, add "testcases" to DEB_BUILD_OPTIONS
ifneq (,$(findstring testcases,$(DEB_BUILD_OPTIONS)))
	DH_OPTIONS=
else
	DH_OPTIONS=-Ndsme-testcases
endif

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.
	./autogen.sh

	touch configure-stamp

#Architecture
build: build-stamp

build-stamp: configure-stamp

# To build testcases as well, add "testcases" to DEB_BUILD_OPTIONS
ifneq (,$(findstring testcases,$(DEB_BUILD_OPTIONS)))
	$(MAKE) tests
else
	dh_auto_configure -- --disable-static
	dh_auto_build
endif

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.
	if [ -e Makefile ]; then $(MAKE) distclean; fi
	rm -rf Makefile.in aclocal.m4 compile config.guess config.sub \
		configure depcomp install-sh iphbd/Makefile.in ltmain.sh \
		missing modules/Makefile.in test/Makefile test/Makefile.in \
		util/Makefile.in m4

	dh_clean

install:
	dh_testdir
	dh_testroot
	dh_clean -k -s
	dh_installdirs

	# Add here commands to install the package into
	# debian/tmp.
	$(MAKE) install DESTDIR=$(CURDIR)/debian/tmp

	dh_install -s

# Must not depend on anything. This is to be called by
# binary-arch/binary-indep
# in another 'make' thread.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs -XREADME
	dh_installexamples
	dh_installman
	dh_link
	dh_strip --dbg-package=hbtest \
	         --dbg-package=libiphb0
	dh_compress
	dh_fixperms
	dh_makeshlibs --exclude=/usr/lib/dsme/
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb
# Build architecture independant packages using the common target.
binary-indep: build install

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