]> arthur.barton.de Git - bup.git/blob - Makefile
Makefile: handle shell commands (cmd/*-cmd.sh)
[bup.git] / Makefile
1 OS:=$(shell uname | sed 's/[-_].*//')
2 CFLAGS=-Wall -g -O2 -Werror $(PYINCLUDE) -g
3 ifneq ($(OS),CYGWIN)
4   CFLAGS += -fPIC
5 endif
6 SHARED=-shared
7 SOEXT:=.so
8
9 ifeq (${OS},Darwin)
10   MACHINE:=$(shell arch)
11   CFLAGS += -arch $(MACHINE)
12   SHARED = -dynamiclib
13 endif
14 ifeq ($(OS),CYGWIN)
15   LDFLAGS += -L/usr/bin
16   EXT:=.exe
17   SOEXT:=.dll
18 endif
19
20 default: all
21
22 all: bup Documentation/all
23
24 bup: lib/bup/_version.py lib/bup/_helpers$(SOEXT) cmds
25
26 Documentation/all: bup
27
28 INSTALL=install
29 PYTHON=python
30 MANDIR=$(DESTDIR)/usr/share/man
31 DOCDIR=$(DESTDIR)/usr/share/doc/bup
32 BINDIR=$(DESTDIR)/usr/bin
33 LIBDIR=$(DESTDIR)/usr/lib/bup
34 install: all
35         $(INSTALL) -d $(MANDIR)/man1 $(DOCDIR) $(BINDIR) \
36                 $(LIBDIR)/bup $(LIBDIR)/cmd $(LIBDIR)/tornado \
37                 $(LIBDIR)/web $(LIBDIR)/web/static
38         [ ! -e Documentation/.docs-available ] || \
39           $(INSTALL) -m 0644 \
40                 Documentation/*.1 \
41                 $(MANDIR)/man1
42         [ ! -e Documentation/.docs-available ] || \
43           $(INSTALL) -m 0644 \
44                 Documentation/*.html \
45                 $(DOCDIR)
46         $(INSTALL) -m 0755 bup $(BINDIR)
47         $(INSTALL) -m 0755 \
48                 cmd/bup-* \
49                 $(LIBDIR)/cmd
50         $(INSTALL) -m 0644 \
51                 lib/bup/*.py \
52                 $(LIBDIR)/bup
53         $(INSTALL) -m 0755 \
54                 lib/bup/*$(SOEXT) \
55                 $(LIBDIR)/bup
56         $(INSTALL) -m 0644 \
57                 lib/tornado/*.py \
58                 $(LIBDIR)/tornado
59         $(INSTALL) -m 0644 \
60                 lib/web/static/* \
61                 $(LIBDIR)/web/static/
62         $(INSTALL) -m 0644 \
63                 lib/web/*.html \
64                 $(LIBDIR)/web/
65 %/all:
66         $(MAKE) -C $* all
67
68 %/clean:
69         $(MAKE) -C $* clean
70
71 lib/bup/_helpers$(SOEXT): \
72                 lib/bup/bupsplit.c lib/bup/_helpers.c lib/bup/csetup.py
73         @rm -f $@
74         cd lib/bup && $(PYTHON) csetup.py build
75         cp lib/bup/build/*/_helpers$(SOEXT) lib/bup/
76
77 .PHONY: lib/bup/_version.py
78 lib/bup/_version.py:
79         rm -f $@ $@.new
80         ./format-subst.pl $@.pre >$@.new
81         mv $@.new $@
82
83 runtests: all runtests-python runtests-cmdline
84
85 runtests-python:
86         $(PYTHON) wvtest.py $(wildcard t/t*.py lib/*/t/t*.py)
87
88 runtests-cmdline: all
89         t/test.sh
90
91 stupid:
92         PATH=/bin:/usr/bin $(MAKE) test
93
94 test: all
95         ./wvtestrun $(MAKE) PYTHON=$(PYTHON) runtests
96
97 check: test
98
99 %: %.o
100         $(CC) $(CFLAGS) (LDFLAGS) -o $@ $^ $(LIBS)
101
102 bup: main.py
103         rm -f $@
104         ln -s $< $@
105
106 cmds: \
107     $(patsubst cmd/%-cmd.py,cmd/bup-%,$(wildcard cmd/*-cmd.py)) \
108     $(patsubst cmd/%-cmd.sh,cmd/bup-%,$(wildcard cmd/*-cmd.sh))
109
110 cmd/bup-%: cmd/%-cmd.py
111         rm -f $@
112         ln -s $*-cmd.py $@
113
114 %: %.py
115         rm -f $@
116         ln -s $< $@
117
118 bup-%: cmd-%.sh
119         rm -f $@
120         ln -s $< $@
121
122 cmd/bup-%: cmd/%-cmd.sh
123         rm -f $@
124         ln -s $*-cmd.sh $@
125
126 %.o: %.c
127         gcc -c -o $@ $< $(CPPFLAGS) $(CFLAGS)
128         
129 # update the local 'man' and 'html' branches with pregenerated output files, for
130 # people who don't have pandoc (and maybe to aid in google searches or something)
131 export-docs: Documentation/all
132         git update-ref refs/heads/man origin/man '' 2>/dev/null || true
133         git update-ref refs/heads/html origin/html '' 2>/dev/null || true
134         GIT_INDEX_FILE=gitindex.tmp; export GIT_INDEX_FILE; \
135         rm -f $${GIT_INDEX_FILE} && \
136         git add -f Documentation/*.1 && \
137         git update-ref refs/heads/man \
138                 $$(echo "Autogenerated man pages for $$(git describe)" \
139                     | git commit-tree $$(git write-tree --prefix=Documentation) \
140                                 -p refs/heads/man) && \
141         rm -f $${GIT_INDEX_FILE} && \
142         git add -f Documentation/*.html && \
143         git update-ref refs/heads/html \
144                 $$(echo "Autogenerated html pages for $$(git describe)" \
145                     | git commit-tree $$(git write-tree --prefix=Documentation) \
146                                 -p refs/heads/html)
147
148 # push the pregenerated doc files to origin/man and origin/html
149 push-docs: export-docs
150         git push origin man html
151
152 # import pregenerated doc files from origin/man and origin/html, in case you
153 # don't have pandoc but still want to be able to install the docs.
154 import-docs: Documentation/clean
155         git archive origin/html | (cd Documentation; tar -xvf -)
156         git archive origin/man | (cd Documentation; tar -xvf -)
157
158 clean: Documentation/clean
159         rm -f *.o lib/*/*.o *.so lib/*/*.so *.dll *.exe \
160                 .*~ *~ */*~ lib/*/*~ lib/*/*/*~ \
161                 *.pyc */*.pyc lib/*/*.pyc lib/*/*/*.pyc \
162                 bup bup-* cmd/bup-* lib/bup/_version.py randomgen memtest \
163                 out[12] out2[tc] tags[12] tags2[tc]
164         rm -rf *.tmp t/*.tmp lib/*/*/*.tmp build lib/bup/build