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