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

#This rule file have a bashism
SHELL:=/bin/bash

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

# "based" on template Makefile for most debian packages version 0.7
# Personall Variables
PACKNAME=$(shell dh_listpackages)
PACKAGE=$(shell dh_listpackages)

# Variabels used by the Debian Maintainer exclusively for package
# development.
SOURCENAME=$(shell dpkg-parsechangelog | grep "Source:" | cut -d ' ' -f 2)
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=wheezy
DIST=$(shell dpkg-parsechangelog | grep "Distribution" | cut -d ' ' -f 2)
SECTION=main
CATEG=my_sources
#CATEG=other_sources
DISTFILE=$(SOURCENAME)_$(VER).orig.tar.xz
#DISTFILES=$(DISTFILE) $(SOURCENAME)_$(DEBVER).diff.gz
DISTFILES=$(DISTFILE) $(SOURCENAME)_$(DEBVER).debian.tar.xz


build-arch: build-arch-up-stamp
build-arch-up-stamp:
	touch $@


build-indep: build-indep-up-stamp
build-indep-up-stamp:
	touch $@


build: build-stamp
build-stamp:
	dh_testdir

	# Add here commands to compile the package.
	$(MAKE)
	#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 


binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
	dh_installexamples --exclude=.svn
#	dh_install
#	dh_installmenu
#	dh_installdebconf	
	dh_installlogrotate
#	dh_installemacsen
#	dh_installpam
#	dh_installmime
#	dh_python
	dh_systemd_enable
	dh_installinit --no-start --update-rcd-params="start 37 S ."
	dh_systemd_start
#	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


binary-arch: build install


binary: binary-indep binary-arch


# 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: 
	make -f ../upload upload


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