]> arthur.barton.de Git - bup.git/blob - Makefile
Merge web GET fix and SIGTERM and unix:// support
[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/_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 $(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         cp lib/bup/build/*/_helpers$(SOEXT) lib/bup/
128
129 lib/bup/_version.py:
130         @echo "Something has gone wrong; $@ should already exist."
131         @echo 'Check "./configure-version --update"'
132         @false
133
134 t/tmp:
135         mkdir t/tmp
136
137 runtests: runtests-python runtests-cmdline
138
139 # The "pwd -P" here may not be appropriate in the long run, but we
140 # need it until we settle the relevant drecurse/exclusion questions:
141 # https://groups.google.com/forum/#!topic/bup-list/9ke-Mbp10Q0
142 runtests-python: all t/tmp
143         $(pf); cd $$(pwd -P); TMPDIR="$(test_tmp)" \
144           "$(bup_python)" wvtest.py t/t*.py lib/*/t/t*.py 2>&1 \
145             | tee -a t/tmp/test-log/$$$$.log
146
147 cmdline_tests := \
148   t/test-web.sh \
149   t/test-rm.sh \
150   t/test-gc.sh \
151   t/test-main.sh \
152   t/test-list-idx.sh \
153   t/test-index.sh \
154   t/test-split-join.sh \
155   t/test-fuse.sh \
156   t/test-drecurse.sh \
157   t/test-cat-file.sh \
158   t/test-compression.sh \
159   t/test-fsck.sh \
160   t/test-index-clear.sh \
161   t/test-index-check-device.sh \
162   t/test-ls.sh \
163   t/test-tz.sh \
164   t/test-meta.sh \
165   t/test-on.sh \
166   t/test-restore-map-owner.sh \
167   t/test-restore-single-file.sh \
168   t/test-rm-between-index-and-save.sh \
169   t/test-save-with-valid-parent.sh \
170   t/test-sparse-files.sh \
171   t/test-command-without-init-fails.sh \
172   t/test-redundant-saves.sh \
173   t/test-save-creates-no-unrefs.sh \
174   t/test-save-restore-excludes.sh \
175   t/test-save-strip-graft.sh \
176   t/test-import-duplicity.sh \
177   t/test-import-rdiff-backup.sh \
178   t/test-xdev.sh \
179   t/test.sh
180
181 # For parallel runs.
182 # The "pwd -P" here may not be appropriate in the long run, but we
183 # need it until we settle the relevant drecurse/exclusion questions:
184 # https://groups.google.com/forum/#!topic/bup-list/9ke-Mbp10Q0
185 tmp-target-run-test%: all t/tmp
186         $(pf); cd $$(pwd -P); TMPDIR="$(test_tmp)" \
187           t/test$* 2>&1 | tee -a t/tmp/test-log/$$$$.log
188
189 runtests-cmdline: $(subst t/test,tmp-target-run-test,$(cmdline_tests))
190
191 stupid:
192         PATH=/bin:/usr/bin $(MAKE) test
193
194 test: all
195         if test -e t/tmp/test-log; then rm -r t/tmp/test-log; fi
196         mkdir -p t/tmp/test-log
197         ./wvtest watch --no-counts \
198           $(MAKE) runtests-python runtests-cmdline 2>t/tmp/test-log/$$$$.log
199         ./wvtest report t/tmp/test-log/*.log
200
201 check: test
202
203 cmd/python-cmd.sh: config/config.vars Makefile
204         printf "#!/bin/sh\nexec %q \"\$$@\"" "$(bup_python)" \
205           >> cmd/python-cmd.sh.$$PPID.tmp
206         chmod u+x cmd/python-cmd.sh.$$PPID.tmp
207         mv cmd/python-cmd.sh.$$PPID.tmp cmd/python-cmd.sh
208
209 cmd/bup-%: cmd/%-cmd.py
210         rm -f $@
211         ln -s $*-cmd.py $@
212
213 cmd/bup-%: cmd/%-cmd.sh
214         rm -f $@
215         ln -s $*-cmd.sh $@
216
217 .PHONY: Documentation/all
218 Documentation/all: $(man_roff) $(man_html)
219
220 Documentation/substvars: $(bup_deps)
221         echo "s,%BUP_VERSION%,$$(./bup version --tag),g" > $@
222         echo "s,%BUP_DATE%,$$(./bup version --date),g" >> $@
223
224 Documentation/%.1: Documentation/%.md Documentation/substvars
225         $(pf); sed -f Documentation/substvars $< \
226           | $(PANDOC) -s -r markdown -w man -o $@
227
228 Documentation/%.html: Documentation/%.md Documentation/substvars
229         $(pf); sed -f Documentation/substvars $< \
230           | $(PANDOC) -s -r markdown -w html -o $@
231
232 .PHONY: Documentation/clean
233 Documentation/clean:
234         cd Documentation && rm -f *~ .*~ *.[0-9] *.html substvars
235
236 # update the local 'man' and 'html' branches with pregenerated output files, for
237 # people who don't have pandoc (and maybe to aid in google searches or something)
238 export-docs: Documentation/all
239         git update-ref refs/heads/man origin/man '' 2>/dev/null || true
240         git update-ref refs/heads/html origin/html '' 2>/dev/null || true
241         set -eo pipefail; \
242         GIT_INDEX_FILE=gitindex.tmp; export GIT_INDEX_FILE; \
243         rm -f $${GIT_INDEX_FILE} && \
244         git add -f Documentation/*.1 && \
245         git update-ref refs/heads/man \
246                 $$(echo "Autogenerated man pages for $$(git describe --always)" \
247                     | git commit-tree $$(git write-tree --prefix=Documentation) \
248                                 -p refs/heads/man) && \
249         rm -f $${GIT_INDEX_FILE} && \
250         git add -f Documentation/*.html && \
251         git update-ref refs/heads/html \
252                 $$(echo "Autogenerated html pages for $$(git describe --always)" \
253                     | git commit-tree $$(git write-tree --prefix=Documentation) \
254                                 -p refs/heads/html)
255
256 # push the pregenerated doc files to origin/man and origin/html
257 push-docs: export-docs
258         git push origin man html
259
260 # import pregenerated doc files from origin/man and origin/html, in case you
261 # don't have pandoc but still want to be able to install the docs.
262 import-docs: Documentation/clean
263         $(pf); git archive origin/html | (cd Documentation && tar -xvf -)
264         $(pf); git archive origin/man | (cd Documentation && tar -xvf -)
265
266 clean: Documentation/clean cmd/bup-python
267         cd config && rm -f *~ .*~ \
268           ${CONFIGURE_DETRITUS} ${CONFIGURE_FILES} ${GENERATED_FILES}
269         rm -f *.o lib/*/*.o *.so lib/*/*.so *.dll lib/*/*.dll *.exe \
270                 .*~ *~ */*~ lib/*/*~ lib/*/*/*~ \
271                 *.pyc */*.pyc lib/*/*.pyc lib/*/*/*.pyc \
272                 bup bup-* \
273                 randomgen memtest \
274                 testfs.img lib/bup/t/testfs.img
275         if test -e t/mnt; then t/cleanup-mounts-under t/mnt; fi
276         if test -e t/mnt; then rm -r t/mnt; fi
277         if test -e t/tmp; then t/cleanup-mounts-under t/tmp; fi
278         # FIXME: migrate these to t/mnt/
279         if test -e lib/bup/t/testfs; \
280           then umount lib/bup/t/testfs || true; fi
281         rm -rf *.tmp *.tmp.meta t/*.tmp lib/*/*/*.tmp build lib/bup/build lib/bup/t/testfs
282         if test -e t/tmp; then t/force-delete t/tmp; fi
283         ./configure-version --clean
284         t/configure-sampledata --clean
285         # Remove last so that cleanup tools can depend on it
286         rm -f cmd/bup-* cmd/python-cmd.sh