]> arthur.barton.de Git - bup.git/blob - Makefile
a9c7fb9ebc278ac072c6372db88a7dbd3448117d
[bup.git] / Makefile
1
2 MAKEFLAGS += --warn-undefined-variables
3
4 SHELL := bash
5 .DEFAULT_GOAL := all
6
7 # See config/config.vars.in (sets bup_python, among other things)
8 -include config/config.vars
9
10 pf := set -o pipefail
11 cfg_py := $(CURDIR)/config/bin/python
12
13 define isok
14   && echo " ok" || echo " no"
15 endef
16
17 # If ok, strip trailing " ok" and return the output, otherwise, error
18 define shout
19 $(if $(subst ok,,$(lastword $(1))),$(error $(2)),$(shell x="$(1)"; echo $${x%???}))
20 endef
21
22 sampledata_rev := $(shell dev/configure-sampledata --revision $(isok))
23 sampledata_rev := \
24   $(call shout,$(sampledata_rev),Could not parse sampledata revision)
25
26 current_sampledata := test/sampledata/var/rev/v$(sampledata_rev)
27
28 os := $(shell ($(pf); uname | sed 's/[-_].*//') $(isok))
29 os := $(call shout,$(os),Unable to determine OS)
30
31 CFLAGS := -O2 -Wall -Werror -Wformat=2 $(CFLAGS)
32 CFLAGS := -Wno-unknown-pragmas -Wsign-compare $(CFLAGS)
33 CFLAGS := -D_FILE_OFFSET_BITS=64 $(PYINCLUDE) $(CFLAGS)
34 SOEXT:=.so
35
36 ifeq ($(os),CYGWIN)
37   SOEXT:=.dll
38 endif
39
40 ifdef TMPDIR
41   test_tmp := $(TMPDIR)
42 else
43   test_tmp := $(CURDIR)/test/tmp
44 endif
45
46 initial_setup := $(shell dev/update-checkout-info lib/bup/checkout_info.py $(isok))
47 initial_setup := $(call shout,$(initial_setup),update-checkout-info failed))
48
49 config/config.vars: \
50   configure config/configure config/configure.inc \
51   $(wildcard config/*.in)
52         MAKE="$(MAKE)" ./configure
53
54 # On some platforms, Python.h and readline.h fight over the
55 # _XOPEN_SOURCE version, i.e. -Werror crashes on a mismatch, so for
56 # now, we're just going to let Python's version win.
57
58 ifneq ($(strip $(bup_readline_cflags)),)
59   readline_cflags += $(bup_readline_cflags)
60   readline_xopen := $(filter -D_XOPEN_SOURCE=%,$(readline_cflags))
61   readline_xopen := $(subst -D_XOPEN_SOURCE=,,$(readline_xopen))
62   readline_cflags := $(filter-out -D_XOPEN_SOURCE=%,$(readline_cflags))
63   readline_cflags += $(addprefix -DBUP_RL_EXPECTED_XOPEN_SOURCE=,$(readline_xopen))
64   CFLAGS += $(readline_cflags)
65 endif
66
67 LDFLAGS += $(bup_readline_ldflags)
68
69 ifeq ($(bup_have_libacl),1)
70   CFLAGS += $(bup_libacl_cflags)
71   LDFLAGS += $(bup_libacl_ldflags)
72 endif
73
74 bup_ext_cmds := lib/cmd/bup-import-rdiff-backup lib/cmd/bup-import-rsnapshot
75
76 config/bin/python: config/config.vars
77
78 bup_deps := lib/bup/_helpers$(SOEXT)
79
80 all: $(bup_deps) Documentation/all $(current_sampledata)
81
82 $(current_sampledata):
83         dev/configure-sampledata --setup
84
85 PANDOC ?= $(shell type -p pandoc)
86
87 ifeq (,$(PANDOC))
88   $(shell echo "Warning: pandoc not found; skipping manpage generation" 1>&2)
89   man_md :=
90 else
91   man_md := $(wildcard Documentation/*.md)
92 endif
93
94 man_roff := $(patsubst %.md,%.1,$(man_md))
95 man_html := $(patsubst %.md,%.html,$(man_md))
96
97 INSTALL=install
98 PREFIX=/usr/local
99 MANDIR=$(PREFIX)/share/man
100 DOCDIR=$(PREFIX)/share/doc/bup
101 BINDIR=$(PREFIX)/bin
102 LIBDIR=$(PREFIX)/lib/bup
103
104 dest_mandir := $(DESTDIR)$(MANDIR)
105 dest_docdir := $(DESTDIR)$(DOCDIR)
106 dest_bindir := $(DESTDIR)$(BINDIR)
107 dest_libdir := $(DESTDIR)$(LIBDIR)
108
109 install: all
110         $(INSTALL) -d $(dest_bindir) $(dest_libdir)/bup/cmd $(dest_libdir)/cmd \
111           $(dest_libdir)/web/static
112         test -z "$(man_roff)" || install -d $(dest_mandir)/man1
113         test -z "$(man_roff)" || $(INSTALL) -m 0644 $(man_roff) $(dest_mandir)/man1
114         test -z "$(man_html)" || install -d $(dest_docdir)
115         test -z "$(man_html)" || $(INSTALL) -m 0644 $(man_html) $(dest_docdir)
116         dev/install-python-script lib/cmd/bup "$(dest_libdir)/cmd/bup"
117         $(INSTALL) -pm 0755 $(bup_ext_cmds) "$(dest_libdir)/cmd/"
118         cd "$(dest_bindir)" && \
119           ln -sf "$$($(bup_python) -c 'import os; print(os.path.relpath("$(abspath $(dest_libdir))/cmd/bup"))')"
120         set -e; \
121         $(INSTALL) -pm 0644 lib/bup/*.py $(dest_libdir)/bup/
122         $(INSTALL) -pm 0644 lib/bup/cmd/*.py $(dest_libdir)/bup/cmd/
123         $(INSTALL) -pm 0755 \
124                 lib/bup/*$(SOEXT) \
125                 $(dest_libdir)/bup
126         $(INSTALL) -pm 0644 \
127                 lib/web/static/* \
128                 $(dest_libdir)/web/static/
129         $(INSTALL) -pm 0644 \
130                 lib/web/*.html \
131                 $(dest_libdir)/web/
132         if test -e lib/bup/checkout_info.py; then \
133             $(INSTALL) -pm 0644 lib/bup/checkout_info.py \
134                 $(dest_libdir)/bup/source_info.py; \
135         else \
136             ! grep -qF '$$Format' lib/bup/source_info.py; \
137             $(INSTALL) -pm 0644 lib/bup/source_info.py $(dest_libdir)/bup/; \
138         fi
139
140 config/config.h: config/config.vars
141
142 lib/bup/_helpers$(SOEXT): \
143                 config/config.h lib/bup/bupsplit.h \
144                 lib/bup/bupsplit.c lib/bup/_helpers.c lib/bup/csetup.py
145         @rm -f $@
146         cd lib/bup && $(cfg_py) csetup.py build "$(CFLAGS)" "$(LDFLAGS)"
147         # Make sure there's just the one file we expect before we copy it.
148         $(cfg_py) -c \
149           "import glob; assert(len(glob.glob('lib/bup/build/*/_helpers*$(SOEXT)')) == 1)"
150         cp lib/bup/build/*/_helpers*$(SOEXT) "$@"
151
152 test/tmp:
153         mkdir test/tmp
154
155 ifeq (yes,$(shell config/bin/python -c "import xdist; print('yes')" 2>/dev/null))
156   # MAKEFLAGS must not be in an immediate := assignment
157   parallel_opt = $(lastword $(filter -j%,$(MAKEFLAGS)))
158   get_parallel_n = $(patsubst -j%,%,$(parallel_opt))
159   maybe_specific_n = $(if $(filter -j%,$(parallel_opt)),-n$(get_parallel_n))
160   xdist_opt = $(if $(filter -j,$(parallel_opt)),-nauto,$(maybe_specific_n))
161 else
162   xdist_opt =
163 endif
164
165 test: all test/tmp
166         ./pytest $(xdist_opt)
167
168 stupid:
169         PATH=/bin:/usr/bin $(MAKE) test
170
171 check: test
172
173 distcheck: all
174         ./pytest $(xdist_opt) -m release
175
176 long-test: export BUP_TEST_LEVEL=11
177 long-test: test
178
179 long-check: export BUP_TEST_LEVEL=11
180 long-check: check
181
182 .PHONY: check-both
183 check-both:
184         $(MAKE) clean && PYTHON=python3 $(MAKE) check
185         $(MAKE) clean && PYTHON=python2 $(MAKE) check
186
187 .PHONY: Documentation/all
188 Documentation/all: $(man_roff) $(man_html)
189
190 Documentation/substvars: $(bup_deps)
191         # FIXME: real temp file
192         set -e; bup_ver=$$(./bup version); \
193         echo "s,%BUP_VERSION%,$$bup_ver,g" > $@.tmp; \
194         echo "s,%BUP_DATE%,$$bup_ver,g" >> $@.tmp
195         mv $@.tmp $@
196
197 Documentation/%.1: Documentation/%.md Documentation/substvars
198         $(pf); sed -f Documentation/substvars $< \
199           | $(PANDOC) -s -r markdown -w man -o $@
200
201 Documentation/%.html: Documentation/%.md Documentation/substvars
202         $(pf); sed -f Documentation/substvars $< \
203           | $(PANDOC) -s -r markdown -w html -o $@
204
205 .PHONY: Documentation/clean
206 Documentation/clean:
207         cd Documentation && rm -f *~ .*~ *.[0-9] *.html substvars
208
209 # Note: this adds commits containing the current manpages in roff and
210 # html format to the man and html branches respectively.  The version
211 # is determined by "git describe --always".
212 .PHONY: update-doc-branches
213 update-doc-branches: Documentation/all
214         dev/update-doc-branches refs/heads/man refs/heads/html
215
216 # push the pregenerated doc files to origin/man and origin/html
217 push-docs: export-docs
218         git push origin man html
219
220 # import pregenerated doc files from origin/man and origin/html, in case you
221 # don't have pandoc but still want to be able to install the docs.
222 import-docs: Documentation/clean
223         $(pf); git archive origin/html | (cd Documentation && tar -xvf -)
224         $(pf); git archive origin/man | (cd Documentation && tar -xvf -)
225
226 clean: Documentation/clean config/bin/python
227         cd config && rm -rf config.var
228         cd config && rm -f *~ .*~ \
229           ${CONFIGURE_DETRITUS} ${CONFIGURE_FILES} ${GENERATED_FILES}
230         rm -f *.o lib/*/*.o *.so lib/*/*.so *.dll lib/*/*.dll *.exe \
231                 .*~ *~ */*~ lib/*/*~ lib/*/*/*~ \
232                 *.pyc */*.pyc lib/*/*.pyc lib/*/*/*.pyc \
233                 lib/bup/checkout_info.py \
234                 randomgen memtest \
235                 testfs.img test/int/testfs.img
236         if test -e test/mnt; then dev/cleanup-mounts-under test/mnt; fi
237         if test -e test/mnt; then rm -r test/mnt; fi
238         if test -e test/tmp; then dev/cleanup-mounts-under test/tmp; fi
239         # FIXME: migrate these to test/mnt/
240         if test -e test/int/testfs; \
241           then umount test/int/testfs || true; fi
242         rm -rf *.tmp *.tmp.meta test/*.tmp lib/*/*/*.tmp build lib/bup/build test/int/testfs
243         if test -e test/tmp; then dev/force-delete test/tmp; fi
244         dev/configure-sampledata --clean
245         # Remove last so that cleanup tools can depend on it
246         rm -rf config/bin