#!/usr/bin/make -f
# -*- makefile -*-

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

%:
	dh $@

override_dh_install:
	cp -r "$(CURDIR)/commands" "$(CURDIR)/includes" "$(CURDIR)/drush.php" "$(CURDIR)/drush.info" "$(CURDIR)/debian/drush/usr/share/php/drush/"
	chmod a+x "$(CURDIR)/debian/drush/usr/share/php/drush/drush.php"
	ln -s /usr/share/php/drush/drush.php "$(CURDIR)/debian/drush/usr/bin/drush"
	cp "$(CURDIR)/drush.complete.sh" "$(CURDIR)/debian/drush/etc/bash_completion.d/drush"

override_dh_compress:
	dh_compress -XREADME.txt -Xexamples/ -Xdocs/

release: 
	git-buildpackage --release

snapshot: 
	git-buildpackage --snapshot

DOMAIN?=$(shell hostname -f)
KEY?="-kjenkins@$(DOMAIN)"

# this builds a debian package based on what the current branches are
# this usually tests the latest release
jenkins-build-official:
	git-buildpackage -b --git-upstream-branch=origin/upstream --git-debian-branch=origin/debian --git-ignore-branch ${KEY}

# the upstream version: strip the 6.x and turn the appendix into
# +N.foo where N is the number of commits since last tag and foo is
# the hash
upstream_version=$(shell git describe --tags origin/7.x-4.x | sed 's/6.x-//;s/-\([0-9]*\)-\([^-]*\)$$/+\1.\2/')
# the debian version, strip the debian/ part of the tag and the
# upstream version number, keep just the debian part, replacing as
# above for the N.foo part
debian_version=$(shell git describe --tags origin/debian | sed "s/debian\///;s/-\([0-9]*\)-\([^-]*\)$$/+\1.\2/;s/^.*-//" )

# this builds a debian package but first updates the branches to follow the latest 1.x branch
# this assumes you are on a "debian" branch (of course)
jenkins-build-auto:
	git merge origin/7.x-4.x
	dch -D unstable -v ${upstream_version}-${debian_version} "automatic jenkins build ${BUILD_TAG}"
	git commit -m"dummy commit for jenkins ${BUILD_TAG} autobuild" debian/changelog
	git-buildpackage -b --git-upstream-branch=origin/7.x-4.x ${KEY}

show-version:
	@echo ${upstream_version}-${debian_version}
