]> arthur.barton.de Git - bup.git/blob - Makefile
Makefile: fix tests with bash and pipefail
[bup.git] / Makefile
1
2 SHELL := bash
3 pf := set -o pipefail
4
5 sampledata_rev := $(shell t/configure-sampledata --revision)
6 current_sampledata := t/sampledata/var/rev/v$(sampledata_rev)
7
8 OS:=$(shell uname | sed 's/[-_].*//')
9 CFLAGS := -Wall -O2 -Werror -Wno-unknown-pragmas $(PYINCLUDE) $(CFLAGS)
10 CFLAGS := -D_FILE_OFFSET_BITS=64 $(CFLAGS)
11 SOEXT:=.so
12
13 ifeq ($(OS),CYGWIN)
14   SOEXT:=.dll
15 endif
16
17 ifdef TMPDIR
18   test_tmp := $(TMPDIR)
19 else
20   test_tmp := $(CURDIR)/t/tmp
21 endif
22
23 initial_setup := $(shell ./configure-version --update)
24 bup_deps := bup lib/bup/_version.py lib/bup/_helpers$(SOEXT) cmds
25
26 all: $(bup_deps) Documentation/all $(current_sampledata)
27
28 bup:
29         ln -s main.py bup
30
31 Documentation/all: $(bup_deps)
32
33 $(current_sampledata):
34         t/configure-sampledata --setup
35
36 PYTHON = $(shell cmd/bup-python -c 'import sys; print sys.executable')
37
38 define install-python-bin
39   set -e; \
40   sed -e '1 s|.*|#!$(PYTHON)|; 2,/^# end of bup preamble$$/d' $1 > $2; \
41   chmod 0755 $2;
42 endef
43
44 INSTALL=install
45 PREFIX=/usr
46 MANDIR=$(DESTDIR)$(PREFIX)/share/man
47 DOCDIR=$(DESTDIR)$(PREFIX)/share/doc/bup
48 BINDIR=$(DESTDIR)$(PREFIX)/bin
49 LIBDIR=$(DESTDIR)$(PREFIX)/lib/bup
50 install: all
51         $(INSTALL) -d $(MANDIR)/man1 $(DOCDIR) $(BINDIR) \
52                 $(LIBDIR)/bup $(LIBDIR)/cmd \
53                 $(LIBDIR)/web $(LIBDIR)/web/static
54         [ ! -e Documentation/.docs-available ] || \
55           $(INSTALL) -m 0644 \
56                 Documentation/*.1 \
57                 $(MANDIR)/man1
58         [ ! -e Documentation/.docs-available ] || \
59           $(INSTALL) -m 0644 \
60                 Documentation/*.html \
61                 $(DOCDIR)
62         $(call install-python-bin,bup,"$(BINDIR)/bup")
63         set -e; \
64         for cmd in $$(ls cmd/bup-* | grep -v cmd/bup-python); do \
65           $(call install-python-bin,"$$cmd","$(LIBDIR)/$$cmd") \
66         done
67         $(INSTALL) -pm 0644 \
68                 lib/bup/*.py \
69                 $(LIBDIR)/bup
70         $(INSTALL) -pm 0755 \
71                 lib/bup/*$(SOEXT) \
72                 $(LIBDIR)/bup
73         $(INSTALL) -pm 0644 \
74                 lib/web/static/* \
75                 $(LIBDIR)/web/static/
76         $(INSTALL) -pm 0644 \
77                 lib/web/*.html \
78                 $(LIBDIR)/web/
79 %/all:
80         $(MAKE) -C $* all
81
82 %/clean:
83         $(MAKE) -C $* clean
84
85 config/config.h: config/Makefile config/configure config/configure.inc \
86                 $(wildcard config/*.in)
87         cd config && $(MAKE) config.h
88
89 lib/bup/_helpers$(SOEXT): \
90                 config/config.h \
91                 lib/bup/bupsplit.c lib/bup/_helpers.c lib/bup/csetup.py
92         @rm -f $@
93         cd lib/bup && \
94         LDFLAGS="$(LDFLAGS)" CFLAGS="$(CFLAGS)" $(PYTHON) csetup.py build
95         cp lib/bup/build/*/_helpers$(SOEXT) lib/bup/
96
97 lib/bup/_version.py:
98         @echo "Something has gone wrong; $@ should already exist."
99         @echo 'Check "./configure-version --update"'
100         @false
101
102 t/tmp:
103         mkdir t/tmp
104
105 runtests: runtests-python runtests-cmdline
106
107 runtests-python: all t/tmp
108         $(pf); TMPDIR="$(test_tmp)" \
109           $(PYTHON) wvtest.py t/t*.py lib/*/t/t*.py 2>&1 \
110             | tee -a t/tmp/test-log/$$$$.log
111
112 cmdline_tests := \
113   t/test-index.sh \
114   t/test-split-join.sh \
115   t/test-fuse.sh \
116   t/test-drecurse.sh \
117   t/test-cat-file.sh \
118   t/test-compression.sh \
119   t/test-fsck.sh \
120   t/test-index-clear.sh \
121   t/test-index-check-device.sh \
122   t/test-ls.sh \
123   t/test-tz.sh \
124   t/test-meta.sh \
125   t/test-on.sh \
126   t/test-restore-map-owner.sh \
127   t/test-restore-single-file.sh \
128   t/test-rm-between-index-and-save.sh \
129   t/test-sparse-files.sh \
130   t/test-command-without-init-fails.sh \
131   t/test-redundant-saves.sh \
132   t/test-save-creates-no-unrefs.sh \
133   t/test-save-restore-excludes.sh \
134   t/test-save-strip-graft.sh \
135   t/test-import-duplicity.sh \
136   t/test-import-rdiff-backup.sh \
137   t/test-xdev.sh \
138   t/test.sh
139
140 # For parallel runs.
141 tmp-target-run-test%: all t/tmp
142         $(pf); TMPDIR="$(test_tmp)" \
143           t/test$* 2>&1 | tee -a t/tmp/test-log/$$$$.log
144
145 runtests-cmdline: $(subst t/test,tmp-target-run-test,$(cmdline_tests))
146
147 stupid:
148         PATH=/bin:/usr/bin $(MAKE) test
149
150 test: all
151         if test -e t/tmp/test-log; then rm -r t/tmp/test-log; fi
152         mkdir -p t/tmp/test-log
153         ./wvtest watch --no-counts \
154           $(MAKE) PYTHON=$(PYTHON) runtests-python runtests-cmdline
155         ./wvtest report t/tmp/test-log/*.log
156
157 check: test
158
159 cmd/python-cmd.sh: config/configure config/configure.inc
160         ./configure
161
162 cmds: \
163     $(patsubst cmd/%-cmd.py,cmd/bup-%,$(wildcard cmd/*-cmd.py)) \
164     $(patsubst cmd/%-cmd.sh,cmd/bup-%,$(wildcard cmd/*-cmd.sh))
165
166 cmd/bup-%: cmd/%-cmd.py
167         rm -f $@
168         ln -s $*-cmd.py $@
169
170 cmd/bup-%: cmd/%-cmd.sh
171         rm -f $@
172         ln -s $*-cmd.sh $@
173
174 # update the local 'man' and 'html' branches with pregenerated output files, for
175 # people who don't have pandoc (and maybe to aid in google searches or something)
176 export-docs: Documentation/all
177         git update-ref refs/heads/man origin/man '' 2>/dev/null || true
178         git update-ref refs/heads/html origin/html '' 2>/dev/null || true
179         set -eo pipefail; \
180         GIT_INDEX_FILE=gitindex.tmp; export GIT_INDEX_FILE; \
181         rm -f $${GIT_INDEX_FILE} && \
182         git add -f Documentation/*.1 && \
183         git update-ref refs/heads/man \
184                 $$(echo "Autogenerated man pages for $$(git describe --always)" \
185                     | git commit-tree $$(git write-tree --prefix=Documentation) \
186                                 -p refs/heads/man) && \
187         rm -f $${GIT_INDEX_FILE} && \
188         git add -f Documentation/*.html && \
189         git update-ref refs/heads/html \
190                 $$(echo "Autogenerated html pages for $$(git describe --always)" \
191                     | git commit-tree $$(git write-tree --prefix=Documentation) \
192                                 -p refs/heads/html)
193
194 # push the pregenerated doc files to origin/man and origin/html
195 push-docs: export-docs
196         git push origin man html
197
198 # import pregenerated doc files from origin/man and origin/html, in case you
199 # don't have pandoc but still want to be able to install the docs.
200 import-docs: Documentation/clean
201         $(pf); git archive origin/html | (cd Documentation && tar -xvf -)
202         $(pf); git archive origin/man | (cd Documentation && tar -xvf -)
203
204 clean: Documentation/clean config/clean
205         rm -f *.o lib/*/*.o *.so lib/*/*.so *.dll lib/*/*.dll *.exe \
206                 .*~ *~ */*~ lib/*/*~ lib/*/*/*~ \
207                 *.pyc */*.pyc lib/*/*.pyc lib/*/*/*.pyc \
208                 bup bup-* cmd/bup-* \
209                 cmd/python-cmd.sh \
210                 randomgen memtest \
211                 testfs.img lib/bup/t/testfs.img
212         if test -e t/mnt; then t/cleanup-mounts-under t/mnt; fi
213         if test -e t/mnt; then rm -r t/mnt; fi
214         if test -e t/tmp; then t/cleanup-mounts-under t/tmp; fi
215         # FIXME: migrate these to t/mnt/
216         if test -e lib/bup/t/testfs; \
217           then umount lib/bup/t/testfs || true; fi
218         rm -rf *.tmp *.tmp.meta t/*.tmp lib/*/*/*.tmp build lib/bup/build lib/bup/t/testfs
219         if test -e t/tmp; then t/force-delete t/tmp; fi
220         ./configure-version --clean
221         t/configure-sampledata --clean