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

include /usr/share/python/python.mk

#export DH_VERBOSE=1
export DH_PYCENTRAL=nomove
CFLAGS = -Wall -g
PYVERS=$(shell pyversions -vr)

UPSTREAM_VERSION=`dpkg-parsechangelog | grep '^Version' | cut -d' ' -f2 | cut -d- -f 1`
ORIG_URI = lp:~aptoncd-team/aptoncd/main
REPOS_VERSION = $(shell echo $(UPSTREAM_VERSION) | sed -r "s/.*~bzr//")
REVISION=`bzr version-info $(ORIG_URI)| grep '^revno' | cut -d' ' -f 2`

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif

configure: configure-stamp
configure-stamp:
	dh_testdir
	touch configure-stamp


build: build-stamp
build-stamp: $(PYVERS:%=build-python%)
build-python%:
	dh_testdir
	python$* setup.py build

	touch $@

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

	rm -rf build
	find . -name ".svn" -exec rm -fr {} \;
	find . -name "*.pyc" -exec rm {} \;
	rm -rf po/mo

	dh_clean 

install: build
	dh_testdir
	dh_testroot
	dh_clean
	dh_installdirs
	cd $(CURDIR)/po; make update-po
	python ./setup.py install --prefix=$(CURDIR)/debian/aptoncd/usr $(py_setup_install_args)
	
binary-indep: build install
	dh_icons
	dh_testdir
	dh_testroot
	dh_install
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
	dh_pycentral
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-arch: build install

binary: binary-indep binary-arch

get-orig-source:
	bzr export --quiet --format tgz aptoncd_$(UPSTREAM_VERSION)+bzr$(REVISION).orig.tar.gz $(ORIG_URI)

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