Scatter the useful files into subdirectories by theme.
[cfd] / build / pysetup.mk
diff --git a/build/pysetup.mk b/build/pysetup.mk
new file mode 100644 (file)
index 0000000..8e6e607
--- /dev/null
@@ -0,0 +1,76 @@
+### -*-makefile-*-
+###
+### Standard Makefile for Python packages.
+
+default: all
+
+PYTHON                 ?= python
+PYTHONS                        ?= $(PYTHON)
+prefix                 ?= /usr/local
+
+###--------------------------------------------------------------------------
+### Version information.
+
+distdir                        := $(shell $(PYTHON) setup.py -q distdir)
+
+###--------------------------------------------------------------------------
+### Useful targets implemented by the `setup.py' program.
+
+SINGLE_PYTARGETS       += gen
+CMD-gen                        ?= build_gen
+
+PYTARGETS              += all
+CMD-all                        ?= build
+$(foreach p,$(PYTHONS),all/$p):: all/%: gen
+
+PYTARGETS              += clean
+OPTS-clean             ?= --all
+clean-hook::; rm -f MANIFEST RELEASE
+
+SINGLE_PYTARGETS       += dist
+CMD-dist               ?= sdist
+OPTS-dist              += --dist-dir .
+
+PYTARGETS              += install
+OPTS-install           += --prefix $(prefix) \
+                               $(and $(DESTDIR),--root $(DESTDIR))
+
+PYTARGETS              += check
+CMD-check              ?= test
+$(foreach p,$(PYTHONS),check/$p):: check/%: all/%
+
+###--------------------------------------------------------------------------
+### Interfacing `setup.py' to make.
+
+pysetup = $(or $2,$(PYTHON)) setup.py \
+       $(if $(filter-out undefined,$(origin CMD-$1)),$(CMD-$1),$1) \
+       $(OPTS-$1) $(OPTS-$1/$(or $2,$(PYTHON)))
+
+PYTHON_PYTARGETS        = $(foreach t, $(PYTARGETS), \
+                               $(foreach p, $(PYTHONS), \
+                                       $t/$p))
+ALL_PYTARGETS           = $(PYTARGETS)
+ALL_PYTARGETS          += $(SINGLE_PYTARGETS) $(PYTHON_PYTARGETS)
+
+$(foreach t, $(ALL_PYTARGETS), $t-hook):: %:
+
+$(SINGLE_PYTARGETS):: %: %-hook setup.py
+       $(call pysetup,$*)
+$(PYTARGETS):: %: %-hook $(foreach p, $(PYTHONS), %/$p)
+$(PYTHON_PYTARGETS):: %: %-hook setup.py
+       $(call pysetup,$(patsubst %/,%,$(dir $*)),$(notdir $*))
+
+.PHONY: $(ALL_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) check && $(MAKE) dist
+       cp _distcheck/$(distdir)/$(distdir).tar.gz .
+       rm -rf _distcheck
+
+###----- That's all, folks --------------------------------------------------