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

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


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
REPOSTARGET=root@debian.tagus.ist.utl.pt:/var/www/debian/debian/dists/$(MDIST)/$(DIST)/$(SECTION)/
REPOSARCH=~/debian/$(SECTION)/$(CATEG)/$(SOURCENAME)


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.

	touch configure-stamp


build: configure build-stamp
build-stamp:
	dh_testdir

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

	touch build-stamp

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) install DESTDIR=$(CURDIR)/debian/$(PACKAGE)


# 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
	dh_installcron
	dh_installcron --name=cal-scripts-postgres
#	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


# 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)


# Upload the packages and the distribution files into the rigth places
upload:	
	#mkdir -p $(REPOSARCH)
	cp ../*_$(DEBVER).* ../*_$(DEBVER)_* $(REPOSARCH)
	scp ../$(SOURCENAME)_$(VER)* ../*_$(DEBVER).* ../*_$(DEBVER)_* $(REPOSTARGET)


# Make tags of the sources as documented by subversion
tag:
	cd .. ; svn add $(SOURCENAME)_$(VER).orig.tar.gz $(SOURCENAME)_$(VER).tar.gz
	cd .. ; svn add $(SOURCENAME)_$(DEBVER)_*.changes ; svn add $(SOURCENAME)_$(DEBVER)_*.build ; svn add $(SOURCENAME)_$(DEBVER).dsc ; svn add $(SOURCENAME)_$(DEBVER).diff.gz
	cd .. ; svn add *_$(DEBVER)_*.deb
	cd .. ; svn st ; echo "enter to continue" ; read enter
	cd .. ; svn ci -m "released v$(DEBVER)"
	svn copy -m "released v$(DEBVER)" $(shell svn info | grep "Repository Root" | cut -d ' ' -f 3)/trunk/src/$(SOURCENAME) $(shell svn info | grep "Repository Root" | cut -d ' ' -f 3)/tags/src/$(SOURCENAME)/$(SOURCENAME)-$(DEBVER)
	debchange -i


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