| 1 |
# vim: set noet sw=4 ts=4 fileencoding=utf-8: |
| 2 |
|
| 3 |
# External utilities |
| 4 |
PYTHON=python3 |
| 5 |
PIP=pip |
| 6 |
PYTEST=pytest |
| 7 |
TWINE=twine |
| 8 |
PYFLAGS= |
| 9 |
DEST_DIR=/ |
| 10 |
|
| 11 |
# Calculate the base names of the distribution, the location of all source, |
| 12 |
# documentation, packaging, icon, and executable script files |
| 13 |
NAME:=$(shell $(PYTHON) $(PYFLAGS) setup.py --name) |
| 14 |
PKG_DIR:=$(subst -,_,$(NAME)) |
| 15 |
VER:=$(shell $(PYTHON) $(PYFLAGS) setup.py --version) |
| 16 |
PY_SOURCES:=$(shell \ |
| 17 |
$(PYTHON) $(PYFLAGS) setup.py egg_info >/dev/null 2>&1 && \ |
| 18 |
grep -v "\.egg-info" $(PKG_DIR).egg-info/SOURCES.txt) |
| 19 |
DOC_SOURCES:=docs/conf.py \ |
| 20 |
$(wildcard docs/*.png) \ |
| 21 |
$(wildcard docs/*.svg) \ |
| 22 |
$(wildcard docs/*.dot) \ |
| 23 |
$(wildcard docs/*.mscgen) \ |
| 24 |
$(wildcard docs/*.gpi) \ |
| 25 |
$(wildcard docs/*.rst) \ |
| 26 |
$(wildcard docs/*.pdf) |
| 27 |
SUBDIRS:= |
| 28 |
|
| 29 |
# Calculate the name of all outputs |
| 30 |
DIST_WHEEL=dist/$(NAME)-$(VER)-py2.py3-none-any.whl |
| 31 |
DIST_TAR=dist/$(NAME)-$(VER).tar.gz |
| 32 |
DIST_ZIP=dist/$(NAME)-$(VER).zip |
| 33 |
|
| 34 |
# Default target |
| 35 |
all: |
| 36 |
@echo "make install - Install on local system" |
| 37 |
@echo "make develop - Install symlinks for development" |
| 38 |
@echo "make test - Run tests" |
| 39 |
@echo "make doc - Generate HTML and PDF documentation" |
| 40 |
@echo "make source - Create source package" |
| 41 |
@echo "make wheel - Generate a PyPI wheel package" |
| 42 |
@echo "make zip - Generate a source zip package" |
| 43 |
@echo "make tar - Generate a source tar package" |
| 44 |
@echo "make dist - Generate all packages" |
| 45 |
@echo "make clean - Get rid of all generated files" |
| 46 |
@echo "make release - Create and tag a new release" |
| 47 |
@echo "make upload - Upload the new release to repositories" |
| 48 |
|
| 49 |
install: $(SUBDIRS) |
| 50 |
$(PYTHON) $(PYFLAGS) setup.py install --root $(DEST_DIR) |
| 51 |
|
| 52 |
doc: $(DOC_SOURCES) |
| 53 |
$(MAKE) -C docs clean |
| 54 |
$(MAKE) -C docs html |
| 55 |
$(MAKE) -C docs epub |
| 56 |
$(MAKE) -C docs latexpdf |
| 57 |
|
| 58 |
source: $(DIST_TAR) $(DIST_ZIP) |
| 59 |
|
| 60 |
wheel: $(DIST_WHEEL) |
| 61 |
|
| 62 |
zip: $(DIST_ZIP) |
| 63 |
|
| 64 |
tar: $(DIST_TAR) |
| 65 |
|
| 66 |
dist: $(DIST_WHEEL) $(DIST_TAR) $(DIST_ZIP) |
| 67 |
|
| 68 |
develop: tags |
| 69 |
@# These have to be done separately to avoid a cockup... |
| 70 |
$(PIP) install -U setuptools |
| 71 |
$(PIP) install -U pip |
| 72 |
$(PIP) install -e .[doc,test] |
| 73 |
|
| 74 |
test: |
| 75 |
$(PYTEST) tests |
| 76 |
|
| 77 |
clean: |
| 78 |
rm -fr dist/ build/ .pytest_cache/ $(NAME).egg-info/ tags .coverage |
| 79 |
for dir in $(SUBDIRS); do \ |
| 80 |
$(MAKE) -C $$dir clean; \ |
| 81 |
done |
| 82 |
find $(CURDIR) -name "*.pyc" -delete |
| 83 |
|
| 84 |
tags: $(PY_SOURCES) |
| 85 |
ctags -R --exclude="build/*" --exclude="docs/*" --languages="Python" |
| 86 |
|
| 87 |
$(SUBDIRS): |
| 88 |
$(MAKE) -C $@ |
| 89 |
|
| 90 |
$(DIST_TAR): $(PY_SOURCES) $(SUBDIRS) |
| 91 |
$(PYTHON) $(PYFLAGS) setup.py sdist --formats gztar |
| 92 |
|
| 93 |
$(DIST_ZIP): $(PY_SOURCES) $(SUBDIRS) |
| 94 |
$(PYTHON) $(PYFLAGS) setup.py sdist --formats zip |
| 95 |
|
| 96 |
$(DIST_WHEEL): $(PY_SOURCES) $(SUBDIRS) |
| 97 |
$(PYTHON) $(PYFLAGS) setup.py bdist_wheel --universal |
| 98 |
|
| 99 |
release: |
| 100 |
$(MAKE) clean |
| 101 |
test -z "$(shell git status --porcelain)" |
| 102 |
git tag -s release-$(VER) -m "Release $(VER)" |
| 103 |
git push origin release-$(VER) |
| 104 |
$(MAKE) $(DIST_TAR) $(DIST_WHEEL) |
| 105 |
$(TWINE) check $(DIST_TAR) $(DIST_WHEEL) |
| 106 |
$(TWINE) upload $(DIST_TAR) $(DIST_WHEEL) |
| 107 |
|
| 108 |
.PHONY: all install develop test doc source egg wheel zip tar dist clean tags release upload $(SUBDIRS) |