]> arthur.barton.de Git - bup.git/blob - Makefile
Stop forcing LC_CTYPE=ISO-8859-1
[bup.git] / Makefile
1
2 SHELL := bash
3 .DEFAULT_GOAL := all
4
5 # See config/config.vars.in (sets bup_python, among other things)
6 include config/config.vars
7
8 pf := set -o pipefail
9
10 define isok
11   && echo " ok" || echo " no"
12 endef
13
14 # If ok, strip trailing " ok" and return the output, otherwise, error
15 define shout
16 $(if $(subst ok,,$(lastword $(1))),$(error $(2)),$(shell x="$(1)"; echo $${x%???}))
17 endef
18
19 sampledata_rev := $(shell t/configure-sampledata --revision $(isok))
20 sampledata_rev := \
21   $(call shout,$(sampledata_rev),Could not parse sampledata revision)
22
23 current_sampledata := t/sampledata/var/rev/v$(sampledata_rev)
24
25 os := $(shell ($(pf); uname | sed 's/[-_].*//') $(isok))
26 os := $(call shout,$(os),Unable to determine OS)
27
28 CFLAGS := -Wall -O2 -Werror -Wno-unknown-pragmas $(PYINCLUDE) $(CFLAGS)
29 CFLAGS := -D_FILE_OFFSET_BITS=64 $(CFLAGS)
30 SOEXT:=.so
31
32 ifeq ($(os),CYGWIN)
33   SOEXT:=.dll
34 endif
35
36 ifdef TMPDIR
37   test_tmp := $(TMPDIR)
38 else
39   test_tmp := $(CURDIR)/t/tmp
40 endif
41
42 initial_setup := $(shell ./configure-version --update $(isok))
43 initial_setup := $(call shout,$(initial_setup),Version configuration failed))
44
45 config/config.vars: configure config/configure config/configure.inc \
46   $(wildcard config/*.in)
47         MAKE="$(MAKE)" ./configure
48
49 # On some platforms, Python.h and readline.h fight over the
50 # _XOPEN_SOURCE version, i.e. -Werror crashes on a mismatch, so for
51 # now, we're just going to let Python's version win.
52 readline_cflags += $(shell pkg-config readline --cflags)
53 readline_xopen := $(filter -D_XOPEN_SOURCE=%,$(readline_cflags))
54 readline_xopen := $(subst -D_XOPEN_SOURCE=,,$(readline_xopen))
55 ifneq ($(readline_xopen),600)
56   $(error "Unexpected pkg-config readline _XOPEN_SOURCE --cflags $(readline_cflags)")
57 endif
58 readline_cflags := $(filter-out -D_XOPEN_SOURCE=%,$(readline_cflags))
59 readline_cflags += $(addprefix -DBUP_RL_EXPECTED_XOPEN_SOURCE=,$(readline_xopen))
60
61 CFLAGS += $(readline_cflags)
62 LDFLAGS += $(shell pkg-config readline --libs)
63
64 bup_cmds := cmd/bup-python \
65   $(patsubst cmd/%-cmd.py,cmd/bup-%,$(wildcard cmd/*-cmd.py)) \
66   $(patsubst cmd/%-cmd.sh,cmd/bup-%,$(wildcard cmd/*-cmd.sh))
67
68 bup_deps := lib/bup/_checkout.py lib/bup/_helpers$(SOEXT) $(bup_cmds)
69
70 all: $(bup_deps) Documentation/all $(current_sampledata)
71
72 $(current_sampledata):
73         t/configure-sampledata --setup
74
75 PANDOC ?= $(shell type -p pandoc)
76
77 ifeq (,$(PANDOC))
78   $(shell echo "Warning: pandoc not found; skipping manpage generation" 1>&2)
79   man_md :=
80 else
81   man_md := $(wildcard Documentation/*.md)
82 endif
83
84 man_roff := $(patsubst %.md,%.1,$(man_md))
85 man_html := $(patsubst %.md,%.html,$(man_md))
86
87 INSTALL=install
88 PREFIX=/usr/local
89 MANDIR=$(PREFIX)/share/man
90 DOCDIR=$(PREFIX)/share/doc/bup
91 BINDIR=$(PREFIX)/bin
92 LIBDIR=$(PREFIX)/lib/bup
93
94 dest_mandir := $(DESTDIR)$(MANDIR)
95 dest_docdir := $(DESTDIR)$(DOCDIR)
96 dest_bindir := $(DESTDIR)$(BINDIR)
97 dest_libdir := $(DESTDIR)$(LIBDIR)
98
99 install: all
100         $(INSTALL) -d $(dest_bindir) \
101                 $(dest_libdir)/bup $(dest_libdir)/cmd \
102                 $(dest_libdir)/web $(dest_libdir)/web/static
103         test -z "$(man_roff)" || install -d $(dest_mandir)/man1
104         test -z "$(man_roff)" || $(INSTALL) -m 0644 $(man_roff) $(dest_mandir)/man1
105         test -z "$(man_html)" || install -d $(dest_docdir)
106         test -z "$(man_html)" || $(INSTALL) -m 0644 $(man_html) $(dest_docdir)
107         dev/install-python-script lib/cmd/bup "$(dest_libdir)/cmd/bup"
108         set -e; \
109         for cmd in $$(ls cmd/bup-* | grep -v cmd/bup-python); do \
110           dev/install-python-script "$$cmd" "$(dest_libdir)/$$cmd"; \
111         done
112         cd "$(dest_bindir)" && \
113           ln -sf "$$($(bup_python) -c 'import os; print(os.path.relpath("$(abspath $(dest_libdir))/cmd/bup"))')"
114         set -e; \
115         $(INSTALL) -pm 0644 \
116                 lib/bup/*.py \
117                 $(dest_libdir)/bup
118         $(INSTALL) -pm 0755 \
119                 lib/bup/*$(SOEXT) \
120                 $(dest_libdir)/bup
121         $(INSTALL) -pm 0644 \
122                 lib/web/static/* \
123                 $(dest_libdir)/web/static/
124         $(INSTALL) -pm 0644 \
125                 lib/web/*.html \
126                 $(dest_libdir)/web/
127
128 config/config.h: config/config.vars
129
130 lib/bup/_helpers$(SOEXT): \
131                 config/config.h lib/bup/bupsplit.h \
132                 lib/bup/bupsplit.c lib/bup/_helpers.c lib/bup/csetup.py
133         @rm -f $@
134         cd lib/bup && $(bup_python) csetup.py build "$(CFLAGS)" "$(LDFLAGS)"
135         # Make sure there's just the one file we expect before we copy it.
136         "$(bup_python)" -c \
137           "import glob; assert(len(glob.glob('lib/bup/build/*/_helpers*$(SOEXT)')) == 1)"
138         cp lib/bup/build/*/_helpers*$(SOEXT) "$@"
139
140 lib/bup/_checkout.py:
141         @if grep -F '$Format' lib/bup/_release.py \
142             && ! test -e lib/bup/_checkout.py; then \
143           echo "Something has gone wrong; $@ should already exist."; \
144           echo 'Check "./configure-version --update"'; \
145           false; \
146         fi
147
148 t/tmp:
149         mkdir t/tmp
150
151 runtests: runtests-python runtests-cmdline
152
153 python_tests := \
154   lib/bup/t/tbloom.py \
155   lib/bup/t/tclient.py \
156   lib/bup/t/tgit.py \
157   lib/bup/t/thashsplit.py \
158   lib/bup/t/thelpers.py \
159   lib/bup/t/tindex.py \
160   lib/bup/t/tmetadata.py \
161   lib/bup/t/toptions.py \
162   lib/bup/t/tresolve.py \
163   lib/bup/t/tshquote.py \
164   lib/bup/t/tvfs.py \
165   lib/bup/t/tvint.py \
166   lib/bup/t/txstat.py
167
168 # The "pwd -P" here may not be appropriate in the long run, but we
169 # need it until we settle the relevant drecurse/exclusion questions:
170 # https://groups.google.com/forum/#!topic/bup-list/9ke-Mbp10Q0
171 runtests-python: all t/tmp
172         mkdir -p t/tmp/test-log
173         $(pf); cd $$(pwd -P); TMPDIR="$(test_tmp)" \
174           ./wvtest.py  $(python_tests) 2>&1 \
175             | tee -a t/tmp/test-log/$$$$.log
176
177 cmdline_tests := \
178   t/test.sh \
179   t/test-argv \
180   t/test-cat-file.sh \
181   t/test-command-without-init-fails.sh \
182   t/test-compression.sh \
183   t/test-drecurse.sh \
184   t/test-fsck.sh \
185   t/test-fuse.sh \
186   t/test-ftp \
187   t/test-web.sh \
188   t/test-gc.sh \
189   t/test-import-duplicity.sh \
190   t/test-import-rdiff-backup.sh \
191   t/test-index.sh \
192   t/test-index-check-device.sh \
193   t/test-index-clear.sh \
194   t/test-list-idx.sh \
195   t/test-ls \
196   t/test-ls-remote \
197   t/test-main.sh \
198   t/test-meta.sh \
199   t/test-on.sh \
200   t/test-packsizelimit \
201   t/test-prune-older \
202   t/test-redundant-saves.sh \
203   t/test-restore-map-owner.sh \
204   t/test-restore-single-file.sh \
205   t/test-rm.sh \
206   t/test-rm-between-index-and-save.sh \
207   t/test-save-creates-no-unrefs.sh \
208   t/test-save-restore \
209   t/test-save-errors \
210   t/test-save-restore-excludes.sh \
211   t/test-save-strip-graft.sh \
212   t/test-save-with-valid-parent.sh \
213   t/test-sparse-files.sh \
214   t/test-split-join.sh \
215   t/test-tz.sh \
216   t/test-xdev.sh
217
218 tmp-target-run-test-get-%: all t/tmp
219         $(pf); cd $$(pwd -P); TMPDIR="$(test_tmp)" \
220           t/test-get $* 2>&1 | tee -a t/tmp/test-log/$$$$.log
221
222 test_get_targets += \
223   tmp-target-run-test-get-replace \
224   tmp-target-run-test-get-universal \
225   tmp-target-run-test-get-ff \
226   tmp-target-run-test-get-append \
227   tmp-target-run-test-get-pick \
228   tmp-target-run-test-get-new-tag \
229   tmp-target-run-test-get-unnamed
230
231 # For parallel runs.
232 # The "pwd -P" here may not be appropriate in the long run, but we
233 # need it until we settle the relevant drecurse/exclusion questions:
234 # https://groups.google.com/forum/#!topic/bup-list/9ke-Mbp10Q0
235 tmp-target-run-test%: all t/tmp
236         $(pf); cd $$(pwd -P); TMPDIR="$(test_tmp)" \
237           t/test$* 2>&1 | tee -a t/tmp/test-log/$$$$.log
238
239 runtests-cmdline: $(test_get_targets) $(subst t/test,tmp-target-run-test,$(cmdline_tests))
240
241 stupid:
242         PATH=/bin:/usr/bin $(MAKE) test
243
244 test: all
245         if test -e t/tmp/test-log; then rm -r t/tmp/test-log; fi
246         mkdir -p t/tmp/test-log
247         ./wvtest watch --no-counts \
248           $(MAKE) runtests 2>t/tmp/test-log/$$$$.log
249         ./wvtest report t/tmp/test-log/*.log
250
251 check: test
252
253 distcheck: all
254         ./wvtest run t/test-release-archive.sh
255
256 cmd/bup-python: config/config.var/bup-python
257         cd cmd && ln -sf "$$(< $(CURDIR)/config/config.var/bup-python)" bup-python
258
259 long-test: export BUP_TEST_LEVEL=11
260 long-test: test
261
262 long-check: export BUP_TEST_LEVEL=11
263 long-check: check
264
265 .PHONY: check-both
266 check-both:
267         $(MAKE) clean \
268           && PYTHON=python3 BUP_ALLOW_UNEXPECTED_PYTHON_VERSION=true $(MAKE) check
269         $(MAKE) clean \
270           && PYTHON=python2 $(MAKE) check
271
272 cmd/bup-%: cmd/%-cmd.py
273         rm -f $@
274         ln -s $*-cmd.py $@
275
276 cmd/bup-%: cmd/%-cmd.sh
277         rm -f $@
278         ln -s $*-cmd.sh $@
279
280 .PHONY: Documentation/all
281 Documentation/all: $(man_roff) $(man_html)
282
283 Documentation/substvars: $(bup_deps)
284         echo "s,%BUP_VERSION%,$$(./bup version --tag),g" > $@
285         echo "s,%BUP_DATE%,$$(./bup version --date),g" >> $@
286
287 Documentation/%.1: Documentation/%.md Documentation/substvars
288         $(pf); sed -f Documentation/substvars $< \
289           | $(PANDOC) -s -r markdown -w man -o $@
290
291 Documentation/%.html: Documentation/%.md Documentation/substvars
292         $(pf); sed -f Documentation/substvars $< \
293           | $(PANDOC) -s -r markdown -w html -o $@
294
295 .PHONY: Documentation/clean
296 Documentation/clean:
297         cd Documentation && rm -f *~ .*~ *.[0-9] *.html substvars
298
299 # Note: this adds commits containing the current manpages in roff and
300 # html format to the man and html branches respectively.  The version
301 # is determined by "git describe --always".
302 .PHONY: update-doc-branches
303 update-doc-branches: Documentation/all
304         dev/update-doc-branches refs/heads/man refs/heads/html
305
306 # push the pregenerated doc files to origin/man and origin/html
307 push-docs: export-docs
308         git push origin man html
309
310 # import pregenerated doc files from origin/man and origin/html, in case you
311 # don't have pandoc but still want to be able to install the docs.
312 import-docs: Documentation/clean
313         $(pf); git archive origin/html | (cd Documentation && tar -xvf -)
314         $(pf); git archive origin/man | (cd Documentation && tar -xvf -)
315
316 clean: Documentation/clean cmd/bup-python
317         cd config && rm -f *~ .*~ \
318           ${CONFIGURE_DETRITUS} ${CONFIGURE_FILES} ${GENERATED_FILES}
319         cd config && rm -rf config.var
320         rm -f *.o lib/*/*.o *.so lib/*/*.so *.dll lib/*/*.dll *.exe \
321                 .*~ *~ */*~ lib/*/*~ lib/*/*/*~ \
322                 *.pyc */*.pyc lib/*/*.pyc lib/*/*/*.pyc \
323                 randomgen memtest \
324                 testfs.img lib/bup/t/testfs.img
325         for x in $$(ls cmd/*-cmd.py cmd/*-cmd.sh | grep -vF python-cmd.sh | cut -b 5-); do \
326             echo "cmd/bup-$${x%-cmd.*}"; \
327         done | xargs -t rm -f
328         if test -e t/mnt; then t/cleanup-mounts-under t/mnt; fi
329         if test -e t/mnt; then rm -r t/mnt; fi
330         if test -e t/tmp; then t/cleanup-mounts-under t/tmp; fi
331         # FIXME: migrate these to t/mnt/
332         if test -e lib/bup/t/testfs; \
333           then umount lib/bup/t/testfs || true; fi
334         rm -rf *.tmp *.tmp.meta t/*.tmp lib/*/*/*.tmp build lib/bup/build lib/bup/t/testfs
335         if test -e t/tmp; then t/force-delete t/tmp; fi
336         ./configure-version --clean
337         t/configure-sampledata --clean
338         # Remove last so that cleanup tools can depend on it
339         rm -f cmd/bup-python