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