|
| 1 | +# vim: set noet sw=4 ts=4 fileencoding=utf-8: |
| 2 | + |
| 3 | +# External utilities |
| 4 | +PYTHON=python3 |
| 5 | +PYFLAGS= |
| 6 | +DEST_DIR=/ |
| 7 | + |
| 8 | +# Horrid hack to ensure setuptools is installed in our python environment. This |
| 9 | +# is necessary with Python 3.3's venvs which don't install it by default. |
| 10 | +ifeq ($(shell python -c "import setuptools" 2>&1),) |
| 11 | +SETUPTOOLS:= |
| 12 | +else |
| 13 | +SETUPTOOLS:=$(shell wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | $(PYTHON)) |
| 14 | +endif |
| 15 | + |
| 16 | +# Calculate the base names of the distribution, the location of all source, |
| 17 | +# documentation, packaging, icon, and executable script files |
| 18 | +NAME:=$(shell $(PYTHON) $(PYFLAGS) setup.py --name) |
| 19 | +VER:=$(shell $(PYTHON) $(PYFLAGS) setup.py --version) |
| 20 | +PYVER:=$(shell $(PYTHON) $(PYFLAGS) -c "import sys; print('py%d.%d' % sys.version_info[:2])") |
| 21 | +PY_SOURCES:=$(shell \ |
| 22 | + $(PYTHON) $(PYFLAGS) setup.py egg_info >/dev/null 2>&1 && \ |
| 23 | + cat $(NAME).egg-info/SOURCES.txt) |
| 24 | +DOC_SOURCES:=$(wildcard docs/*.rst) |
| 25 | + |
| 26 | +# Calculate the name of all outputs |
| 27 | +DIST_EGG=dist/$(NAME)-$(VER)-$(PYVER).egg |
| 28 | +DIST_TAR=dist/$(NAME)-$(VER).tar.gz |
| 29 | +DIST_ZIP=dist/$(NAME)-$(VER).zip |
| 30 | + |
| 31 | + |
| 32 | +# Default target |
| 33 | +all: |
| 34 | + @echo "make install - Install on local system" |
| 35 | + @echo "make develop - Install symlinks for development" |
| 36 | + @echo "make test - Run tests" |
| 37 | + @echo "make doc - Generate HTML and PDF documentation" |
| 38 | + @echo "make source - Create source package" |
| 39 | + @echo "make egg - Generate a PyPI egg package" |
| 40 | + @echo "make zip - Generate a source zip package" |
| 41 | + @echo "make tar - Generate a source tar package" |
| 42 | + @echo "make dist - Generate all packages" |
| 43 | + @echo "make clean - Get rid of all generated files" |
| 44 | + @echo "make release - Create and tag a new release" |
| 45 | + @echo "make upload - Upload the new release to repositories" |
| 46 | + |
| 47 | +install: |
| 48 | + $(PYTHON) $(PYFLAGS) setup.py install --root $(DEST_DIR) |
| 49 | + |
| 50 | +doc: $(DOC_SOURCES) |
| 51 | + $(PYTHON) $(PYFLAGS) setup.py build_sphinx -b html |
| 52 | + |
| 53 | +source: $(DIST_TAR) $(DIST_ZIP) |
| 54 | + |
| 55 | +egg: $(DIST_EGG) |
| 56 | + |
| 57 | +zip: $(DIST_ZIP) |
| 58 | + |
| 59 | +tar: $(DIST_TAR) |
| 60 | + |
| 61 | +dist: $(DIST_EGG) $(DIST_RPM) $(DIST_DEB) $(DIST_TAR) $(DIST_ZIP) |
| 62 | + |
| 63 | +develop: tags |
| 64 | + $(PYTHON) $(PYFLAGS) setup.py develop |
| 65 | + |
| 66 | +test: |
| 67 | + $(PYTHON) $(PYFLAGS) setup.py test |
| 68 | + |
| 69 | +clean: |
| 70 | + $(PYTHON) $(PYFLAGS) setup.py clean |
| 71 | + $(MAKE) -f $(CURDIR)/debian/rules clean |
| 72 | + rm -fr build/ dist/ $(NAME).egg-info/ tags |
| 73 | + find $(CURDIR) -name "*.pyc" -delete |
| 74 | + |
| 75 | +tags: $(PY_SOURCES) |
| 76 | + ctags -R --exclude="build/*" --exclude="debian/*" --exclude="docs/*" --languages="Python" |
| 77 | + |
| 78 | +$(DIST_TAR): $(PY_SOURCES) |
| 79 | + $(PYTHON) $(PYFLAGS) setup.py sdist --formats gztar |
| 80 | + |
| 81 | +$(DIST_ZIP): $(PY_SOURCES) |
| 82 | + $(PYTHON) $(PYFLAGS) setup.py sdist --formats zip |
| 83 | + |
| 84 | +$(DIST_EGG): $(PY_SOURCES) |
| 85 | + $(PYTHON) $(PYFLAGS) setup.py bdist_egg |
| 86 | + |
| 87 | +release: $(PY_SOURCES) $(DOC_SOURCES) |
| 88 | + $(MAKE) clean |
| 89 | + # ensure there are no current uncommitted changes |
| 90 | + test -z "$(shell git status --porcelain)" |
| 91 | + # commit the changes and add a new tag |
| 92 | + git commit debian/changelog -m "Updated changelog for release $(VER)" |
| 93 | + git tag -s release-$(VER) -m "Release $(VER)" |
| 94 | + |
| 95 | +upload: $(PY_SOURCES) $(DOC_SOURCES) |
| 96 | + # build a source archive and upload to PyPI |
| 97 | + $(PYTHON) $(PYFLAGS) setup.py sdist upload |
| 98 | + |
| 99 | +.PHONY: all install develop test doc source egg zip tar dist clean tags release upload |
| 100 | + |
0 commit comments