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