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