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