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

build3vers := $(shell py3versions -rv)

override_dh_auto_build: 
	set -e ; \
	for i in $(build3vers); do \
		python$$i ./setup.py build;\
	done
	
	mkdir -p build/docs/html/doctrees
	find postgresql/documentation/ -type f -exec cp {} build/docs/ \;
	cp postgresql/project.py build/docs/
	cp postgresql/documentation/sphinx/index.rst build/docs/index.txt
	sphinx-build -E -b html -d build/docs/html/doctrees build/docs build/docs/html

override_dh_auto_install:
	dh_install -ppython3-postgresql
	mkdir -p $(CURDIR)/debian/python3-postgresql/usr/share/python3-postgresql/
	set -e ; \
	for i in $(build3vers); do \
		python$$i ./setup.py install --root $(CURDIR)/debian/python3-postgresql; \
		rm -rf $(CURDIR)/debian/python3-postgresql/usr/local/lib/python$$i/dist-packages/postgresql/documentation; \
		mv $(CURDIR)/debian/python3-postgresql/usr/local/lib/python$$i/dist-packages/postgresql/lib/libsys.sql $(CURDIR)/debian/python3-postgresql/usr/share/python3-postgresql/; \
	done

override_dh_compress:
	dh_compress -X.js

override_dh_auto_clean:
	dh_clean
	rm -rf build
	rm -rf html

%:
	dh --with python3 $@
