chiark / gitweb /
COPYRIGHT: Fix comment for LGPL-2.
[cfd] / build / pysetup.mk
1 ### -*-makefile-*-
2 ###
3 ### Standard Makefile for Python packages.
4 ###
5 ### (c) 2013, 2019, 2020 Straylight/Edgeware
6 ###
7
8 ###----- Licensing notice ---------------------------------------------------
9 ###
10 ### This file is part of the Common Files Distribution (`common').
11 ###
12 ### `Common' is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU General Public License as published by
14 ### the Free Software Foundation; either version 2 of the License, or
15 ### (at your option) any later version.
16 ###
17 ### `Common' is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ### GNU General Public License for more details.
21 ###
22 ### You should have received a copy of the GNU General Public License
23 ### along with `common'; if not, write to the Free Software Foundation,
24 ### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26 default: all
27
28 PYTHON                  ?= python
29 PYTHONS                 ?= $(PYTHON)
30 prefix                  ?= /usr/local
31
32 ###--------------------------------------------------------------------------
33 ### Version information.
34
35 distdir                 := $(shell $(PYTHON) setup.py -q distdir)
36
37 ###--------------------------------------------------------------------------
38 ### Useful targets implemented by the `setup.py' program.
39
40 SINGLE_PYTARGETS        += gen
41 CMD-gen                 ?= build_gen
42
43 PYTARGETS               += all
44 CMD-all                 ?= build
45 $(foreach p,$(PYTHONS),all/$p):: all/%: gen
46
47 PYTARGETS               += clean
48 OPTS-clean              ?= --all
49 clean-hook::; rm -f MANIFEST RELEASE
50
51 SINGLE_PYTARGETS        += dist
52 CMD-dist                ?= sdist
53 OPTS-dist               += --dist-dir .
54
55 PYTARGETS               += install
56 OPTS-install            += --prefix $(prefix) \
57                                 $(and $(DESTDIR),--root $(DESTDIR))
58
59 PYTARGETS               += check
60 CMD-check               ?= test
61 $(foreach p,$(PYTHONS),check/$p):: check/%: all/%
62
63 ###--------------------------------------------------------------------------
64 ### Interfacing `setup.py' to make.
65
66 pysetup = $(or $2,$(PYTHON)) setup.py \
67         $(if $(filter-out undefined,$(origin CMD-$1)),$(CMD-$1),$1) \
68         $(OPTS-$1) $(OPTS-$1/$(or $2,$(PYTHON)))
69
70 PYTHON_PYTARGETS         = $(foreach t, $(PYTARGETS), \
71                                 $(foreach p, $(PYTHONS), \
72                                         $t/$p))
73 ALL_PYTARGETS            = $(PYTARGETS)
74 ALL_PYTARGETS           += $(SINGLE_PYTARGETS) $(PYTHON_PYTARGETS)
75
76 $(foreach t, $(ALL_PYTARGETS), $t-hook):: %:
77
78 $(SINGLE_PYTARGETS):: %: %-hook setup.py
79         $(call pysetup,$*)
80 $(PYTARGETS):: %: %-hook $(foreach p, $(PYTHONS), %/$p)
81 $(PYTHON_PYTARGETS):: %: %-hook setup.py
82         $(call pysetup,$(patsubst %/,%,$(dir $*)),$(notdir $*))
83
84 .PHONY: $(ALL_PYTARGETS)
85
86 ###--------------------------------------------------------------------------
87 ### Release builds.
88
89 distcheck:
90         rm -rf _distcheck
91         $(PYTHON) setup.py sdist --dist-dir _distcheck
92         cd _distcheck && tar xvfz $(distdir).tar.gz
93         cd _distcheck/$(distdir) && $(MAKE) check && $(MAKE) dist
94         cp _distcheck/$(distdir)/$(distdir).tar.gz .
95         rm -rf _distcheck
96
97 ###----- That's all, folks --------------------------------------------------