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

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

DESTDIR=$(CURDIR)/debian/tmp
SAMPLESDIR=$(CURDIR)/debian/python-googleapi-samples/usr/share/doc/python-googleapi-samples/examples/

PYTHON2=$(shell pyversions -vr)
PYTHON3=$(shell py3versions -vr)

override_dh_clean:
	dh_clean
	rm -f $(CURDIR)/google_api_python_client.egg-info/SOURCES.txt
	rm -f $(CURDIR)/google_api_python_client.egg-info/top_level.txt

build-python%:
	python$* setup.py build

#override_dh_auto_build: $(PYTHON3:%=build-python%)
#	dh_auto_build

install-python%:
	python$* setup.py install --root=$(DESTDIR) --install-layout=deb
	sed -ri "1 s|(#!/usr/bin/python)[0-9.]+|\1|" \
		`find $(DESTDIR) -name '*.py'`
	sed -ri "1 s|(#!/usr/bin/python)[0-9.]+|\1|" \
		`find $(SAMPLESDIR) -name '*.py'`

#override_dh_auto_install: $(PYTHON3:%=install-python%)
#	dh_auto_install

override_dh_fixperms:
	dh_fixperms
	chmod a-x $(SAMPLESDIR)/storage_serviceaccount_appengine/listing.xsl

#override_dh_auto_test:
#	doesn't work at the moment
#	python setup.py test

%:
#       not compatible with Python 3.x ATM
#	dh $@ --with python2,python3
	dh $@ --with python2

.PHONY: override_dh_clean override_dh_fixperms
