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