PYTHON=`which python3`
PYTHONCOVERAGE=`which python3-coverage`
DESTDIR=/
BUILDIR=$(CURDIR)/debian/pymanager
PROJECT=pymanager
VERSION=1.0.0
#OMIT_COVERGAGE=--omit=/usr/lib/python3/*,tests/*

all:
	@echo "make sdist - Create source package"
	@echo "make bdist - Create package"
	@echo "make bdist_wheel - Create package wheel"
	@echo "make test - Test"
	@echo "make coverage - coverage"
	@echo "make htmldoc - generate html doc (out : doc/build)"
	@echo "make install - Install on local system"
	@echo "make builddeb - Generate a deb package"
	@echo "make clean - Get rid of scratch and byte files"

sdist:
	$(PYTHON) setup.py sdist $(COMPILE)

bdist:
	$(PYTHON) setup.py bdist $(COMPILE)

bdist_wheel:
	$(PYTHON) setup.py bdist_wheel $(COMPILE)

test:
	$(PYTHON) setup.py test

coverage:
	$(PYTHONCOVERAGE) erase
	$(PYTHONCOVERAGE) run -a --concurrency=multiprocessing tests/test_client_manager.py
	$(PYTHONCOVERAGE) run -a tests/test_certificate.py
	$(PYTHONCOVERAGE) run -a tests/test_manager.py 
	$(PYTHONCOVERAGE) run -a tests/test_client.py
	$(PYTHONCOVERAGE) run -a tests/test_password.py
	$(PYTHONCOVERAGE) combine
	$(PYTHONCOVERAGE) report
	$(PYTHONCOVERAGE) html
	$(PYTHONCOVERAGE) xml

htmldoc:
	sphinx-build -b html docs/source docs/build

install:
	$(PYTHON) setup.py install --root $(DESTDIR) $(COMPILE)

builddeb:
	# build the source package in the parent directory
	# then rename it to project_version.orig.tar.gz
	$(PYTHON) setup.py sdist $(COMPILE) --dist-dir=../
	rename -v -f 's/$(PROJECT)-(.*)\.tar\.gz/$(PROJECT)_$$1\.orig\.tar\.gz/' ../*
	# build the package
	dpkg-buildpackage -i -I -rfakeroot

clean:
	$(PYTHON) setup.py clean
	$(MAKE) -f $(CURDIR)/debian/rules clean
	rm -rf build/ MANIFEST
	rm -rf docs/build/
	rm -rf dist/
	rm -rf .coverage
	rm -rf htmlcov
	rm -rf pymanager/__pycache__
	find . -name '*.pyc' -delete