2 MAKEFLAGS += --warn-undefined-variables
7 # Guard against accidentally using/testing a local bup
8 export PATH := $(CURDIR)/dev/shadow-bin:$(PATH)
11 generated_dependencies :=
13 # See config/config.vars.in (sets bup_python_config, among other things)
14 include config/config.vars
15 -include $(generated_dependencies)
20 && echo " ok" || echo " no"
23 # If ok, strip trailing " ok" and return the output, otherwise, error
25 $(if $(subst ok,,$(lastword $(1))),$(error $(2)),$(shell x="$(1)"; echo $${x%???}))
28 sampledata_rev := $(shell dev/configure-sampledata --revision $(isok))
30 $(call shout,$(sampledata_rev),Could not parse sampledata revision)
32 current_sampledata := test/sampledata/var/rev/v$(sampledata_rev)
34 os := $(shell ($(pf); uname | sed 's/[-_].*//') $(isok))
35 os := $(call shout,$(os),Unable to determine OS)
37 # CFLAGS CPPFLAGS LDFLAGS are handled vis config/config.vars.in
39 # Satisfy --warn-undefined-variables
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)
58 test_tmp := $(CURDIR)/test/tmp
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
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
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.
73 helpers_cflags = $(bup_python_cflags) $(bup_shared_cflags) -I$(CURDIR)/src
74 helpers_ldflags := $(bup_python_ldflags) $(bup_shared_ldflags)
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)
85 helpers_ldflags += $(bup_readline_ldflags)
87 ifeq ($(bup_have_libacl),1)
88 helpers_cflags += $(bup_libacl_cflags)
89 helpers_ldflags += $(bup_libacl_ldflags)
92 bup_ext_cmds := lib/cmd/bup-import-rdiff-backup lib/cmd/bup-import-rsnapshot
94 bup_deps := lib/bup/_helpers$(soext) lib/cmd/bup
96 all: dev/bup-exec dev/bup-python dev/python $(bup_deps) Documentation/all \
99 $(current_sampledata):
100 dev/configure-sampledata --setup
102 PANDOC ?= $(shell type -p pandoc)
105 $(shell echo "Warning: pandoc not found; skipping manpage generation" 1>&2)
108 man_md := $(wildcard Documentation/*.md)
111 man_roff := $(patsubst %.md,%.1,$(man_md))
112 man_html := $(patsubst %.md,%.html,$(man_md))
116 MANDIR=$(PREFIX)/share/man
117 DOCDIR=$(PREFIX)/share/doc/bup
119 LIBDIR=$(PREFIX)/lib/bup
121 dest_mandir := $(DESTDIR)$(MANDIR)
122 dest_docdir := $(DESTDIR)$(DOCDIR)
123 dest_bindir := $(DESTDIR)$(BINDIR)
124 dest_libdir := $(DESTDIR)$(LIBDIR)
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"))')" \
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 \
144 $(INSTALL) -pm 0644 \
146 $(dest_libdir)/web/static/
147 $(INSTALL) -pm 0644 \
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; \
154 ! grep -qF '$$Format' lib/bup/source_info.py; \
155 $(INSTALL) -pm 0644 lib/bup/source_info.py $(dest_libdir)/bup/; \
158 embed_cflags = $(bup_python_cflags_embed) $(bup_shared_cflags) -I$(CURDIR)/src
159 embed_ldflags := $(bup_python_ldflags_embed) $(bup_shared_ldflags)
161 config/config.h: config/config.vars
162 clean_paths += config/config.h.tmp
164 cc_bin = $(CC) $(embed_cflags) -I src $(CPPFLAGS) $(CFLAGS) $^ \
165 $(embed_ldflags) $(LDFLAGS) -fPIE -o $@
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
173 clean_paths += dev/python
174 dev/python: dev/python-proposed
175 dev/validate-python $@-proposed
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
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
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
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 $@
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))
210 lint: dev/bup-exec dev/bup-python
213 test: all test/tmp dev/python lint
214 ! bup version # Ensure we can't test the local bup (cf. dev/shadow-bin)
216 if test yes = "$$(dev/python -c 'import xdist; print("yes")' 2>/dev/null)"; then \
217 (set -x; ./pytest $(xdist_opt);) \
219 (set -x; ./pytest;) \
223 PATH=/bin:/usr/bin $(MAKE) test
228 if test yes = $$(dev/python -c "import xdist; print('yes')" 2>/dev/null); then \
229 (set -x; ./pytest $(xdist_opt) -m release;) \
231 (set -x; ./pytest -m release;) \
234 long-test: export BUP_TEST_LEVEL=11
237 long-check: export BUP_TEST_LEVEL=11
242 $(MAKE) clean && BUP_PYTHON_CONFIG=python3-config $(MAKE) check
244 .PHONY: Documentation/all
245 Documentation/all: $(man_roff) $(man_html)
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
254 Documentation/%.1: Documentation/%.md Documentation/substvars
255 $(pf); sed -f Documentation/substvars $< \
256 | "$(PANDOC)" -s -r markdown -w man -o $@
258 Documentation/%.html: Documentation/%.md Documentation/substvars
259 $(pf); sed -f Documentation/substvars $< \
260 | "$(PANDOC)" -s -r markdown -w html -o $@
262 .PHONY: Documentation/clean
264 cd Documentation && rm -f *~ .*~ *.[0-9] *.html substvars
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
273 # push the pregenerated doc files to origin/man and origin/html
274 push-docs: export-docs
275 git push origin man html
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 -)
283 clean: Documentation/clean
284 cd config && rm -rf finished bin config.var
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
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