#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

#  "based" on template debian/rules for most debian packages version 0.24

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

#For overriding debian/compat
#export DH_COMPAT=7

PACKAGE=$(shell dh_listpackages)

# Variabels used by the Debian Maintainer exclusively for package
# development.
DEBVER=$(shell dpkg-parsechangelog | grep "Version:" | cut -d ' ' -f 2)
VER=$(shell dpkg-parsechangelog | grep "Version:" | cut -d ' ' -f 2 | cut -f 1 -d -)
MDIST=lenny
DIST=$(shell dpkg-parsechangelog | grep "Distribution" | cut -d ' ' -f 2)
SECTION=non-free
CATEG=my_sources
#CATEG=other_sources



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.
	$(MAKE) configure
	touch $@


build-arch: build-arch-stamp
build-arch-stamp: configure-stamp
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE) build-arch
	#docbook-to-man debian/$(PACKAGE).sgml > $(PACKAGE).1

	touch $@


build-indep: build-indep-stamp
build-indep-stamp: configure-stamp
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE) build-indep
	#docbook-to-man debian/$(PACKAGE).sgml > $(PACKAGE).1

	touch $@


build: build-stamp
build-stamp: configure-stamp
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE) build
	#docbook-to-man debian/$(PACKAGE).sgml > $(PACKAGE).1

	touch $@

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

	# Add here commands to clean up after the build process.
	$(MAKE) clean

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	#dh_clean -k 
	dh_prep
	dh_installdirs

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


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

# Build architecture-dependent files here.
#binary-arch: build-arch install
binary-indep: build-indep 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_python
#	dh_installinit
#	dh_installcron
#	dh_installinfo
	dh_installman
	dh_lintian
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_perl
#	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb


# Check variabels used by the Debian Maintainer exclusively for
# package development.
vars:
	echo $(VER) $(DEBVER) $(MDIST) $(DIST) $(PACKNAME) $(SOURCENAME)
	echo $(REPOSTARGET)
	echo $(REPOSARCH)
	echo $(DEB_HOST_GNU_TYPE) $(DEB_BUILD_GNU_TYPE)


# Make tags of the sources as documented by subversion
tag:
	cd .. ; svn add $(DISTFILES) ;\
		echo $(PWD)
	cd .. ; svn add $(SOURCENAME)_$(DEBVER)_*.changes \
			$(SOURCENAME)_$(DEBVER)_*.build \
			$(SOURCENAME)_$(DEBVER).dsc
	cd .. ; svn add *_$(DEBVER)_*.deb
	cd .. ; svn st ; echo "enter to continue" ; read enter
	cd .. ; shopt -s nullglob ; svn ci -m "released v$(DEBVER)" \
		$(DISTFILES) \
		$(SOURCENAME)_$(DEBVER)_*.changes \
		$(SOURCENAME)_$(DEBVER)_*.build \
		$(SOURCENAME)_$(DEBVER).dsc \
		*_$(DEBVER)_*.deb
	svn mkdir --parents -m "Preparing tag directory for release v$(DEBVER)" $(shell svn info | grep "Repository Root" | cut -d ' ' -f 3)/tags/src/$(SOURCENAME)/$(SOURCENAME)-$(DEBVER)
	cd .. ; shopt -s nullglob ; svn copy -m "released v$(DEBVER)" \
		$(DISTFILES) \
		$(SOURCENAME)_$(DEBVER)_*.changes \
		$(SOURCENAME)_$(DEBVER)_*.build \
		$(SOURCENAME)_$(DEBVER).dsc \
		*_$(DEBVER)_*.deb \
		$(shell svn info | grep "Repository Root" | cut -d ' ' -f 3)/tags/src/$(SOURCENAME)/$(SOURCENAME)-$(DEBVER)
	debchange -i "New release"


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