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