pysetup.mk: Run commands on multiple `python's, possibly in parallel.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 14 Oct 2019 10:22:16 +0000 (11:22 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 8 May 2020 11:30:13 +0000 (12:30 +0100)
Most targets delegated to `setup.py' are now run, in parallel, on
multiple Python versions listed in the new Makefile variable `PYTHONS'.
The exceptions are `gen' and `dist', which only make sense with a single
Python.

Targets which can run multiple Python versions now support per-version
options for targets: set the variable OPTS-TARGET/PYTHON (e.g.,
`OPTS-install/python3.5').

pysetup.mk

index 09dd7b0..633e96c 100644 (file)
@@ -5,6 +5,7 @@
 default: all
 
 PYTHON                 ?= python
+PYTHONS                        ?= $(PYTHON)
 prefix                 ?= /usr/local
 
 ###--------------------------------------------------------------------------
@@ -15,18 +16,18 @@ distdir                     := $(shell $(PYTHON) setup.py -q distdir)
 ###--------------------------------------------------------------------------
 ### Useful targets implemented by the `setup.py' program.
 
-PYTARGETS              += gen
+SINGLE_PYTARGETS       += gen
 CMD-gen                        ?= build_gen
 
 PYTARGETS              += all
 CMD-all                        ?= build
-all:: gen
+$(foreach p,$(PYTHONS),all/$p):: all/%: gen
 
 PYTARGETS              += clean
 OPTS-clean             ?= --all
 clean-hook::; rm -f MANIFEST RELEASE
 
-PYTARGETS              += dist
+SINGLE_PYTARGETS       += dist
 CMD-dist               ?= sdist
 OPTS-dist              += --dist-dir .
 
@@ -38,15 +39,25 @@ PYTARGETS           += check
 ###--------------------------------------------------------------------------
 ### Interfacing `setup.py' to make.
 
-pysetup = $(PYTHON) setup.py \
+pysetup = $(or $2,$(PYTHON)) setup.py \
        $(if $(filter-out undefined,$(origin CMD-$1)),$(CMD-$1),$1) \
-       $(OPTS-$1)
+       $(OPTS-$1) $(OPTS-$1/$(or $2,$(PYTHON)))
 
-$(foreach t, $(PYTARGETS), $t-hook):: %:
-$(PYTARGETS):: %: %-hook setup.py
+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: $(PYTARGETS)
+.PHONY: $(ALL_PYTARGETS)
 
 ###--------------------------------------------------------------------------
 ### Release builds.