|
| 1 | +# vim: set noet sw=4 ts=4 fileencoding=utf-8: |
| 2 | + |
| 3 | +# External utilities |
| 4 | +PYTHON=python |
| 5 | +PIP=pip |
| 6 | +PYTEST=py.test |
| 7 | +COVERAGE=coverage |
| 8 | +PYFLAGS= |
| 9 | +DEST_DIR=/ |
| 10 | + |
| 11 | +# Horrid hack to ensure setuptools is installed in our python environment. This |
| 12 | +# is necessary with Python 3.3's venvs which don't install it by default. |
| 13 | +ifeq ($(shell python -c "import setuptools" 2>&1),) |
| 14 | +SETUPTOOLS:= |
| 15 | +else |
| 16 | +SETUPTOOLS:=$(shell wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | $(PYTHON)) |
| 17 | +endif |
| 18 | + |
| 19 | +# Calculate the base names of the distribution, the location of all source, |
| 20 | +# documentation, packaging, icon, and executable script files |
| 21 | +NAME:=$(shell $(PYTHON) $(PYFLAGS) setup.py --name) |
| 22 | +VER:=$(shell $(PYTHON) $(PYFLAGS) setup.py --version) |
| 23 | +ifeq ($(shell lsb_release -si),Ubuntu) |
| 24 | +DEB_SUFFIX:=ubuntu1 |
| 25 | +else |
| 26 | +DEB_SUFFIX:= |
| 27 | +endif |
| 28 | +DEB_ARCH:=$(shell dpkg --print-architecture) |
| 29 | +PYVER:=$(shell $(PYTHON) $(PYFLAGS) -c "import sys; print('py%d.%d' % sys.version_info[:2])") |
| 30 | +PY_SOURCES:=$(shell \ |
| 31 | + $(PYTHON) $(PYFLAGS) setup.py egg_info >/dev/null 2>&1 && \ |
| 32 | + grep -v "\.egg-info" $(NAME).egg-info/SOURCES.txt) |
| 33 | +DEB_SOURCES:=debian/changelog \ |
| 34 | + debian/control \ |
| 35 | + debian/copyright \ |
| 36 | + debian/rules \ |
| 37 | + debian/docs \ |
| 38 | + $(wildcard debian/*.init) \ |
| 39 | + $(wildcard debian/*.default) \ |
| 40 | + $(wildcard debian/*.manpages) \ |
| 41 | + $(wildcard debian/*.docs) \ |
| 42 | + $(wildcard debian/*.doc-base) \ |
| 43 | + $(wildcard debian/*.desktop) |
| 44 | +DOC_SOURCES:= |
| 45 | +SUBDIRS:= |
| 46 | + |
| 47 | +# Calculate the name of all outputs |
| 48 | +DIST_EGG=dist/$(NAME)-$(VER)-$(PYVER).egg |
| 49 | +DIST_TAR=dist/$(NAME)-$(VER).tar.gz |
| 50 | +DIST_ZIP=dist/$(NAME)-$(VER).zip |
| 51 | +DIST_DEB=dist/python-$(NAME)_$(VER)-1$(DEB_SUFFIX)_all.deb \ |
| 52 | + dist/python3-$(NAME)_$(VER)-1$(DEB_SUFFIX)_all.deb \ |
| 53 | + dist/python-$(NAME)-docs_$(VER)-1$(DEB_SUFFIX)_all.deb \ |
| 54 | + dist/$(NAME)_$(VER)-1$(DEB_SUFFIX)_$(DEB_ARCH).changes |
| 55 | +DIST_DSC=dist/$(NAME)_$(VER)-1$(DEB_SUFFIX).tar.gz \ |
| 56 | + dist/$(NAME)_$(VER)-1$(DEB_SUFFIX).dsc \ |
| 57 | + dist/$(NAME)_$(VER)-1$(DEB_SUFFIX)_source.changes |
| 58 | +MAN_PAGES= |
| 59 | + |
| 60 | + |
| 61 | +# Default target |
| 62 | +all: |
| 63 | + @echo "make install - Install on local system" |
| 64 | + @echo "make develop - Install symlinks for development" |
| 65 | + @echo "make test - Run tests" |
| 66 | + @echo "make doc - Generate HTML and PDF documentation" |
| 67 | + @echo "make source - Create source package" |
| 68 | + @echo "make egg - Generate a PyPI egg package" |
| 69 | + @echo "make zip - Generate a source zip package" |
| 70 | + @echo "make tar - Generate a source tar package" |
| 71 | + @echo "make deb - Generate Debian packages" |
| 72 | + @echo "make dist - Generate all packages" |
| 73 | + @echo "make clean - Get rid of all generated files" |
| 74 | + @echo "make release - Create and tag a new release" |
| 75 | + @echo "make upload - Upload the new release to repositories" |
| 76 | + |
| 77 | +install: $(SUBDIRS) |
| 78 | + $(PYTHON) $(PYFLAGS) setup.py install --root $(DEST_DIR) |
| 79 | + |
| 80 | +doc: $(DOC_SOURCES) |
| 81 | + $(MAKE) -C docs clean |
| 82 | + $(MAKE) -C docs html |
| 83 | + $(MAKE) -C docs latexpdf |
| 84 | + |
| 85 | +source: $(DIST_TAR) $(DIST_ZIP) |
| 86 | + |
| 87 | +egg: $(DIST_EGG) |
| 88 | + |
| 89 | +zip: $(DIST_ZIP) |
| 90 | + |
| 91 | +tar: $(DIST_TAR) |
| 92 | + |
| 93 | +deb: $(DIST_DEB) $(DIST_DSC) |
| 94 | + |
| 95 | +dist: $(DIST_EGG) $(DIST_DEB) $(DIST_DSC) $(DIST_TAR) $(DIST_ZIP) |
| 96 | + |
| 97 | +develop: tags |
| 98 | + @# These have to be done separately to avoid a cockup... |
| 99 | + $(PIP) install -U setuptools |
| 100 | + $(PIP) install -U pip |
| 101 | + $(PIP) install -e . |
| 102 | + |
| 103 | +test: |
| 104 | + $(COVERAGE) run -m $(PYTEST) tests -v |
| 105 | + $(COVERAGE) report --rcfile coverage.cfg |
| 106 | + |
| 107 | +clean: |
| 108 | + $(PYTHON) $(PYFLAGS) setup.py clean |
| 109 | + $(MAKE) -f $(CURDIR)/debian/rules clean |
| 110 | + $(MAKE) -C docs clean |
| 111 | + rm -fr build/ dist/ $(NAME).egg-info/ tags |
| 112 | + for dir in $(SUBDIRS); do \ |
| 113 | + $(MAKE) -C $$dir clean; \ |
| 114 | + done |
| 115 | + find $(CURDIR) -name "*.pyc" -delete |
| 116 | + |
| 117 | +tags: $(PY_SOURCES) |
| 118 | + ctags -R --exclude="build/*" --exclude="debian/*" --exclude="docs/*" --languages="Python" |
| 119 | + |
| 120 | +$(SUBDIRS): |
| 121 | + $(MAKE) -C $@ |
| 122 | + |
| 123 | +$(MAN_PAGES): $(DOC_SOURCES) |
| 124 | + $(PYTHON) $(PYFLAGS) setup.py build_sphinx -b man |
| 125 | + mkdir -p man/ |
| 126 | + cp build/sphinx/man/*.[0-9] man/ |
| 127 | + |
| 128 | +$(DIST_TAR): $(PY_SOURCES) $(SUBDIRS) |
| 129 | + $(PYTHON) $(PYFLAGS) setup.py sdist --formats gztar |
| 130 | + |
| 131 | +$(DIST_ZIP): $(PY_SOURCES) $(SUBDIRS) |
| 132 | + $(PYTHON) $(PYFLAGS) setup.py sdist --formats zip |
| 133 | + |
| 134 | +$(DIST_EGG): $(PY_SOURCES) $(SUBDIRS) |
| 135 | + $(PYTHON) $(PYFLAGS) setup.py bdist_egg |
| 136 | + |
| 137 | +$(DIST_DEB): $(PY_SOURCES) $(SUBDIRS) $(DEB_SOURCES) $(MAN_PAGES) |
| 138 | + # build the binary package in the parent directory then rename it to |
| 139 | + # project_version.orig.tar.gz |
| 140 | + $(PYTHON) $(PYFLAGS) setup.py sdist --dist-dir=../ |
| 141 | + rename -f 's/$(NAME)-(.*)\.tar\.gz/$(NAME)_$$1\.orig\.tar\.gz/' ../* |
| 142 | + debuild -b -i -I -Idist -Ibuild -Idocs/_build -Icoverage -I__pycache__ -I.coverage -Itags -I*.pyc -I*.vim -I*.xcf -rfakeroot |
| 143 | + mkdir -p dist/ |
| 144 | + for f in $(DIST_DEB); do cp ../$${f##*/} dist/; done |
| 145 | + |
| 146 | +$(DIST_DSC): $(PY_SOURCES) $(SUBDIRS) $(DEB_SOURCES) $(MAN_PAGES) |
| 147 | + # build the source package in the parent directory then rename it to |
| 148 | + # project_version.orig.tar.gz |
| 149 | + $(PYTHON) $(PYFLAGS) setup.py sdist --dist-dir=../ |
| 150 | + rename -f 's/$(NAME)-(.*)\.tar\.gz/$(NAME)_$$1\.orig\.tar\.gz/' ../* |
| 151 | + debuild -S -i -I -Idist -Ibuild -Idocs/_build -Icoverage -I__pycache__ -I.coverage -Itags -I*.pyc -I*.vim -I*.xcf -rfakeroot |
| 152 | + mkdir -p dist/ |
| 153 | + for f in $(DIST_DSC); do cp ../$${f##*/} dist/; done |
| 154 | + |
| 155 | +release: $(PY_SOURCES) $(DOC_SOURCES) $(DEB_SOURCES) |
| 156 | + $(MAKE) clean |
| 157 | + # ensure there are no current uncommitted changes |
| 158 | + test -z "$(shell git status --porcelain)" |
| 159 | + # update the debian changelog with new release information |
| 160 | + dch --newversion $(VER)-1$(DEB_SUFFIX) --controlmaint |
| 161 | + # commit the changes and add a new tag |
| 162 | + git commit debian/changelog -m "Updated changelog for release $(VER)" |
| 163 | + git tag -s release-$(VER) -m "Release $(VER)" |
| 164 | + # update the package's registration on PyPI (in case any metadata's changed) |
| 165 | + $(PYTHON) $(PYFLAGS) setup.py register |
| 166 | + |
| 167 | +upload: $(PY_SOURCES) $(DOC_SOURCES) $(DIST_DEB) $(DIST_DSC) |
| 168 | + # build a source archive and upload to PyPI |
| 169 | + $(PYTHON) $(PYFLAGS) setup.py sdist upload |
| 170 | + # build the deb source archive and upload to Raspbian |
| 171 | + dput raspberrypi dist/$(NAME)_$(VER)-1$(DEB_SUFFIX)_source.changes |
| 172 | + dput raspberrypi dist/$(NAME)_$(VER)-1$(DEB_SUFFIX)_$(DEB_ARCH).changes |
| 173 | + git push --tags |
| 174 | + |
| 175 | +.PHONY: all install develop test doc source egg zip tar deb dist clean tags release upload $(SUBDIRS) |
| 176 | + |
0 commit comments