chiark / gitweb /
pysetup.mk: Makefile fragment for interfacing to `setup.py'.
[cfd] / pysetup.mk
diff --git a/pysetup.mk b/pysetup.mk
new file mode 100644 (file)
index 0000000..0e7a218
--- /dev/null
@@ -0,0 +1,58 @@
+### -*-makefile-*-
+###
+### Standard Makefile for Python packages.
+
+default: all
+
+PYTHON                 ?= python
+prefix                 ?= /usr/local
+
+###--------------------------------------------------------------------------
+### Version information.
+
+distdir                        := $(shell $(PYTHON) setup.py -q distdir)
+
+###--------------------------------------------------------------------------
+### Useful targets implemented by the `setup.py' program.
+
+PYTARGETS              += all
+CMD-all                        ?= build
+
+PYTARGETS              += clean
+OPTS-clean             ?= --all
+clean-hook::; rm -f MANIFEST RELEASE
+
+PYTARGETS              += dist
+CMD-dist               ?= sdist
+OPTS-dist              += --dist-dir .
+
+PYTARGETS              += install
+OPTS-install           += --prefix $(prefix)
+
+PYTARGETS              += check
+
+###--------------------------------------------------------------------------
+### Interfacing `setup.py' to make.
+
+pysetup = $(PYTHON) setup.py \
+       $(if $(filter-out undefined,$(origin CMD-$1)),$(CMD-$1),$1) \
+       $(OPTS-$1)
+
+$(foreach t, $(PYTARGETS), $t-hook):: %:
+$(PYTARGETS):: %: %-hook setup.py
+       $(call pysetup,$*)
+
+.PHONY: $(PYTARGETS)
+
+###--------------------------------------------------------------------------
+### Release builds.
+
+distcheck:
+       rm -rf _distcheck
+       $(PYTHON) setup.py sdist --dist-dir _distcheck
+       cd _distcheck && tar xvfz $(distdir).tar.gz
+       cd _distcheck/$(distdir) && make && make check && make dist
+       cp _distcheck/$(distdir)/$(distdir).tar.gz .
+       rm -rf _distcheck
+
+###----- That's all, folks --------------------------------------------------