#!/usr/bin/make -f

include /usr/share/quilt/quilt.make

PYVERS=$(shell pyversions -vs)

config: config-stamp
config-stamp: 
	dh_testdir
	[ ! -d debian/patches ] || $(MAKE) -f /usr/share/quilt/quilt.make patch
	touch $@

build-arch: build
build-indep: build

build: $(PYVERS:%=build-python%)
	cd doc/ && make html
	find doc/_build/html -name "*.html" | while read F; do \
		echo Removing google-analytics from $$F; \
		cp "$$F" tmp.html; \
		printf "\n\n" >> tmp.html; \
		awk -f "$(CURDIR)/debian/remove_ga.awk" tmp.html > "$$F"; \
		rm tmp.html; \
		done

build-python%: config-stamp
	dh_testdir
	python$* setup.py build
	touch $@

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f config-stamp build-python?.* install-python?.*
	rm -f `find . -name "*.pyc"`
	rm -rf build doc/build doc/_build
	[ ! -d debian/patches ] || $(MAKE) -f /usr/share/quilt/quilt.make unpatch
	dh_clean

install: build $(PYVERS:%=install-python%)

install-python%:
	dh_testdir
	dh_testroot
	python$* setup.py install \
		--no-compile \
		--root=$(CURDIR)/debian/python-deap
	touch $@

binary-indep: install
	dh_testdir
	dh_testroot
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_install
	dh_installman
	rm -fv debian/python-deap-doc/usr/share/doc/python-deap/html/_static/jquery.js
	ln -s /usr/share/javascript/jquery/jquery.js \
		debian/python-deap-doc/usr/share/doc/python-deap/html/_static/jquery.js
	rm -fv debian/python-deap-doc/usr/share/doc/python-deap/html/_static/underscore.js
	ln -s /usr/share/javascript/underscore/underscore.js \
		debian/python-deap-doc/usr/share/doc/python-deap/html/_static/underscore.js
	dh_link
	dh_compress --exclude=.js --exclude=.pdf --exclude=.py --exclude=.yml
	dh_fixperms
	dh_python2
	[ ! -e /usr/bin/dh_buildinfo ] || dh_buildinfo
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-arch: build install

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