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

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

DEB_HOST_ARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEBVERSION = $(shell head -n 1 debian/changelog | sed -e 's/^[^(]*(\([^)]*\)).*/\1/')
UPVERSION = $(shell echo $(DEBVERSION) | sed -r -e 's/^.*://' -e 's/-[0-9.]*(\+b[0-9])?$$//' -e 's/~agaida.[0-9]*$$//')

%:
	dh $@ --with quilt

override_dh_quilt_patch:
	dh_quilt_patch
	bash build

override_dh_quilt_unpatch:
	quilt pop -af || return 0

override_dh_install:
	# make needed files and directories
	mkdir -p logs
	touch logs/log.txt
	mkdir -p userfiles
	dh_install
	mkdir -p debian/cmsimplexh/usr/share/cmsimplexh/config
	mv -f debian/cmsimplexh/usr/share/cmsimplexh/cmsimple/languages/defaultconfig.php debian/cmsimplexh/usr/share/cmsimplexh/config/defaultlangconfig.php
	mv -f debian/cmsimplexh/usr/share/cmsimplexh/cmsimple/languages/deconfig.php      debian/cmsimplexh/usr/share/cmsimplexh/config
	mv -f debian/cmsimplexh/usr/share/cmsimplexh/cmsimple/languages/enconfig.php      debian/cmsimplexh/usr/share/cmsimplexh/config
	mv -f debian/cmsimplexh/usr/share/cmsimplexh/cmsimple/config.php                  debian/cmsimplexh/usr/share/cmsimplexh/config
	mv -f debian/cmsimplexh/usr/share/cmsimplexh/cmsimple/defaultconfig.php           debian/cmsimplexh/usr/share/cmsimplexh/config

get-orig-source: maintainer-clean
	if [ ! -d .xyz ]; then \
	    git clone git://github.com/agaida/cmsimplexh.git .xyz; \
	    cd .xyz; \
	    git fetch --all; \
	    git reset --hard $(UPVERSION); \
	else \
	    cd .xyz; \
	    git pull --all; \
	    git reset --hard $(UPVERSION); \
	fi; \
	cp -a * ..; \

maintainer-clean: 
	dh_clean
	rm -rf $$(ls | grep -v debian)
	rm -rf .pc

versions:
	echo "Package-Version: $(DEBVERSION)"
	echo "Upstream-Version: $(UPVERSION)"



