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