#!/usr/bin/make -f

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

PY2VERS := $(shell pyversions -r -v)
PY3VERS := $(shell py3versions -r -v)
PYVERS := $(PY2VERS) $(PY3VERS)

%:
	dh $@ --with python2,python3,sphinxdoc

override_dh_auto_build:
	set -e; \
	for py in $(PYVERS); do  \
	    python$$py setup.py build; \
	done

	$(MAKE) -C doc html

override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
	# run tests
	-for py in $(PYVERS); do  \
	    for test in OpenSSL/test/test*; do \
	        echo "running $$test for python$$py ..."; \
		LIB=$$(python$$py -c "from distutils.command.build import build ; from distutils.core import Distribution ; b = build(Distribution()) ; b.finalize_options() ; print(b.build_purelib)") ; \
	        PYTHONPATH=$$LIB python$$py $$test; \
	    done; \
	done
endif
     

override_dh_auto_clean:
	-for py in $(PYVERS); do \
	    python$$py setup.py clean --all; \
	done

	rm -rf build

	$(MAKE) -C doc clean

	rm -rf *.key *.pem tmp*

	dh_clean build-stamp version.pyc

override_dh_auto_install: DH_OPTIONS=
override_dh_auto_install:
	set -e; \
	for py in $(PY2VERS); do \
	    echo "installing for python$$py ..."; \
 	    python$$py setup.py install --root=$(CURDIR)/debian/python-openssl --install-layout=deb; \
 	done
	set -e; \
	for py in $(PY3VERS); do \
	    echo "installing for python$$py ..."; \
 	    python$$py setup.py install --root=$(CURDIR)/debian/python3-openssl --install-layout=deb; \
 	done

override_dh_installchangelogs:
	dh_installchangelogs ChangeLog
