#!/usr/bin/make -f

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	SCONSOPTS += -j$(NUMJOBS)
endif

export PYVERS=$(shell pyversions -vr)

%:
		dh $@ --with python2

override_dh_auto_configure:	$(PYVERS:%=debian/stamps/configure-python%)
debian/stamps/configure-python%:
	mkdir build-python$*
	cp -r build engine ext utils SConstruct setup.py test_fife.py build-python$*
	find build-python$*/engine/core/ext/tinyxml -type f -a \! -name fife_tinyxml.h -delete
	touch $@

override_dh_auto_build:	$(PYVERS:%=debian/stamps/build-python%)
debian/stamps/build-python%:
	python$* $(shell which scons) -C build-python$* fife-python $(SCONSOPTS)

override_dh_auto_test:	$(PYVERS:%=debian/stamps/test-python%)
debian/stamps/test-python%:
	python$* $(shell which scons) -C build-python$* tests $(SCONSOPTS)


override_dh_auto_install:	$(PYVERS:%=debian/stamps/install-python%)
debian/stamps/install-python%:
	python$* $(shell which scons) -C build-python$* DESTDIR=$(CURDIR)/debian/python-fife install-python $(SCONSOPTS)
	find $(CURDIR)/debian/python-fife -name '*.so' -exec chrpath -d {} \;

override_dh_auto_clean:
	rm -fr build-python*
	rm -f debian/stamps/*
	dh_clean

# override_dh_builddeb:
# 	dh_builddeb -- -Zxz
