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