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