#!/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

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

# The rationale for /sbin and /lib/dsme: DSME needs to be available on bootup before networking starts.
# Also see http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/sbin.html and
# http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/lib.html
	dh_auto_configure -- --disable-static --exec-prefix=""
	dh_auto_build
	dh_auto_test

	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 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
	#mkdir $(CURDIR)/debian/tmp/etc/dsme
	install -m 440  dsme/dsme.conf      $(CURDIR)/debian/tmp/etc/dbus-1/system.d/

	# install tests (if needed)
ifneq (,$(findstring testcases,$(DEB_BUILD_OPTIONS)))
	$(MAKE) tests_install DESTDIR=$(CURDIR)/debian/tmp
endif

	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=dsme
	dh_compress
	dh_fixperms
	dh_makeshlibs --exclude=/lib/dsme/
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb
	aegis-deb-add -control debian/dsme/DEBIAN/control .. debian/dsme.aegis=_aegis
# Build architecture independant packages using the common target.
binary-indep: build install
#	$(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
#binary-arch: build install
#	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

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