]> arthur.barton.de Git - bup.git/blob - Makefile
Generate bup-python from Makefile not configure
[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         ./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/_version.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 Documentation/all: $(bup_deps)
61
62 $(current_sampledata):
63         t/configure-sampledata --setup
64
65 define install-python-bin
66   set -e; \
67   sed -e '1 s|.*|#!$(bup_python)|; 2,/^# end of bup preamble$$/d' $1 > $2; \
68   chmod 0755 $2;
69 endef
70
71 INSTALL=install
72 PREFIX=/usr
73 MANDIR=$(DESTDIR)$(PREFIX)/share/man
74 DOCDIR=$(DESTDIR)$(PREFIX)/share/doc/bup
75 BINDIR=$(DESTDIR)$(PREFIX)/bin
76 LIBDIR=$(DESTDIR)$(PREFIX)/lib/bup
77 install: all
78         $(INSTALL) -d $(MANDIR)/man1 $(DOCDIR) $(BINDIR) \
79                 $(LIBDIR)/bup $(LIBDIR)/cmd \
80                 $(LIBDIR)/web $(LIBDIR)/web/static
81         [ ! -e Documentation/.docs-available ] || \
82           $(INSTALL) -m 0644 \
83                 Documentation/*.1 \
84                 $(MANDIR)/man1
85         [ ! -e Documentation/.docs-available ] || \
86           $(INSTALL) -m 0644 \
87                 Documentation/*.html \
88                 $(DOCDIR)
89         $(call install-python-bin,bup,"$(BINDIR)/bup")
90         set -e; \
91         for cmd in $$(ls cmd/bup-* | grep -v cmd/bup-python); do \
92           $(call install-python-bin,"$$cmd","$(LIBDIR)/$$cmd") \
93         done
94         $(INSTALL) -pm 0644 \
95                 lib/bup/*.py \
96                 $(LIBDIR)/bup
97         $(INSTALL) -pm 0755 \
98                 lib/bup/*$(SOEXT) \
99                 $(LIBDIR)/bup
100         $(INSTALL) -pm 0644 \
101                 lib/web/static/* \
102                 $(LIBDIR)/web/static/
103         $(INSTALL) -pm 0644 \
104                 lib/web/*.html \
105                 $(LIBDIR)/web/
106 %/all:
107         $(MAKE) -C $* all
108
109 %/clean:
110         $(MAKE) -C $* clean
111
112 config/config.h: config/config.vars
113
114 lib/bup/_helpers$(SOEXT): \
115                 config/config.h \
116                 lib/bup/bupsplit.c lib/bup/_helpers.c lib/bup/csetup.py
117         @rm -f $@
118         cd lib/bup && \
119         LDFLAGS="$(LDFLAGS)" CFLAGS="$(CFLAGS)" "$(bup_python)" csetup.py build
120         cp lib/bup/build/*/_helpers$(SOEXT) lib/bup/
121
122 lib/bup/_version.py:
123         @echo "Something has gone wrong; $@ should already exist."
124         @echo 'Check "./configure-version --update"'
125         @false
126
127 t/tmp:
128         mkdir t/tmp
129
130 runtests: runtests-python runtests-cmdline
131
132 # The "pwd -P" here may not be appropriate in the long run, but we
133 # need it until we settle the relevant drecurse/exclusion questions:
134 # https://groups.google.com/forum/#!topic/bup-list/9ke-Mbp10Q0
135 runtests-python: all t/tmp
136         $(pf); cd $$(pwd -P); TMPDIR="$(test_tmp)" \
137           "$(bup_python)" wvtest.py t/t*.py lib/*/t/t*.py 2>&1 \
138             | tee -a t/tmp/test-log/$$$$.log
139
140 cmdline_tests := \
141   t/test-index.sh \
142   t/test-split-join.sh \
143   t/test-fuse.sh \
144   t/test-drecurse.sh \
145   t/test-cat-file.sh \
146   t/test-compression.sh \
147   t/test-fsck.sh \
148   t/test-index-clear.sh \
149   t/test-index-check-device.sh \
150   t/test-ls.sh \
151   t/test-tz.sh \
152   t/test-meta.sh \
153   t/test-on.sh \
154   t/test-restore-map-owner.sh \
155   t/test-restore-single-file.sh \
156   t/test-rm-between-index-and-save.sh \
157   t/test-sparse-files.sh \
158   t/test-command-without-init-fails.sh \
159   t/test-redundant-saves.sh \
160   t/test-save-creates-no-unrefs.sh \
161   t/test-save-restore-excludes.sh \
162   t/test-save-strip-graft.sh \
163   t/test-import-duplicity.sh \
164   t/test-import-rdiff-backup.sh \
165   t/test-xdev.sh \
166   t/test.sh
167
168 # For parallel runs.
169 # The "pwd -P" here may not be appropriate in the long run, but we
170 # need it until we settle the relevant drecurse/exclusion questions:
171 # https://groups.google.com/forum/#!topic/bup-list/9ke-Mbp10Q0
172 tmp-target-run-test%: all t/tmp
173         $(pf); cd $$(pwd -P); TMPDIR="$(test_tmp)" \
174           t/test$* 2>&1 | tee -a t/tmp/test-log/$$$$.log
175
176 runtests-cmdline: $(subst t/test,tmp-target-run-test,$(cmdline_tests))
177
178 stupid:
179         PATH=/bin:/usr/bin $(MAKE) test
180
181 test: all
182         if test -e t/tmp/test-log; then rm -r t/tmp/test-log; fi
183         mkdir -p t/tmp/test-log
184         ./wvtest watch --no-counts $(MAKE) runtests-python runtests-cmdline
185         ./wvtest report t/tmp/test-log/*.log
186
187 check: test
188
189 cmd/python-cmd.sh: config/config.vars Makefile
190         printf "#!/bin/sh\nexec %q \"\$$@\"" "$(bup_python)" \
191           >> cmd/python-cmd.sh.$$PPID.tmp
192         chmod u+x cmd/python-cmd.sh.$$PPID.tmp
193         mv cmd/python-cmd.sh.$$PPID.tmp cmd/python-cmd.sh
194
195 cmd/bup-%: cmd/%-cmd.py
196         rm -f $@
197         ln -s $*-cmd.py $@
198
199 cmd/bup-%: cmd/%-cmd.sh
200         rm -f $@
201         ln -s $*-cmd.sh $@
202
203 # update the local 'man' and 'html' branches with pregenerated output files, for
204 # people who don't have pandoc (and maybe to aid in google searches or something)
205 export-docs: Documentation/all
206         git update-ref refs/heads/man origin/man '' 2>/dev/null || true
207         git update-ref refs/heads/html origin/html '' 2>/dev/null || true
208         set -eo pipefail; \
209         GIT_INDEX_FILE=gitindex.tmp; export GIT_INDEX_FILE; \
210         rm -f $${GIT_INDEX_FILE} && \
211         git add -f Documentation/*.1 && \
212         git update-ref refs/heads/man \
213                 $$(echo "Autogenerated man pages for $$(git describe --always)" \
214                     | git commit-tree $$(git write-tree --prefix=Documentation) \
215                                 -p refs/heads/man) && \
216         rm -f $${GIT_INDEX_FILE} && \
217         git add -f Documentation/*.html && \
218         git update-ref refs/heads/html \
219                 $$(echo "Autogenerated html pages for $$(git describe --always)" \
220                     | git commit-tree $$(git write-tree --prefix=Documentation) \
221                                 -p refs/heads/html)
222
223 # push the pregenerated doc files to origin/man and origin/html
224 push-docs: export-docs
225         git push origin man html
226
227 # import pregenerated doc files from origin/man and origin/html, in case you
228 # don't have pandoc but still want to be able to install the docs.
229 import-docs: Documentation/clean
230         $(pf); git archive origin/html | (cd Documentation && tar -xvf -)
231         $(pf); git archive origin/man | (cd Documentation && tar -xvf -)
232
233 clean: Documentation/clean config/clean
234         rm -f *.o lib/*/*.o *.so lib/*/*.so *.dll lib/*/*.dll *.exe \
235                 .*~ *~ */*~ lib/*/*~ lib/*/*/*~ \
236                 *.pyc */*.pyc lib/*/*.pyc lib/*/*/*.pyc \
237                 bup bup-* cmd/bup-* \
238                 cmd/python-cmd.sh \
239                 randomgen memtest \
240                 testfs.img lib/bup/t/testfs.img
241         if test -e t/mnt; then t/cleanup-mounts-under t/mnt; fi
242         if test -e t/mnt; then rm -r t/mnt; fi
243         if test -e t/tmp; then t/cleanup-mounts-under t/tmp; fi
244         # FIXME: migrate these to t/mnt/
245         if test -e lib/bup/t/testfs; \
246           then umount lib/bup/t/testfs || true; fi
247         rm -rf *.tmp *.tmp.meta t/*.tmp lib/*/*/*.tmp build lib/bup/build lib/bup/t/testfs
248         if test -e t/tmp; then t/force-delete t/tmp; fi
249         ./configure-version --clean
250         t/configure-sampledata --clean