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