#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

# FOR AUTOCONF 2.52 AND NEWER ONLY
CONFFLAGS =
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
  CONFFLAGS += --build $(DEB_HOST_GNU_TYPE)
else
  CONFFLAGS += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
endif




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

configure:
	chmod +x debian/autogen.sh
	debian/autogen.sh

configure-stamp: configure
	dh_testdir

	ln -sf /usr/share/misc/config.sub .
	ln -sf /usr/share/misc/config.guess .
	rm -f config.cache

	./configure CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" \
		$(CONFFLAGS) \
	 	--config-cache \
		--disable-dependency-tracking \
		--prefix=/usr \
		--mandir=\$${prefix}/share/man \
		--infodir=\$${prefix}/share/info \
		--datadir=\$${prefix}/share \
		--libexecdir=\$${prefix}/lib \
		--sysconfdir=/etc \
		--enable-debug

	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir

	$(MAKE)
	#/usr/bin/docbook-to-man debian/dbus-scripts.sgml > dbus-scripts.1

	touch build-stamp

# Clean everything up, including everything auto-generated
# at build time that needs not to be kept around in the Debian diff
clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	-$(MAKE) clean
	-$(MAKE) distclean

	find -type d -name autom4te.cache -print0 | xargs -0 -r rm -rf \;
	-rm -f platform.h auto-include.h
	find -type d -name build -print0 | xargs -0 -r rm -rf \;
	find \( -name config.sub -o -name config.guess \) -print0 | xargs -0 -r rm -f \;

	# Fix permissions
	if [ -r debian/executable.files ] ; then \
		find -type d -print0 | xargs -0 -r chmod 755 ;\
		find -type f ! -name 'rules' -print0 | xargs -0 -r chmod 644 ;\
		xargs -t -r chmod +x < debian/executable.files ;\
	fi

	# Final static cleanups
	if [ -r debian/deletable.files ] ; then \
		xargs -t -r rm -f < debian/deletable.files ;\
	fi

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	# Add here commands to install the package into debian/dbus-scripts.
	$(MAKE) install DESTDIR=$(CURDIR)/debian/dbus-scripts
	mkdir -p $(CURDIR)/debian/dbus-scripts/etc/dbus-scripts.d
	cp dbus-scripts-example $(CURDIR)/debian/dbus-scripts/etc/dbus-scripts.d/


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

# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
#	dh_installexamples
	dh_install
#	dh_installmenu
#	dh_installdebconf	
#	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
	dh_installinit -- start 99 2 3 4 . stop 20 0 1 5 6 .
#	dh_installcron
#	dh_installinfo
#	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_python
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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