]> arthur.barton.de Git - bup.git/blob - GNUmakefile
make: add check-py2 and check-py3 targets
[bup.git] / GNUmakefile
1
2 MAKEFLAGS += --warn-undefined-variables
3 OUTPUT_OPTION = -MMD -MP -o $@
4
5 SHELL := bash
6 .DEFAULT_GOAL := all
7
8 clean_paths :=
9 generated_dependencies :=
10
11 # See config/config.vars.in (sets bup_python_config, among other things)
12 include config/config.vars
13 -include $(generated_dependencies)
14
15 pf := set -o pipefail
16
17 define isok
18   && echo " ok" || echo " no"
19 endef
20
21 # If ok, strip trailing " ok" and return the output, otherwise, error
22 define shout
23 $(if $(subst ok,,$(lastword $(1))),$(error $(2)),$(shell x="$(1)"; echo $${x%???}))
24 endef
25
26 sampledata_rev := $(shell dev/configure-sampledata --revision $(isok))
27 sampledata_rev := \
28   $(call shout,$(sampledata_rev),Could not parse sampledata revision)
29
30 current_sampledata := test/sampledata/var/rev/v$(sampledata_rev)
31
32 os := $(shell ($(pf); uname | sed 's/[-_].*//') $(isok))
33 os := $(call shout,$(os),Unable to determine OS)
34
35 # Satisfy --warn-undefined-variables
36 CFLAGS ?=
37 DESTDIR ?=
38 CPPFLAGS ?=
39 LDFLAGS ?=
40 TARGET_ARCH ?=
41
42 bup_shared_cflags := -O2 -Wall -Werror -Wformat=2
43 bup_shared_cflags := -Wno-unused-command-line-argument $(bup_shared_cflags)
44 bup_shared_cflags := -Wno-unknown-pragmas -Wsign-compare $(bup_shared_cflags)
45 bup_shared_cflags := -D_FILE_OFFSET_BITS=64 $(bup_shared_cflags)
46
47 bup_shared_ldflags :=
48
49 soext := .so
50 ifeq ($(os),CYGWIN)
51   soext := .dll
52 endif
53
54 ifdef TMPDIR
55   test_tmp := $(TMPDIR)
56 else
57   test_tmp := $(CURDIR)/test/tmp
58 endif
59
60 initial_setup := $(shell dev/update-checkout-info lib/bup/checkout_info.py $(isok))
61 initial_setup := $(call shout,$(initial_setup),update-checkout-info failed))
62 clean_paths += lib/bup/checkout_info.py
63
64 # Dependency changes here should be mirrored in Makefile
65 config/config.vars: configure config/configure config/configure.inc config/*.in
66         MAKE="$(MAKE)" ./configure
67
68 # On some platforms, Python.h and readline.h fight over the
69 # _XOPEN_SOURCE version, i.e. -Werror crashes on a mismatch, so for
70 # now, we're just going to let Python's version win.
71
72 helpers_cflags := $(bup_python_cflags) $(bup_shared_cflags) -I$(CURDIR)/src
73 helpers_ldflags := $(bup_python_ldflags) $(bup_shared_ldflags)
74
75 ifneq ($(strip $(bup_readline_cflags)),)
76   readline_cflags += $(bup_readline_cflags)
77   readline_xopen := $(filter -D_XOPEN_SOURCE=%,$(readline_cflags))
78   readline_xopen := $(subst -D_XOPEN_SOURCE=,,$(readline_xopen))
79   readline_cflags := $(filter-out -D_XOPEN_SOURCE=%,$(readline_cflags))
80   readline_cflags += $(addprefix -DBUP_RL_EXPECTED_XOPEN_SOURCE=,$(readline_xopen))
81   helpers_cflags += $(readline_cflags)
82 endif
83
84 helpers_ldflags += $(bup_readline_ldflags)
85
86 ifeq ($(bup_have_libacl),1)
87   helpers_cflags += $(bup_libacl_cflags)
88   helpers_ldflags += $(bup_libacl_ldflags)
89 endif
90
91 bup_ext_cmds := lib/cmd/bup-import-rdiff-backup lib/cmd/bup-import-rsnapshot
92
93 bup_deps := lib/bup/_helpers$(soext) lib/cmd/bup
94
95 all: dev/bup-exec dev/bup-python dev/python $(bup_deps) Documentation/all \
96   $(current_sampledata)
97
98 $(current_sampledata):
99         dev/configure-sampledata --setup
100
101 PANDOC ?= $(shell type -p pandoc)
102
103 ifeq (,$(PANDOC))
104   $(shell echo "Warning: pandoc not found; skipping manpage generation" 1>&2)
105   man_md :=
106 else
107   man_md := $(wildcard Documentation/*.md)
108 endif
109
110 man_roff := $(patsubst %.md,%.1,$(man_md))
111 man_html := $(patsubst %.md,%.html,$(man_md))
112
113 INSTALL=install
114 PREFIX=/usr/local
115 MANDIR=$(PREFIX)/share/man
116 DOCDIR=$(PREFIX)/share/doc/bup
117 BINDIR=$(PREFIX)/bin
118 LIBDIR=$(PREFIX)/lib/bup
119
120 dest_mandir := $(DESTDIR)$(MANDIR)
121 dest_docdir := $(DESTDIR)$(DOCDIR)
122 dest_bindir := $(DESTDIR)$(BINDIR)
123 dest_libdir := $(DESTDIR)$(LIBDIR)
124
125 install: all
126         $(INSTALL) -d $(dest_bindir) $(dest_libdir)/bup/cmd $(dest_libdir)/cmd \
127           $(dest_libdir)/web/static
128         test -z "$(man_roff)" || install -d $(dest_mandir)/man1
129         test -z "$(man_roff)" || $(INSTALL) -m 0644 $(man_roff) $(dest_mandir)/man1
130         test -z "$(man_html)" || install -d $(dest_docdir)
131         test -z "$(man_html)" || $(INSTALL) -m 0644 $(man_html) $(dest_docdir)
132         $(INSTALL) -pm 0755 lib/cmd/bup "$(dest_libdir)/cmd/bup"
133         $(INSTALL) -pm 0755 $(bup_ext_cmds) "$(dest_libdir)/cmd/"
134         cd "$(dest_bindir)" && \
135           ln -sf "$$($(CURDIR)/dev/python -c 'import os; print(os.path.relpath("$(abspath $(dest_libdir))/cmd/bup"))')" \
136             .
137         set -e; \
138         $(INSTALL) -pm 0644 lib/bup/*.py $(dest_libdir)/bup/
139         $(INSTALL) -pm 0644 lib/bup/cmd/*.py $(dest_libdir)/bup/cmd/
140         $(INSTALL) -pm 0755 \
141                 lib/bup/*$(soext) \
142                 $(dest_libdir)/bup
143         $(INSTALL) -pm 0644 \
144                 lib/web/static/* \
145                 $(dest_libdir)/web/static/
146         $(INSTALL) -pm 0644 \
147                 lib/web/*.html \
148                 $(dest_libdir)/web/
149         if test -e lib/bup/checkout_info.py; then \
150             $(INSTALL) -pm 0644 lib/bup/checkout_info.py \
151                 $(dest_libdir)/bup/source_info.py; \
152         else \
153             ! grep -qF '$$Format' lib/bup/source_info.py; \
154             $(INSTALL) -pm 0644 lib/bup/source_info.py $(dest_libdir)/bup/; \
155         fi
156
157 embed_cflags := $(bup_python_cflags_embed) $(bup_shared_cflags) -I$(CURDIR)/src
158 embed_ldflags := $(bup_python_ldflags_embed) $(bup_shared_ldflags)
159
160 config/config.h: config/config.vars
161 clean_paths += config/config.h.tmp
162
163 cc_bin = $(CC) $(embed_cflags) $(CFLAGS) $^ $(embed_ldflags) $(LDFLAGS) -fPIE \
164   -I src $(OUTPUT_OPTION)
165
166 clean_paths += dev/python-proposed
167 generated_dependencies += dev/python-proposed.d
168 dev/python-proposed: dev/python.c src/bup/compat.c src/bup/io.c
169         rm -f dev/python
170         $(cc_bin)
171
172 clean_paths += dev/python
173 dev/python: dev/python-proposed
174         dev/validate-python $@-proposed
175         ln $@-proposed $@
176
177 clean_paths += dev/bup-exec
178 generated_dependencies += dev/bup-exec.d
179 dev/bup-exec: CFLAGS += -D BUP_DEV_BUP_EXEC=1
180 dev/bup-exec: lib/cmd/bup.c src/bup/compat.c src/bup/io.c
181         $(cc_bin)
182
183 clean_paths += dev/bup-python
184 generated_dependencies += dev/bup-python.d
185 dev/bup-python: CFLAGS += -D BUP_DEV_BUP_PYTHON=1
186 dev/bup-python: lib/cmd/bup.c src/bup/compat.c src/bup/io.c
187         $(cc_bin)
188
189 clean_paths += lib/cmd/bup
190 generated_dependencies += lib/cmd/bup.d
191 lib/cmd/bup: lib/cmd/bup.c src/bup/compat.c src/bup/io.c
192         $(cc_bin)
193
194 clean_paths += lib/bup/_helpers$(soext)
195 generated_dependencies += lib/bup/_helpers.d
196 lib/bup/_helpers$(soext): lib/bup/_helpers.c lib/bup/bupsplit.c
197         $(CC) $(helpers_cflags) $(CFLAGS) $^ \
198           $(helpers_ldflags) $(LDFLAGS) $(OUTPUT_OPTION)
199
200 test/tmp:
201         mkdir test/tmp
202
203 # MAKEFLAGS must not be in an immediate := assignment
204 parallel_opt = $(lastword $(filter -j%,$(MAKEFLAGS)))
205 get_parallel_n = $(patsubst -j%,%,$(parallel_opt))
206 maybe_specific_n = $(if $(filter -j%,$(parallel_opt)),-n$(get_parallel_n))
207 xdist_opt = $(if $(filter -j,$(parallel_opt)),-nauto,$(maybe_specific_n))
208
209 lint: dev/bup-exec dev/bup-python
210         ./pylint
211
212 test: all test/tmp dev/python lint
213         ./bup features
214         if test yes = "$$(dev/python -c 'import xdist; print("yes")' 2>/dev/null)"; then \
215            (set -x; ./pytest $(xdist_opt);) \
216         else \
217           (set -x; ./pytest;) \
218         fi
219
220 stupid:
221         PATH=/bin:/usr/bin $(MAKE) test
222
223 check: test
224
225 distcheck: all
226         if test yes = $$(dev/python -c "import xdist; print('yes')" 2>/dev/null); then \
227           (set -x; ./pytest $(xdist_opt) -m release;) \
228         else \
229           (set -x; ./pytest -m release;) \
230         fi
231
232 long-test: export BUP_TEST_LEVEL=11
233 long-test: test
234
235 long-check: export BUP_TEST_LEVEL=11
236 long-check: check
237
238 .PHONY: check-py2 check-py3 check-both
239 check-py3:
240         $(MAKE) clean && BUP_PYTHON_CONFIG=python3-config $(MAKE) check
241 check-py2:
242         $(MAKE) clean && BUP_PYTHON_CONFIG=python2.7-config $(MAKE) check
243 check-both:
244         $(MAKE) check-py3
245         $(MAKE) check-py2
246
247 .PHONY: Documentation/all
248 Documentation/all: $(man_roff) $(man_html)
249
250 Documentation/substvars: $(bup_deps)
251         # FIXME: real temp file
252         set -e; bup_ver=$$(./bup version); \
253         echo "s,%BUP_VERSION%,$$bup_ver,g" > $@.tmp; \
254         echo "s,%BUP_DATE%,$$bup_ver,g" >> $@.tmp
255         mv $@.tmp $@
256
257 Documentation/%.1: Documentation/%.md Documentation/substvars
258         $(pf); sed -f Documentation/substvars $< \
259           | "$(PANDOC)" -s -r markdown -w man -o $@
260
261 Documentation/%.html: Documentation/%.md Documentation/substvars
262         $(pf); sed -f Documentation/substvars $< \
263           | "$(PANDOC)" -s -r markdown -w html -o $@
264
265 .PHONY: Documentation/clean
266 Documentation/clean:
267         cd Documentation && rm -f *~ .*~ *.[0-9] *.html substvars
268
269 # Note: this adds commits containing the current manpages in roff and
270 # html format to the man and html branches respectively.  The version
271 # is determined by "git describe --always".
272 .PHONY: update-doc-branches
273 update-doc-branches: Documentation/all
274         dev/update-doc-branches refs/heads/man refs/heads/html
275
276 # push the pregenerated doc files to origin/man and origin/html
277 push-docs: export-docs
278         git push origin man html
279
280 # import pregenerated doc files from origin/man and origin/html, in case you
281 # don't have pandoc but still want to be able to install the docs.
282 import-docs: Documentation/clean
283         $(pf); git archive origin/html | (cd Documentation && tar -xvf -)
284         $(pf); git archive origin/man | (cd Documentation && tar -xvf -)
285
286 clean: Documentation/clean
287         cd config && rm -rf finished bin config.var
288         cd config && rm -f \
289           ${CONFIGURE_DETRITUS} ${CONFIGURE_FILES} ${GENERATED_FILES}
290         rm -rf $(clean_paths) .pytest_cache
291         rm -f $(generated_dependencies)
292         find . -name __pycache__ -exec rm -rf {} +
293         if test -e test/mnt; then dev/cleanup-mounts-under test/mnt; fi
294         if test -e test/mnt; then rm -r test/mnt; fi
295         if test -e test/tmp; then dev/cleanup-mounts-under test/tmp; fi
296         # FIXME: migrate these to test/mnt/
297         if test -e test/int/testfs; \
298           then umount test/int/testfs || true; fi
299         rm -rf test/int/testfs test/int/testfs.img testfs.img
300         if test -e test/tmp; then dev/force-delete test/tmp; fi
301         dev/configure-sampledata --clean