]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - Makefile
Makefile: avoid bare quotes, since the emacs syntax-highlighter gets confused by...
[tahoe-lafs/tahoe-lafs.git] / Makefile
1
2 # NOTE: this Makefile requires GNU make
3
4 default: build
5
6 PYTHON=python
7 PATHSEP=$(shell $(PYTHON) -c 'import os ; print os.pathsep')
8 OSSEP=$(shell $(PYTHON) -c 'import os ; print os.sep')
9
10 ifneq ($(INCLUDE_DIRS),)
11 INCLUDE_DIRS_ARG = -I$(INCLUDE_DIRS)
12 endif
13 ifneq ($(LIBRARY_DIRS),)
14 LIBRARY_DIRS_ARG = -L$(LIBRARY_DIRS)
15 endif
16
17 PLAT = $(strip $(shell $(PYTHON) -c "import sys ; print sys.platform"))
18 ifeq ($(PLAT),win32)
19         # The platform is Windows with cygwin build tools and the native Python interpreter.
20         SUPPORT = $(shell cygpath -w $(shell pwd))\support
21         SUPPORTLIB := $(SUPPORT)\Lib\site-packages
22         SRCPATH := $(shell cygpath -w $(shell pwd)/src)
23         INNOSETUP := $(shell cygpath -au "$(PROGRAMFILES)/Inno Setup 5/Compil32.exe")
24 else
25         ifeq ($(PLAT),linux2)
26                 # This is to work-around #402, and anyway the poll reactor is probably better on Linux, if
27                 # we have a lot of open fds.
28                 ifeq ($(REACTOR),)
29                         REACTOR := poll
30                 endif
31         endif
32         ifeq ($(PLAT),cygwin)
33                 # The cygwin select reactor seems to run out of fds in unit tests -- it writes "filedescriptor
34                 # out of range in select()".  Setting reactor=poll fixes that.
35                 ifeq ($(REACTOR),)
36                         REACTOR := poll
37                 endif
38         endif
39         PYVER=$(shell $(PYTHON) misc/pyver.py)
40         SUPPORT = $(shell pwd)/support
41         SUPPORTLIB = $(SUPPORT)/lib/$(PYVER)/site-packages
42         SRCPATH := $(shell pwd)/src
43         CHECK_PYWIN32_DEP := 
44 endif
45
46 ifneq ($(REACTOR),)
47         REACTOROPT := --reactor=$(REACTOR)
48 else
49         REACTOROPT :=
50 endif
51
52 ifneq ($(PYTHONPATH),)
53         PP=PYTHONPATH="$(PYTHONPATH)$(PATHSEP)$(SUPPORTLIB)"
54 else
55         PP=PYTHONPATH="$(SUPPORTLIB)"
56 endif
57
58 # Delete any quote chars in PATH.  Note that if the chars were escaped
59 # (preceded by a back-slash) then the following subst will screw it up and
60 # weird parsing errors will eventually result.
61
62 PATH := $(subst ",,${PATH})
63 PATH := $(subst ',,$(PATH))
64 # ' "  # emacs syntax-highlighter gets confused by the bare quotes above
65
66 TRIALCMD = $(shell PATH="$(PATH):${PWD}/support/bin" $(PP) $(PYTHON) misc/find_trial.py)
67 ifeq ($(TRIALCMD),)
68 $(error Could not find trial.  It comes with twisted.)
69 endif
70 TRIAL=PATH="$(PATH):${PWD}/support/bin" PYTHONUNBUFFERED=1 $(TRIALCMD) --rterrors $(REACTOROPT)
71
72 TRIALCMD = $(shell PATH="${PATH}:${PWD}/support/bin" $(PP) $(PYTHON) misc/find_trial.py)
73 TRIAL=PATH="${PATH}:${PWD}/support/bin" PYTHONUNBUFFERED=1 $(TRIALCMD) --rterrors $(REACTOROPT) $(TRIALOPT)
74
75 .PHONY: make-version build
76
77 # The 'darcsver' setup.py command comes in the 'darcsver' package:
78 # http://pypi.python.org/pypi/darcsver It is necessary only if you want to
79 # automatically produce a new _version.py file from the current darcs history.
80 make-version:
81         $(PP) $(PYTHON) ./setup.py darcsver --count-all-patches
82
83 # We want src/allmydata/_version.py to be up-to-date, but it's a fairly
84 # expensive operation (about 6 seconds on a just-before-0.7.0 tree, probably
85 # because of the 332 patches since the last tag), and we've removed the need
86 # for an explicit 'build' step by removing the C code from src/allmydata and
87 # by running everything in place. It would be neat to do:
88 #
89 #src/allmydata/_version.py: _darcs/patches
90 #       $(MAKE) make-version
91 #
92 # since that would update the embedded version string each time new darcs
93 # patches were pulled, but 1) this would break non-darcs trees (i.e. building
94 # from an exported tarball), and 2) without an obligatory 'build' step this
95 # rule wouldn't be run frequently enought anyways.
96 #
97 # So instead, I'll just make sure that we update the version at least once
98 # when we first start using the tree, and again whenever an explicit
99 # 'make-version' is run, since then at least the developer has some means to
100 # update things. It would be nice if 'make clean' deleted any
101 # automatically-generated _version.py too, so that 'make clean; make all'
102 # could be useable as a "what the heck is going on, get me back to a clean
103 # state', but we need 'make clean' to work on non-darcs trees without
104 # destroying useful information.
105
106 .built:
107         $(MAKE) build
108
109 src/allmydata/_version.py:
110         $(MAKE) make-version
111
112 # c.f. ticket #455, there is a problem in the intersection of setuptools,
113 # twisted's setup.py, and nevow's setup.py . A Tahoe build, to satisfy its
114 # dependencies, may try to build both Twisted and Nevow. If both of these
115 # occur during the same invocation of 'setup.py develop', then the Nevow
116 # build will fail with an "ImportError: No module named components". Running
117 # the build a second time will succeed. Until there is a new version of
118 # setuptools which properly sandboxes sys.modules (or a new version of nevow
119 # which doesn't import twisted during its build, or a new version of twisted
120 # which doesn't import itself during its build), we just build tahoe twice
121 # and ignore the errors from the first pass.
122
123 build: src/allmydata/_version.py
124         -$(MAKE) build-once
125         $(MAKE) build-once
126
127 build-once:
128         mkdir -p "$(SUPPORTLIB)"
129         $(PP) $(PYTHON) ./setup.py develop --prefix="$(SUPPORT)"
130         chmod +x bin/tahoe
131         touch .built
132
133 # 'make install' will do the following:
134 #   build+install tahoe (probably to /usr/lib/pythonN.N/site-packages)
135 # 'make install PREFIX=/usr/local/stow/tahoe-N.N' will do the same, but to
136 # a different location
137
138 install: src/allmydata/_version.py
139 ifdef PREFIX
140         mkdir -p $(PREFIX)
141         $(PP) $(PYTHON) ./setup.py install \
142            --single-version-externally-managed \
143            --prefix=$(PREFIX) --record=./tahoe.files
144 else
145         $(PP) $(PYTHON) ./setup.py install \
146            --single-version-externally-managed
147 endif
148
149
150 # TESTING
151
152 .PHONY: signal-error-deps test test-figleaf figleaf-output
153
154
155 signal-error-deps:
156         @echo
157         @echo
158         @echo "ERROR: Not all of Tahoe's dependencies are in place.  Please see docs/install.html for help on installing dependencies."
159         @echo
160         @echo
161         exit 1
162
163 check-auto-deps:
164         @$(PP) $(PYTHON) -c 'import _auto_deps ; _auto_deps.require_auto_deps()' || $(MAKE) signal-error-deps
165
166 .checked-deps:
167         $(MAKE) check-auto-deps
168         touch .checked-deps
169
170 # you can use 'make test TEST=allmydata.test.test_introducer' to run just
171 # test_introducer. TEST=allmydata.test.test_client.Basic.test_permute works
172 # too.
173 TEST=allmydata
174
175 # use 'make test TRIALARGS=--reporter=bwverbose' from buildbot, to
176 # suppress the ansi color sequences
177
178 test: build src/allmydata/_version.py
179         $(PP) $(TRIAL) $(TRIALARGS) $(TEST)
180
181 quicktest: .built .checked-deps
182         $(PP) $(TRIAL) $(TRIALARGS) $(TEST)
183
184 test-figleaf: build src/allmydata/_version.py
185         rm -f .figleaf
186         $(PP) $(TRIAL) --reporter=bwverbose-figleaf $(TEST)
187
188 quicktest-figleaf: src/allmydata/_version.py
189         rm -f .figleaf
190         $(PP) $(TRIAL) --reporter=bwverbose-figleaf $(TEST)
191
192 figleaf-output:
193         $(PP) \
194          $(PYTHON) misc/figleaf2html -d coverage-html -r src -x misc/figleaf.excludes
195         @echo "now point your browser at coverage-html/index.html"
196
197 # after doing test-figleaf and figleaf-output, point your browser at
198 # coverage-html/index.html
199
200 .PHONY: upload-figleaf .figleaf.el pyflakes count-lines
201 .PHONY: check-memory check-memory-once clean
202
203 # 'upload-figleaf' is meant to be run with an UPLOAD_TARGET=host:/dir setting
204 ifdef UPLOAD_TARGET
205
206 ifndef UPLOAD_HOST
207 $(error UPLOAD_HOST must be set when using UPLOAD_TARGET)
208 endif
209 ifndef COVERAGEDIR
210 $(error COVERAGEDIR must be set when using UPLOAD_TARGET)
211 endif
212
213 upload-figleaf:
214         rsync -a coverage-html/ $(UPLOAD_TARGET)
215         ssh $(UPLOAD_HOST) make update-tahoe-figleaf COVERAGEDIR=$(COVERAGEDIR)
216 else
217 upload-figleaf:
218         echo "this target is meant to be run with UPLOAD_TARGET=host:/path/"
219         false
220 endif
221
222 .figleaf.el: .figleaf
223         $(PP) $(PYTHON) misc/figleaf2el.py .figleaf src
224
225 pyflakes:
226         $(PYTHON) -OOu `which pyflakes` src/allmydata |sort |uniq
227
228 count-lines:
229         @echo -n "files: "
230         @find src -name '*.py' |grep -v /build/ |wc --lines
231         @echo -n "lines: "
232         @cat `find src -name '*.py' |grep -v /build/` |wc --lines
233         @echo -n "TODO: "
234         @grep TODO `find src -name '*.py' |grep -v /build/` | wc --lines
235
236 check-memory: .built
237         rm -rf _test_memory
238         $(PP) \
239          $(PYTHON) src/allmydata/test/check_memory.py upload
240         $(PP) \
241          $(PYTHON) src/allmydata/test/check_memory.py upload-self
242         $(PP) \
243          $(PYTHON) src/allmydata/test/check_memory.py upload-POST
244         $(PP) \
245          $(PYTHON) src/allmydata/test/check_memory.py download
246         $(PP) \
247          $(PYTHON) src/allmydata/test/check_memory.py download-GET
248         $(PP) \
249          $(PYTHON) src/allmydata/test/check_memory.py download-GET-slow
250         $(PP) \
251          $(PYTHON) src/allmydata/test/check_memory.py receive
252
253 check-memory-once: .built
254         rm -rf _test_memory
255         $(PP) \
256          $(PYTHON) src/allmydata/test/check_memory.py $(MODE)
257
258 # The check-speed target uses a pre-established client node to run a canned
259 # set of performance tests against a test network that is also
260 # pre-established (probably on a remote machine). Provide it with the path to
261 # a local directory where this client node has been created (and populated
262 # with the necessary FURLs of the test network). This target will start that
263 # client with the current code and then run the tests. Afterwards it will
264 # stop the client.
265 #
266 # The 'sleep 5' is in there to give the new client a chance to connect to its
267 # storageservers, since check_speed.py has no good way of doing that itself.
268
269 check-speed: .built
270         if [ -z '$(TESTCLIENTDIR)' ]; then exit 1; fi
271         @echo "stopping any leftover client code"
272         -$(PYTHON) bin/tahoe stop $(TESTCLIENTDIR)
273         $(PYTHON) bin/tahoe start $(TESTCLIENTDIR)
274         sleep 5
275         $(PYTHON) src/allmydata/test/check_speed.py $(TESTCLIENTDIR)
276         $(PYTHON) bin/tahoe stop $(TESTCLIENTDIR)
277
278 # The check-grid target also uses a pre-established client node, along with a
279 # long-term directory that contains some well-known files. See the docstring
280 # in src/allmydata/test/check_grid.py to see how to set this up.
281 check-grid: .built
282         if [ -z '$(TESTCLIENTDIR)' ]; then exit 1; fi
283         $(PYTHON) src/allmydata/test/check_grid.py $(TESTCLIENTDIR) bin/tahoe
284
285 # 'make repl' is a simple-to-type command to get a Python interpreter loop
286 # from which you can type 'import allmydata'
287 repl:
288         $(PP) $(PYTHON)
289
290 test-darcs-boringfile:
291         $(MAKE)
292         $(PYTHON) misc/test-darcs-boringfile.py
293
294 test-clean:
295         find . |grep -vEe"allfiles.tmp|src/allmydata/_(version|auto_deps).py|src/allmydata_tahoe.egg-info" |sort >allfiles.tmp.old
296         $(MAKE)
297         $(MAKE) clean
298         find . |grep -vEe"allfiles.tmp|src/allmydata/_(version|auto_deps).py|src/allmydata_tahoe.egg-info" |sort >allfiles.tmp.new
299         diff allfiles.tmp.old allfiles.tmp.new
300
301 clean:
302         rm -rf build _trial_temp _test_memory .checked-deps .built
303         rm -f debian
304         rm -f `find src/allmydata -name '*.so' -or -name '*.pyc'`
305         rm -rf tahoe_deps.egg-info allmydata_tahoe.egg-info
306         rm -rf support dist
307         rm -rf setuptools*.egg *.pyc darcsver*.egg pyutil*.egg
308         rm -rf misc/dependencies/build misc/dependencies/temp
309         rm -rf misc/dependencies/tahoe_deps.egg-info
310
311 find-trailing-spaces:
312         $(PYTHON) misc/find-trailing-spaces.py -r src
313
314 # TARBALL GENERATION
315 .PHONY: tarballs upload-tarballs
316 tarballs:
317         $(MAKE) make-version
318         $(PYTHON) setup.py sdist --formats=bztar,gztar,zip
319 upload-tarballs:
320         for f in dist/allmydata-tahoe-*; do \
321          xfer-client --furlfile ~/.tahoe-tarball-upload.furl $$f; \
322         done
323
324 # DEBIAN PACKAGING
325
326 VER=$(shell $(PYTHON) misc/get-version.py)
327 DEBCOMMENTS="'make deb' build"
328
329 show-version:
330         @echo $(VER)
331
332 .PHONY: setup-deb deb-ARCH is-known-debian-arch
333 .PHONY: deb-etch deb-sid
334 .PHONY: deb-edgy deb-feisty deb-gutsy deb-hardy
335
336 deb-sid:
337         $(MAKE) deb-ARCH ARCH=sid
338 deb-feisty:
339         $(MAKE) deb-ARCH ARCH=feisty
340 # edgy uses the feisty control files for now
341 deb-edgy:
342         $(MAKE) deb-ARCH ARCH=edgy TAHOE_ARCH=feisty
343 # etch uses the feisty control files for now
344 deb-etch:
345         $(MAKE) deb-ARCH ARCH=etch TAHOE_ARCH=feisty
346 # same with gutsy, the process has been nicely stable for a while now
347 deb-gutsy:
348         $(MAKE) deb-ARCH ARCH=gutsy TAHOE_ARCH=feisty
349 deb-hardy:
350         $(MAKE) deb-ARCH ARCH=hardy TAHOE_ARCH=feisty
351
352 # we know how to handle the following debian architectures
353 KNOWN_DEBIAN_ARCHES := etch sid  edgy feisty gutsy hardy
354
355 ifeq ($(findstring x-$(ARCH)-x,$(foreach arch,$(KNOWN_DEBIAN_ARCHES),"x-$(arch)-x")),)
356 is-known-debian-arch:
357         @echo "ARCH must be set when using setup-deb or deb-ARCH"
358         @echo "I know how to handle:" $(KNOWN_DEBIAN_ARCHES)
359         false
360 else
361 is-known-debian-arch:
362         true
363 endif
364
365 ifndef TAHOE_ARCH
366 TAHOE_ARCH=$(ARCH)
367 endif
368
369 setup-deb: is-known-debian-arch
370         rm -f debian
371         ln -s misc/$(TAHOE_ARCH)/debian debian
372         chmod +x debian/rules
373
374 # etch (current debian stable) has python-simplejson-1.3, which doesn't 
375 #  support indent=
376 # sid (debian unstable) currently has python-simplejson 1.7.1
377 # edgy has 1.3, which doesn't support indent=
378 # feisty has 1.4, which supports indent= but emits a deprecation warning
379 # gutsy has 1.7.1
380 #
381 # we need 1.4 or newer
382
383 deb-ARCH: is-known-debian-arch setup-deb
384         fakeroot debian/rules binary
385         @echo
386         @echo "The newly built .deb packages are in the parent directory from here."
387
388 .PHONY: increment-deb-version
389 .PHONY: deb-edgy-head deb-feisty-head deb-gutsy-head deb-hardy-head
390 .PHONY: deb-etch-head deb-sid-head
391
392 # The buildbot runs the following targets after each change, to produce
393 # up-to-date tahoe .debs. These steps do not create .debs for anything else.
394
395 increment-deb-version: make-version
396         debchange --newversion $(VER) $(DEBCOMMENTS)
397 deb-sid-head:
398         $(MAKE) setup-deb ARCH=sid
399         $(MAKE) increment-deb-version
400         fakeroot debian/rules binary
401 deb-edgy-head:
402         $(MAKE) setup-deb ARCH=edgy TAHOE_ARCH=feisty
403         $(MAKE) increment-deb-version
404         fakeroot debian/rules binary
405 deb-feisty-head:
406         $(MAKE) setup-deb ARCH=feisty
407         $(MAKE) increment-deb-version
408         fakeroot debian/rules binary
409 deb-etch-head:
410         $(MAKE) setup-deb ARCH=etch TAHOE_ARCH=feisty
411         $(MAKE) increment-deb-version
412         fakeroot debian/rules binary
413 deb-gutsy-head:
414         $(MAKE) setup-deb ARCH=gutsy TAHOE_ARCH=feisty
415         $(MAKE) increment-deb-version
416         fakeroot debian/rules binary
417 deb-hardy-head:
418         $(MAKE) setup-deb ARCH=hardy TAHOE_ARCH=feisty
419         $(MAKE) increment-deb-version
420         fakeroot debian/rules binary
421
422 # These targets provide for windows native builds
423 .PHONY: windows-exe windows-installer windows-installer-upload
424
425 windows-exe: .built
426         cd windows && $(PP) $(PYTHON) setup.py py2exe
427
428 windows-installer: windows-exe
429         $(PP) $(PYTHON) misc/sub-ver.py windows/installer.tmpl >windows/installer.iss
430         cd windows && "$(INNOSETUP)" /cc installer.iss
431
432 windows-installer-upload:
433         chmod -R o+rx windows/dist/installer
434         rsync -av -e /usr/bin/ssh windows/dist/installer/ amduser@dev:/home/amduser/public_html/dist/tahoe/windows/
435
436 # These targets provide for mac native builds
437 .PHONY: mac-exe mac-upload mac-cleanup mac-dbg
438
439 mac-exe: .built
440         $(MAKE) -C mac clean
441         VERSION=$(VER) $(PP) $(MAKE) -C mac build
442
443 mac-dist:
444         VERSION=$(VER) $(MAKE) -C mac diskimage
445
446 mac-upload:
447         VERSION=$(VER) $(MAKE) -C mac upload UPLOAD_DEST=$(UPLOAD_DEST)
448
449 mac-cleanup:
450         VERSION=$(VER) $(MAKE) -C mac cleanup
451
452 mac-dbg:
453         cd mac && $(PP) $(PYTHON)w allmydata_tahoe.py
454
455 # This target runs a stats gatherer server
456 .PHONY: stats-gatherer-run
457 stats-gatherer-run:
458         cd stats_gatherer && $(PP) $(PYTHON) ../src/allmydata/stats.py