]> arthur.barton.de Git - bup.git/blob - GNUmakefile
Respect/prefer/remember user specified CPPFLAGS/CFLAGS/LDFLAGS
[bup.git] / GNUmakefile
1
2 MAKEFLAGS += --warn-undefined-variables
3
4 SHELL := bash
5 .DEFAULT_GOAL := all
6
7 clean_paths :=
8 generated_dependencies :=
9
10 # See config/config.vars.in (sets bup_python_config, among other things)
11 include config/config.vars
12 -include $(generated_dependencies)
13
14 pf := set -o pipefail
15
16 define isok
17   && echo " ok" || echo " no"
18 endef
19
20 # If ok, strip trailing " ok" and return the output, otherwise, error
21 define shout
22 $(if $(subst ok,,$(lastword $(1))),$(error $(2)),$(shell x="$(1)"; echo $${x%???}))
23 endef
24
25 sampledata_rev := $(shell dev/configure-sampledata --revision $(isok))
26 sampledata_rev := \
27   $(call shout,$(sampledata_rev),Could not parse sampledata revision)
28
29 current_sampledata := test/sampledata/var/rev/v$(sampledata_rev)
30
31 os := $(shell ($(pf); uname | sed 's/[-_].*//') $(isok))
32 os := $(call shout,$(os),Unable to determine OS)
33
34 # CFLAGS CPPFLAGS LDFLAGS are handled vis config/config.vars.in
35
36 # Satisfy --warn-undefined-variables
37 DESTDIR ?=
38 TARGET_ARCH ?=
39
40 bup_shared_cflags := -O2 -Wall -Werror -Wformat=2 -MMD -MP
41 bup_shared_cflags := -Wno-unknown-pragmas -Wsign-compare $(bup_shared_cflags)
42 bup_shared_cflags := -D_FILE_OFFSET_BITS=64 $(bup_shared_cflags)
43 bup_shared_cflags := $(bup_config_cflags) $(bup_shared_cflags)
44
45 bup_shared_ldflags :=
46
47 soext := .so
48 ifeq ($(os),CYGWIN)
49   soext := .dll
50 endif
51
52 ifdef TMPDIR
53   test_tmp := $(TMPDIR)
54 else
55   test_tmp := $(CURDIR)/test/tmp
56 endif
57
58 initial_setup := $(shell dev/update-checkout-info lib/bup/checkout_info.py $(isok))
59 initial_setup := $(call shout,$(initial_setup),update-checkout-info failed))
60 clean_paths += lib/bup/checkout_info.py
61
62 # Dependency changes here should be mirrored in Makefile
63 config/config.vars: configure config/configure config/configure.inc 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) -I$(CURDIR)/src
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 "$$($(CURDIR)/dev/python -c 'import os; print(os.path.relpath("$(abspath $(dest_libdir))/cmd/bup"))')" \
134             .
135         set -e; \
136         $(INSTALL) -pm 0644 lib/bup/*.py $(dest_libdir)/bup/
137         $(INSTALL) -pm 0644 lib/bup/cmd/*.py $(dest_libdir)/bup/cmd/
138         $(INSTALL) -pm 0755 \
139                 lib/bup/*$(soext) \
140                 $(dest_libdir)/bup
141         $(INSTALL) -pm 0644 \
142                 lib/web/static/* \
143                 $(dest_libdir)/web/static/
144         $(INSTALL) -pm 0644 \
145                 lib/web/*.html \
146                 $(dest_libdir)/web/
147         if test -e lib/bup/checkout_info.py; then \
148             $(INSTALL) -pm 0644 lib/bup/checkout_info.py \
149                 $(dest_libdir)/bup/source_info.py; \
150         else \
151             ! grep -qF '$$Format' lib/bup/source_info.py; \
152             $(INSTALL) -pm 0644 lib/bup/source_info.py $(dest_libdir)/bup/; \
153         fi
154
155 embed_cflags = $(bup_python_cflags_embed) $(bup_shared_cflags) -I$(CURDIR)/src
156 embed_ldflags := $(bup_python_ldflags_embed) $(bup_shared_ldflags)
157
158 config/config.h: config/config.vars
159 clean_paths += config/config.h.tmp
160
161 cc_bin = $(CC) $(embed_cflags) -I src $(CPPFLAGS) $(CFLAGS) $^ \
162   $(embed_ldflags) $(LDFLAGS) -fPIE -o $@
163
164 clean_paths += dev/python-proposed
165 generated_dependencies += dev/python-proposed.d
166 dev/python-proposed: dev/python.c src/bup/compat.c src/bup/io.c
167         rm -f dev/python
168         $(cc_bin)
169
170 clean_paths += dev/python
171 dev/python: dev/python-proposed
172         dev/validate-python $@-proposed
173         cp -a $@-proposed $@
174
175 clean_paths += dev/bup-exec
176 generated_dependencies += dev/bup-exec.d
177 dev/bup-exec: bup_shared_cflags += -D BUP_DEV_BUP_EXEC=1
178 dev/bup-exec: lib/cmd/bup.c src/bup/compat.c src/bup/io.c
179         $(cc_bin)
180
181 clean_paths += dev/bup-python
182 generated_dependencies += dev/bup-python.d
183 dev/bup-python: bup_shared_cflags += -D BUP_DEV_BUP_PYTHON=1
184 dev/bup-python: lib/cmd/bup.c src/bup/compat.c src/bup/io.c
185         $(cc_bin)
186
187 clean_paths += lib/cmd/bup
188 generated_dependencies += lib/cmd/bup.d
189 lib/cmd/bup: lib/cmd/bup.c src/bup/compat.c src/bup/io.c
190         $(cc_bin)
191
192 clean_paths += lib/bup/_helpers$(soext)
193 generated_dependencies += lib/bup/_helpers.d
194 lib/bup/_helpers$(soext): lib/bup/_helpers.c lib/bup/bupsplit.c
195         $(CC) $(helpers_cflags) $(CPPFLAGS) $(CFLAGS) $^ \
196           $(helpers_ldflags) $(LDFLAGS) -o $@
197
198 test/tmp:
199         mkdir test/tmp
200
201 # MAKEFLAGS must not be in an immediate := assignment
202 parallel_opt = $(lastword $(filter -j%,$(MAKEFLAGS)))
203 get_parallel_n = $(patsubst -j%,%,$(parallel_opt))
204 maybe_specific_n = $(if $(filter -j%,$(parallel_opt)),-n$(get_parallel_n))
205 xdist_opt = $(if $(filter -j,$(parallel_opt)),-nauto,$(maybe_specific_n))
206
207 lint: dev/bup-exec dev/bup-python
208         ./pylint
209
210 test: all test/tmp dev/python lint
211         ./bup features
212         if test yes = "$$(dev/python -c 'import xdist; print("yes")' 2>/dev/null)"; then \
213            (set -x; ./pytest $(xdist_opt);) \
214         else \
215           (set -x; ./pytest;) \
216         fi
217
218 stupid:
219         PATH=/bin:/usr/bin $(MAKE) test
220
221 check: test
222
223 distcheck: all
224         if test yes = $$(dev/python -c "import xdist; print('yes')" 2>/dev/null); then \
225           (set -x; ./pytest $(xdist_opt) -m release;) \
226         else \
227           (set -x; ./pytest -m release;) \
228         fi
229
230 long-test: export BUP_TEST_LEVEL=11
231 long-test: test
232
233 long-check: export BUP_TEST_LEVEL=11
234 long-check: check
235
236 .PHONY: check-py3
237 check-py3:
238         $(MAKE) clean && BUP_PYTHON_CONFIG=python3-config $(MAKE) check
239
240 .PHONY: Documentation/all
241 Documentation/all: $(man_roff) $(man_html)
242
243 Documentation/substvars: $(bup_deps)
244         # FIXME: real temp file
245         set -e; bup_ver=$$(./bup version); \
246         echo "s,%BUP_VERSION%,$$bup_ver,g" > $@.tmp; \
247         echo "s,%BUP_DATE%,$$bup_ver,g" >> $@.tmp
248         mv $@.tmp $@
249
250 Documentation/%.1: Documentation/%.md Documentation/substvars
251         $(pf); sed -f Documentation/substvars $< \
252           | "$(PANDOC)" -s -r markdown -w man -o $@
253
254 Documentation/%.html: Documentation/%.md Documentation/substvars
255         $(pf); sed -f Documentation/substvars $< \
256           | "$(PANDOC)" -s -r markdown -w html -o $@
257
258 .PHONY: Documentation/clean
259 Documentation/clean:
260         cd Documentation && rm -f *~ .*~ *.[0-9] *.html substvars
261
262 # Note: this adds commits containing the current manpages in roff and
263 # html format to the man and html branches respectively.  The version
264 # is determined by "git describe --always".
265 .PHONY: update-doc-branches
266 update-doc-branches: Documentation/all
267         dev/update-doc-branches refs/heads/man refs/heads/html
268
269 # push the pregenerated doc files to origin/man and origin/html
270 push-docs: export-docs
271         git push origin man html
272
273 # import pregenerated doc files from origin/man and origin/html, in case you
274 # don't have pandoc but still want to be able to install the docs.
275 import-docs: Documentation/clean
276         $(pf); git archive origin/html | (cd Documentation && tar -xvf -)
277         $(pf); git archive origin/man | (cd Documentation && tar -xvf -)
278
279 clean: Documentation/clean
280         cd config && rm -rf finished bin config.var
281
282         # Clean up the mounts first, so that find, etc. won't crash later
283         if test -e test/mnt; then dev/cleanup-mounts-under test/mnt; fi
284         if test -e test/mnt; then rm -r test/mnt; fi
285         if test -e test/tmp; then dev/cleanup-mounts-under test/tmp; fi
286         # FIXME: migrate these to test/mnt/
287         if test -e test/int/testfs; \
288           then umount test/int/testfs || true; fi
289         rm -rf test/int/testfs test/int/testfs.img testfs.img
290
291         cd config && rm -f \
292           ${CONFIGURE_DETRITUS} ${CONFIGURE_FILES} ${GENERATED_FILES}
293         rm -rf $(clean_paths) .pytest_cache
294         rm -f $(generated_dependencies)
295         find . -name __pycache__ -exec rm -rf {} +
296         if test -e test/tmp; then dev/force-delete test/tmp; fi
297         dev/configure-sampledata --clean