.PHONY: help
help:
	@echo	"MAKE TARGETS"
	@echo	"clean        -- remove generated files"
	@echo	"ext          -- build C extensions"
	@echo 	"docs         -- build Sphinx docs"
	@echo 	"help         -- this text"
	@echo   "htmlcov      -- make html coverage"
	@echo   "pot          -- update duplicity.pot"
	@echo   "sdist        -- make versioned source"

genned_files=\
	'*.egg-info' \
	'*.gcda' \
	'*.gcno' \
	'*.gcov' \
	'*.o' \
	'*.orig' \
	'*.py[cdo]' \
	'*.tmp' \
	'*~' \
	'.eggs' \
	'.pytest_cache' \
	'.tox' \
	'__pycache__' \
	'_build' \
	'apsw' \
	'build' \
	'dist' \
	'duplicity*.rst' \
	'librsync*.so' \
	'megatestresults' \
	'report.xml' \
	'testdb*' \
	'testextension.sqlext' \
	'testing*.rst' \
	'wheelhouse' \
	'work'

# Use only half the cpus to keep htmlcov from getting resource errors
NUMPROC := $(shell python3 -c "import os; print(max((os.cpu_count() or 4) // 2, 2))")

.PHONY: clean
clean:
	for i in ${genned_files}; do \
		find . -name "$$i" | xargs -t -r rm -rf ; \
	done
	find . -name 'S.*' -type s -delete

.PHONY: docs
docs:
	python3 -m sphinx.ext.apidoc -o docs/ --separate --private . \
		docs apsw duplicity/backends/pyrax_identity/* duplicity/argparse311.py duplicity/dup_tarfile.py setup.* testing/overrides testing/manual
ifndef READTHEDOCS
	$(MAKE) -C docs html
endif

.PHONY: ext
ext:
	python3 ./setup.py build_ext

.PHONY: htmlcov
htmlcov:
	# refer to pyproject.toml for config [tool.coverage.*]
	python3 -m coverage erase
	python3 -m pytest -n$(NUMPROC) --cov=duplicity --cov-report=term --cov-report=html:htmlcov --cov-config=pyproject.toml
	python3 -m coverage erase

.PHONY: pot
pot:
	po/update-pot

.PHONY: sdist
sdist:
	python3 -m build --sdist
	gpg --use-agent -b dist/duplicity-*.tar.gz
