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