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