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