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