#!/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
	rm -f build/*/postgresql/resolved/crypt.py # avoid shipping crypt.py since we rely on libpython3-stdlib instead

	(cd postgresql/documentation/sphinx && ./build.sh)
	mkdir -p build/docs/html/doctrees
	cp -r postgresql/documentation/html build/docs/
	rm -f build/docs/html/_static/jquery.js build/docs/html/_static/underscore.js
	rm -f build/docs/html/.gitignore

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
