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