]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - Makefile
tweaks to build process to support py2exe
[tahoe-lafs/tahoe-lafs.git] / Makefile
1
2 # this Makefile requires GNU make
3
4 default: simple-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 REACTOR=
11
12 ifneq ($(INCLUDE_DIRS),)
13 INCLUDE_DIRS_ARG = -I$(INCLUDE_DIRS)
14 endif
15 ifneq ($(LIBRARY_DIRS),)
16 LIBRARY_DIRS_ARG = -L$(LIBRARY_DIRS)
17 endif
18
19 PLAT = $(strip $(shell python -c "import sys ; print sys.platform"))
20 ifeq ($(PLAT),win32)
21  # The platform is Windows with cygwin build tools and the native Python interpreter.
22  SUPPORT = $(shell cygpath -w $(shell pwd))\support
23  SUPPORTLIB := $(SUPPORT)\Lib\site-packages
24  SRCPATH := $(shell cygpath -w $(shell pwd)/src)
25  CHECK_PYWIN32_DEP := check-pywin32-dep
26 else
27  PYVER=$(shell $(PYTHON) misc/pyver.py)
28  SUPPORT = $(shell pwd)/support
29  SUPPORTLIB = $(SUPPORT)/lib/$(PYVER)/site-packages
30  SRCPATH := $(shell pwd)/src
31  CHECK_PYWIN32_DEP := 
32 endif
33
34 TRIALCMD = $(shell PYTHONPATH="$(PYTHONPATH)$(PATHSEP)$(SRCPATH)" $(PYTHON) misc/find_trial.py)
35
36 ifeq ($(PLAT),cygwin)
37 REACTOR = poll
38 endif
39
40 ifneq ($(REACTOR),)
41         REACTOROPT := --reactor=$(REACTOR)
42 else
43         REACTOROPT := 
44 endif
45
46 TRIAL=PYTHONUNBUFFERED=1 $(TRIALCMD) --rterrors $(REACTOROPT)
47
48 build-auto-deps: check-deps
49         mkdir -p "$(SUPPORTLIB)"
50         echo PYTHONPATH="$(PYTHONPATH)$(PATHSEP)$(SUPPORTLIB)$(PATHSEP)" $(PYTHON) misc/dependencies/build-deps-setup.py install --prefix="$(SUPPORT)"
51         @-PYTHONPATH="$(PYTHONPATH)$(PATHSEP)$(SUPPORTLIB)$(PATHSEP)" \
52          $(PYTHON) misc/dependencies/build-deps-setup.py install \
53          --prefix="$(SUPPORT)"
54
55 # The following target is here because I don't know how to tell the buildmaster
56 # to start instructing his slaves to "build-auto-deps" instead of instructing
57 # them to "build-deps".  --Z
58 build-deps: build-auto-deps
59
60 EGGSPATH = $(shell $(PYTHON) misc/find-dep-eggs.py)
61 show-eggspath:
62         @echo $(EGGSPATH)
63
64 ifneq ($(PYTHONPATH),)
65         PYTHONPATH := $(PYTHONPATH)$(PATHSEP)
66 endif
67 PP=PYTHONPATH="$(SRCPATH)$(PATHSEP)$(PYTHONPATH)$(PATHSEP)$(EGGSPATH)"
68
69 .PHONY: make-version build
70
71 # The 'darcsver' setup.py command comes in the 'darcsver' package:
72 # http://pypi.python.org/pypi/darcsver It is necessary only if you want to
73 # automatically produce a new _version.py file from the current darcs history.
74 make-version:
75         $(PYTHON) ./setup.py darcsver
76
77 # We want src/allmydata/_version.py to be up-to-date, but it's a fairly
78 # expensive operation (about 6 seconds on a just-before-0.7.0 tree, probably
79 # because of the 332 patches since the last tag), and we've removed the need
80 # for an explicit 'build' step by removing the C code from src/allmydata and
81 # by running everything in place. It would be neat to do:
82 #
83 #src/allmydata/_version.py: _darcs/patches
84 #       $(MAKE) make-version
85 #
86 # since that would update the embedded version string each time new darcs
87 # patches were pulled, but 1) this would break non-darcs trees (i.e. building
88 # from an exported tarball), and 2) without an obligatory 'build' step this
89 # rule wouldn't be run frequently enought anyways.
90 #
91 # So instead, I'll just make sure that we update the version at least once
92 # when we first start using the tree, and again whenever an explicit
93 # 'make-version' is run, since then at least the developer has some means to
94 # update things. It would be nice if 'make clean' deleted any
95 # automatically-generated _version.py too, so that 'make clean; make all'
96 # could be useable as a "what the heck is going on, get me back to a clean
97 # state', but we need 'make clean' to work on non-darcs trees without
98 # destroying useful information.
99
100 .built:
101         $(MAKE) build
102         touch .built
103
104 simple-build: build-auto-deps build
105
106 src/allmydata/_version.py:
107         $(MAKE) make-version
108
109 build: src/allmydata/_version.py
110         echo $(PYTHON) ./setup.py build_ext -i $(INCLUDE_DIRS_ARG) $(LIBRARY_DIRS_ARG)
111         @$(PYTHON) ./setup.py build_ext -i $(INCLUDE_DIRS_ARG) $(LIBRARY_DIRS_ARG) || \
112                 echo "Build of Allmydata-Tahoe failed -- please see docs/install.html for instructions."
113         chmod +x bin/tahoe
114
115 # 'make install' will do the following:
116 #   build+install tahoe (probably to /usr/lib/pythonN.N/site-packages)
117 # 'make install PREFIX=/usr/local/stow/tahoe-N.N' will do the same, but to
118 # a different location
119
120 install: src/allmydata/_version.py
121 ifdef PREFIX
122         mkdir -p $(PREFIX)
123         $(PP) $(PYTHON) ./setup.py install \
124            --single-version-externally-managed \
125            --prefix=$(PREFIX) --record=./tahoe.files
126 else
127         $(PP) $(PYTHON) ./setup.py install \
128            --single-version-externally-managed
129 endif
130
131
132 # TESTING
133
134 .PHONY: check-all-deps check-twisted-dep $(CHECK_PYWIN32_DEP) signal-error-deps, signal-error-twisted-dep, signal-error-pywin32-dep, test test-figleaf figleaf-output
135
136
137 signal-error-deps:
138         @echo
139         @echo
140         @echo "ERROR: Not all of Tahoe's dependencies are in place.  Please \
141 see the README for help on installing dependencies."
142         @echo
143         @echo
144         exit 1
145
146 signal-error-twisted-dep:
147         @echo
148         @echo
149         @echo "ERROR: Before running \"make build-auto-deps\" you have to ensure that \
150 Twisted is installed (including its zope.interface dependency).  Twisted and \
151 zope.interface are required for the automatic installation of certain other \
152 libraries that Tahoe requires).  Please see the README for details."
153         @echo
154         @echo
155         exit 1
156
157 signal-error-pywin32-dep:
158         @echo
159         @echo
160         @echo "ERROR: the pywin32 dependency is not in place.  Please see the README \
161 for help on installing dependencies."
162         @echo
163         @echo
164         exit 1
165
166 signal-error-pyopenssl-dep:
167         @echo
168         @echo
169         @echo "ERROR: the pyOpenSSL dependency is not in place (note that pyOpenSSL required \
170 OpenSSL).  Please see the README for help on installing dependencies."
171         @echo
172         @echo
173         exit 1
174
175 check-all-deps: check-deps
176         $(PP) \
177          $(PYTHON) -c 'import allmydata, zfec, foolscap, simplejson, nevow, pycryptopp' || $(MAKE) signal-error-deps
178
179 check-twisted-dep:
180         $(PYTHON) -c 'import twisted, zope.interface' || $(MAKE) signal-error-twisted-dep
181
182 check-pywin32-dep:
183         $(PYTHON) -c 'import win32process' || $(MAKE) signal-error-pywin32-dep
184
185 check-pyopenssl-dep:
186         $(PYTHON) -c 'import OpenSSL' || $(MAKE) signal-error-pyopenssl-dep
187
188 check-deps: check-twisted-dep $(CHECK_PYWIN32_DEP) check-pyopenssl-dep
189
190 .checked-deps:
191         $(MAKE) check-all-deps
192         touch .checked-deps
193
194 # you can use 'make test TEST=allmydata.test.test_introducer' to run just
195 # test_introducer. TEST=allmydata.test.test_client.Basic.test_permute works
196 # too.
197 TEST=allmydata
198
199 # use 'make test TRIALARGS=--reporter=bwverbose' from buildbot, to
200 # suppress the ansi color sequences
201
202 test: .built .checked-deps
203         $(PP) \
204          $(TRIAL) $(TRIALARGS) $(TEST)
205
206 test-figleaf: .built .checked-deps
207         rm -f .figleaf
208         $(PP) \
209          $(TRIAL) --reporter=bwverbose-figleaf $(TEST)
210
211 figleaf-output:
212         $(PP) \
213          $(PYTHON) misc/figleaf2html -d coverage-html -r src -x misc/figleaf.excludes
214         @echo "now point your browser at coverage-html/index.html"
215
216 # after doing test-figleaf and figleaf-output, point your browser at
217 # coverage-html/index.html
218
219 .PHONY: upload-figleaf .figleaf.el pyflakes count-lines
220 .PHONY: check-memory check-memory-once clean
221
222 # 'upload-figleaf' is meant to be run with an UPLOAD_TARGET=host:/dir setting
223 ifdef UPLOAD_TARGET
224
225 ifndef UPLOAD_HOST
226 $(error UPLOAD_HOST must be set when using UPLOAD_TARGET)
227 endif
228 ifndef COVERAGEDIR
229 $(error COVERAGEDIR must be set when using UPLOAD_TARGET)
230 endif
231
232 upload-figleaf:
233         rsync -a coverage-html/ $(UPLOAD_TARGET)
234         ssh $(UPLOAD_HOST) make update-tahoe-figleaf COVERAGEDIR=$(COVERAGEDIR)
235 else
236 upload-figleaf:
237         echo "this target is meant to be run with UPLOAD_TARGET=host:/path/"
238         /bin/false
239 endif
240
241 .figleaf.el: .figleaf
242         $(PP) \
243          $(PYTHON) misc/figleaf2el.py .figleaf src
244
245 pyflakes:
246         $(PYTHON) -OOu `which pyflakes` src/allmydata |sort |uniq
247
248 count-lines:
249         @echo -n "files: "
250         @find src -name '*.py' |grep -v /build/ |wc --lines
251         @echo -n "lines: "
252         @cat `find src -name '*.py' |grep -v /build/` |wc --lines
253         @echo -n "TODO: "
254         @grep TODO `find src -name '*.py' |grep -v /build/` | wc --lines
255
256 check-memory: .built
257         rm -rf _test_memory
258         $(PP) \
259          $(PYTHON) src/allmydata/test/check_memory.py upload
260         $(PP) \
261          $(PYTHON) src/allmydata/test/check_memory.py upload-self
262         $(PP) \
263          $(PYTHON) src/allmydata/test/check_memory.py upload-POST
264         $(PP) \
265          $(PYTHON) src/allmydata/test/check_memory.py download
266         $(PP) \
267          $(PYTHON) src/allmydata/test/check_memory.py download-GET
268         $(PP) \
269          $(PYTHON) src/allmydata/test/check_memory.py download-GET-slow
270         $(PP) \
271          $(PYTHON) src/allmydata/test/check_memory.py receive
272
273 check-memory-once: .built
274         rm -rf _test_memory
275         $(PP) \
276          $(PYTHON) src/allmydata/test/check_memory.py $(MODE)
277
278 # this target uses a pre-established client node to run a canned set of
279 # performance tests against a test network that is also pre-established
280 # (probably on a remote machine). Provide it with the path to a local
281 # directory where this client node has been created (and populated with the
282 # necessary FURLs of the test network). This target will start that client
283 # with the current code and then run the tests. Afterwards it will stop the
284 # client.
285 #
286 # The 'sleep 5' is in there to give the new client a chance to connect to its
287 # storageservers, since check_speed.py has no good way of doing that itself.
288
289 check-speed: .built
290         if [ -z '$(TESTCLIENTDIR)' ]; then exit 1; fi
291         @echo "stopping any leftover client code"
292         -$(PYTHON) bin/tahoe stop $(TESTCLIENTDIR)
293         $(PYTHON) bin/tahoe start $(TESTCLIENTDIR)
294         sleep 5
295         $(PYTHON) src/allmydata/test/check_speed.py $(TESTCLIENTDIR)
296         $(PYTHON) bin/tahoe stop $(TESTCLIENTDIR)
297
298 # 'make repl' is a simple-to-type command to get a Python interpreter loop
299 # from which you can type 'import allmydata'
300 repl:
301         $(PP) python
302
303 test-darcs-boringfile:
304         $(MAKE)
305         $(PYTHON) misc/test-darcs-boringfile.py
306
307 test-clean:
308         find . |grep -v allfiles.tmp |grep -v src/allmydata/_version.py |sort >allfiles.tmp.old
309         $(MAKE)
310         $(MAKE) clean
311         find . |grep -v allfiles.tmp |grep -v src/allmydata/_version.py |sort >allfiles.tmp.new
312         diff allfiles.tmp.old allfiles.tmp.new
313
314 clean:
315         rm -rf build _trial_temp _test_memory .checked-deps .built
316         rm -f debian
317         rm -f `find src/allmydata -name '*.so' -or -name '*.pyc'`
318         rm -rf tahoe_deps.egg-info allmydata_tahoe.egg-info
319         rm -rf support dist
320         rm -rf setuptools*.egg *.pyc darcsver*.egg
321
322 find-trailing-spaces:
323         $(PYTHON) misc/find-trailing-spaces.py -r src
324
325
326 # DEBIAN PACKAGING
327
328 VER=$(shell $(PYTHON) misc/get-version.py)
329 DEBCOMMENTS="'make deb' build"
330
331 show-version:
332         @echo $(VER)
333
334 .PHONY: setup-deb deb-ARCH is-known-debian-arch
335 .PHONY: deb-sid deb-feisty deb-edgy deb-etch
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
351 # we know how to handle the following debian architectures
352 KNOWN_DEBIAN_ARCHES := sid feisty edgy etch gutsy
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-sid-head deb-edgy-head deb-feisty-head
389 .PHONY: deb-etch-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