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