Merge remote-tracking branch 'upstream/v0.10'
[platform/upstream/nodejs.git] / Makefile
1 -include config.mk
2
3 BUILDTYPE ?= Release
4 PYTHON ?= python
5 NINJA ?= ninja
6 DESTDIR ?=
7 SIGN ?=
8 PREFIX ?= /usr/local
9
10 NODE ?= ./node
11
12 # Default to verbose builds.
13 # To do quiet/pretty builds, run `make V=` to set V to an empty string,
14 # or set the V environment variable to an empty string.
15 V ?= 1
16
17 # BUILDTYPE=Debug builds both release and debug builds. If you want to compile
18 # just the debug build, run `make -C out BUILDTYPE=Debug` instead.
19 ifeq ($(BUILDTYPE),Release)
20 all: out/Makefile node
21 else
22 all: out/Makefile node node_g
23 endif
24
25 # The .PHONY is needed to ensure that we recursively use the out/Makefile
26 # to check for changes.
27 .PHONY: node node_g
28
29 ifeq ($(USE_NINJA),1)
30 node: config.gypi
31         $(NINJA) -C out/Release/
32         ln -fs out/Release/node node
33
34 node_g: config.gypi
35         $(NINJA) -C out/Debug/
36         ln -fs out/Debug/node $@
37 else
38 node: config.gypi out/Makefile
39         $(MAKE) -C out BUILDTYPE=Release V=$(V)
40         ln -fs out/Release/node node
41
42 node_g: config.gypi out/Makefile
43         $(MAKE) -C out BUILDTYPE=Debug V=$(V)
44         ln -fs out/Debug/node $@
45 endif
46
47 out/Makefile: common.gypi deps/uv/uv.gyp deps/http_parser/http_parser.gyp deps/zlib/zlib.gyp deps/v8/build/toolchain.gypi deps/v8/build/features.gypi deps/v8/tools/gyp/v8.gyp node.gyp config.gypi
48 ifeq ($(USE_NINJA),1)
49         touch out/Makefile
50         $(PYTHON) tools/gyp_node -f ninja
51 else
52         $(PYTHON) tools/gyp_node -f make
53 endif
54
55 config.gypi: configure
56         $(PYTHON) ./configure
57
58 install: all
59         $(PYTHON) tools/install.py $@ '$(DESTDIR)' '$(PREFIX)'
60
61 uninstall:
62         $(PYTHON) tools/install.py $@ '$(DESTDIR)' '$(PREFIX)'
63
64 clean:
65         -rm -rf out/Makefile node node_g out/$(BUILDTYPE)/node blog.html email.md
66         -find out/ -name '*.o' -o -name '*.a' | xargs rm -rf
67         -rm -rf node_modules
68
69 distclean:
70         -rm -rf out
71         -rm -f config.gypi
72         -rm -f config.mk
73         -rm -rf node node_g blog.html email.md
74         -rm -rf node_modules
75
76 test: all
77         $(PYTHON) tools/test.py --mode=release simple message
78         $(MAKE) jslint
79         $(MAKE) cpplint
80
81 test-http1: all
82         $(PYTHON) tools/test.py --mode=release --use-http1 simple message
83
84 test-valgrind: all
85         $(PYTHON) tools/test.py --mode=release --valgrind simple message
86
87 test/gc/node_modules/weak/build:
88         @if [ ! -f node ]; then make all; fi
89         ./node deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \
90                 --directory="$(shell pwd)/test/gc/node_modules/weak" \
91                 --nodedir="$(shell pwd)"
92
93 test-gc: all test/gc/node_modules/weak/build
94         $(PYTHON) tools/test.py --mode=release gc
95
96 test-all: all test/gc/node_modules/weak/build
97         $(PYTHON) tools/test.py --mode=debug,release
98         make test-npm
99
100 test-all-http1: all
101         $(PYTHON) tools/test.py --mode=debug,release --use-http1
102
103 test-all-valgrind: all
104         $(PYTHON) tools/test.py --mode=debug,release --valgrind
105
106 test-release: all
107         $(PYTHON) tools/test.py --mode=release
108
109 test-debug: all
110         $(PYTHON) tools/test.py --mode=debug
111
112 test-message: all
113         $(PYTHON) tools/test.py message
114
115 test-simple: all
116         $(PYTHON) tools/test.py simple
117
118 test-pummel: all
119         $(PYTHON) tools/test.py pummel
120
121 test-internet: all
122         $(PYTHON) tools/test.py internet
123
124 test-npm: node
125         ./node deps/npm/test/run.js
126
127 test-npm-publish: node
128         npm_package_config_publishtest=true ./node deps/npm/test/run.js
129
130 apidoc_sources = $(wildcard doc/api/*.markdown)
131 apidocs = $(addprefix out/,$(apidoc_sources:.markdown=.html)) \
132           $(addprefix out/,$(apidoc_sources:.markdown=.json))
133
134 apidoc_dirs = out/doc out/doc/api/ out/doc/api/assets out/doc/about out/doc/community out/doc/download out/doc/logos out/doc/images
135
136 apiassets = $(subst api_assets,api/assets,$(addprefix out/,$(wildcard doc/api_assets/*)))
137
138 doc_images = $(addprefix out/,$(wildcard doc/images/* doc/*.jpg doc/*.png))
139
140 website_files = \
141         out/doc/index.html    \
142         out/doc/v0.4_announcement.html   \
143         out/doc/cla.html      \
144         out/doc/sh_main.js    \
145         out/doc/sh_javascript.min.js \
146         out/doc/sh_vim-dark.css \
147         out/doc/sh.css \
148         out/doc/favicon.ico   \
149         out/doc/pipe.css \
150         out/doc/about/index.html \
151         out/doc/community/index.html \
152         out/doc/download/index.html \
153         out/doc/logos/index.html \
154         out/doc/changelog.html \
155         $(doc_images)
156
157 doc: $(apidoc_dirs) $(website_files) $(apiassets) $(apidocs) tools/doc/ blog node
158
159 blogclean:
160         rm -rf out/blog
161
162 blog: doc/blog out/Release/node tools/blog
163         out/Release/node tools/blog/generate.js doc/blog/ out/blog/ doc/blog.html doc/rss.xml
164
165 $(apidoc_dirs):
166         mkdir -p $@
167
168 out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets/
169         cp $< $@
170
171 out/doc/changelog.html: ChangeLog doc/changelog-head.html doc/changelog-foot.html tools/build-changelog.sh node
172         bash tools/build-changelog.sh
173
174 out/doc/%.html: doc/%.html node
175         cat $< | sed -e 's|__VERSION__|'$(VERSION)'|g' > $@
176
177 out/doc/%: doc/%
178         cp -r $< $@
179
180 out/doc/api/%.json: doc/api/%.markdown node
181         out/Release/node tools/doc/generate.js --format=json $< > $@
182
183 out/doc/api/%.html: doc/api/%.markdown node
184         out/Release/node tools/doc/generate.js --format=html --template=doc/template.html $< > $@
185
186 email.md: ChangeLog tools/email-footer.md
187         bash tools/changelog-head.sh | sed 's|^\* #|* \\#|g' > $@
188         cat tools/email-footer.md | sed -e 's|__VERSION__|'$(VERSION)'|g' >> $@
189
190 blog.html: email.md
191         cat $< | ./node tools/doc/node_modules/.bin/marked > $@
192
193 blog-upload: blog
194         rsync -r out/blog/ node@nodejs.org:~/web/nodejs.org/blog/
195
196 website-upload: doc
197         rsync -r out/doc/ node@nodejs.org:~/web/nodejs.org/
198         ssh node@nodejs.org '\
199     rm -f ~/web/nodejs.org/dist/latest &&\
200     ln -s $(VERSION) ~/web/nodejs.org/dist/latest &&\
201     rm -f ~/web/nodejs.org/docs/latest &&\
202     ln -s $(VERSION) ~/web/nodejs.org/docs/latest &&\
203     rm -f ~/web/nodejs.org/dist/node-latest.tar.gz &&\
204     ln -s $(VERSION)/node-$(VERSION).tar.gz ~/web/nodejs.org/dist/node-latest.tar.gz'
205
206 docopen: out/doc/api/all.html
207         -google-chrome out/doc/api/all.html
208
209 docclean:
210         -rm -rf out/doc
211
212 RAWVER=$(shell $(PYTHON) tools/getnodeversion.py)
213 VERSION=v$(RAWVER)
214 RELEASE=$(shell $(PYTHON) tools/getnodeisrelease.py)
215 PLATFORM=$(shell uname | tr '[:upper:]' '[:lower:]')
216 ifeq ($(findstring x86_64,$(shell uname -m)),x86_64)
217 DESTCPU ?= x64
218 else
219 DESTCPU ?= ia32
220 endif
221 ifeq ($(DESTCPU),x64)
222 ARCH=x64
223 else
224 ifeq ($(DESTCPU),arm)
225 ARCH=arm
226 else
227 ARCH=x86
228 endif
229 endif
230 TARNAME=node-$(VERSION)
231 ifdef NIGHTLY
232 TAG = nightly-$(NIGHTLY)
233 TARNAME=node-$(VERSION)-$(TAG)
234 endif
235 TARBALL=$(TARNAME).tar.gz
236 BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH)
237 BINARYTAR=$(BINARYNAME).tar.gz
238 PKG=out/$(TARNAME).pkg
239 packagemaker=/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker
240
241 PKGSRC=nodejs-$(DESTCPU)-$(RAWVER).tgz
242 ifdef NIGHTLY
243 PKGSRC=nodejs-$(DESTCPU)-$(RAWVER)-$(TAG).tgz
244 endif
245
246 dist: doc $(TARBALL) $(PKG)
247
248 PKGDIR=out/dist-osx
249
250 release-only:
251         @if [ "$(shell git status --porcelain | egrep -v '^\?\? ')" = "" ]; then \
252                 exit 0 ; \
253         else \
254           echo "" >&2 ; \
255                 echo "The git repository is not clean." >&2 ; \
256                 echo "Please commit changes before building release tarball." >&2 ; \
257                 echo "" >&2 ; \
258                 git status --porcelain | egrep -v '^\?\?' >&2 ; \
259                 echo "" >&2 ; \
260                 exit 1 ; \
261         fi
262         @if [ "$(NIGHTLY)" != "" -o "$(RELEASE)" = "1" ]; then \
263                 exit 0; \
264         else \
265           echo "" >&2 ; \
266                 echo "#NODE_VERSION_IS_RELEASE is set to $(RELEASE)." >&2 ; \
267           echo "Did you remember to update src/node_version.cc?" >&2 ; \
268           echo "" >&2 ; \
269                 exit 1 ; \
270         fi
271
272 pkg: $(PKG)
273
274 $(PKG): release-only
275         rm -rf $(PKGDIR)
276         rm -rf out/deps out/Release
277         $(PYTHON) ./configure --without-snapshot --dest-cpu=ia32 --tag=$(TAG)
278         $(MAKE) install V=$(V) DESTDIR=$(PKGDIR)/32
279         rm -rf out/deps out/Release
280         $(PYTHON) ./configure --without-snapshot --dest-cpu=x64 --tag=$(TAG)
281         $(MAKE) install V=$(V) DESTDIR=$(PKGDIR)
282         SIGN="$(APP_SIGN)" PKGDIR="$(PKGDIR)" bash tools/osx-codesign.sh
283         lipo $(PKGDIR)/32/usr/local/bin/node \
284                 $(PKGDIR)/usr/local/bin/node \
285                 -output $(PKGDIR)/usr/local/bin/node-universal \
286                 -create
287         mv $(PKGDIR)/usr/local/bin/node-universal $(PKGDIR)/usr/local/bin/node
288         rm -rf $(PKGDIR)/32
289         $(packagemaker) \
290                 --id "org.nodejs.Node" \
291                 --doc tools/osx-pkg.pmdoc \
292                 --out $(PKG)
293         SIGN="$(INT_SIGN)" PKG="$(PKG)" bash tools/osx-productsign.sh
294
295 $(TARBALL): release-only node doc
296         git archive --format=tar --prefix=$(TARNAME)/ HEAD | tar xf -
297         mkdir -p $(TARNAME)/doc/api
298         cp doc/node.1 $(TARNAME)/doc/node.1
299         cp -r out/doc/api/* $(TARNAME)/doc/api/
300         rm -rf $(TARNAME)/deps/v8/test # too big
301         rm -rf $(TARNAME)/doc/images # too big
302         find $(TARNAME)/ -type l | xargs rm # annoying on windows
303         tar -cf $(TARNAME).tar $(TARNAME)
304         rm -rf $(TARNAME)
305         gzip -f -9 $(TARNAME).tar
306
307 tar: $(TARBALL)
308
309 $(BINARYTAR): release-only
310         rm -rf $(BINARYNAME)
311         rm -rf out/deps out/Release
312         $(PYTHON) ./configure --prefix=/ --without-snapshot --dest-cpu=$(DESTCPU) --tag=$(TAG) $(CONFIG_FLAGS)
313         $(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1
314         cp README.md $(BINARYNAME)
315         cp LICENSE $(BINARYNAME)
316         cp ChangeLog $(BINARYNAME)
317         tar -cf $(BINARYNAME).tar $(BINARYNAME)
318         rm -rf $(BINARYNAME)
319         gzip -f -9 $(BINARYNAME).tar
320
321 binary: $(BINARYTAR)
322
323 $(PKGSRC): release-only
324         rm -rf dist out
325         $(PYTHON) configure --prefix=/ --without-snapshot \
326                 --dest-cpu=$(DESTCPU) --tag=$(TAG) $(CONFIG_FLAGS)
327         $(MAKE) install DESTDIR=dist
328         (cd dist; find * -type f | sort) > packlist
329         pkg_info -X pkg_install | \
330                 egrep '^(MACHINE_ARCH|OPSYS|OS_VERSION|PKGTOOLS_VERSION)' > build-info
331         pkg_create -B build-info -c tools/pkgsrc/comment -d tools/pkgsrc/description \
332                 -f packlist -I /opt/local -p dist -U $(PKGSRC)
333
334 pkgsrc: $(PKGSRC)
335
336 dist-upload: $(TARBALL) $(PKG)
337         ssh node@nodejs.org mkdir -p web/nodejs.org/dist/$(VERSION)
338         scp $(TARBALL) node@nodejs.org:~/web/nodejs.org/dist/$(VERSION)/$(TARBALL)
339         scp $(PKG) node@nodejs.org:~/web/nodejs.org/dist/$(VERSION)/$(TARNAME).pkg
340
341 wrkclean:
342         $(MAKE) -C tools/wrk/ clean
343         rm tools/wrk/wrk
344
345 wrk: tools/wrk/wrk
346 tools/wrk/wrk:
347         $(MAKE) -C tools/wrk/
348
349 bench-net: all
350         @$(NODE) benchmark/common.js net
351
352 bench-crypto: all
353         @$(NODE) benchmark/common.js crypto
354
355 bench-tls: all
356         @$(NODE) benchmark/common.js tls
357
358 bench-http: wrk all
359         @$(NODE) benchmark/common.js http
360
361 bench-fs: all
362         @$(NODE) benchmark/common.js fs
363
364 bench-misc: all
365         @$(MAKE) -C benchmark/misc/function_call/
366         @$(NODE) benchmark/common.js misc
367
368 bench-array: all
369         @$(NODE) benchmark/common.js arrays
370
371 bench-buffer: all
372         @$(NODE) benchmark/common.js buffers
373
374 bench-all: bench bench-misc bench-array bench-buffer
375
376 bench: bench-net bench-http bench-fs bench-tls
377
378 bench-http-simple:
379          benchmark/http_simple_bench.sh
380
381 bench-idle:
382         ./node benchmark/idle_server.js &
383         sleep 1
384         ./node benchmark/idle_clients.js &
385
386 jslintfix:
387         PYTHONPATH=tools/closure_linter/ $(PYTHON) tools/closure_linter/closure_linter/fixjsstyle.py --strict --nojsdoc -r lib/ -r src/ --exclude_files lib/punycode.js
388
389 jslint:
390         PYTHONPATH=tools/closure_linter/ $(PYTHON) tools/closure_linter/closure_linter/gjslint.py --unix_mode --strict --nojsdoc -r lib/ -r src/ --exclude_files lib/punycode.js
391
392 CPPLINT_EXCLUDE ?=
393 CPPLINT_EXCLUDE += src/node_dtrace.cc
394 CPPLINT_EXCLUDE += src/node_dtrace.cc
395 CPPLINT_EXCLUDE += src/node_root_certs.h
396 CPPLINT_EXCLUDE += src/node_win32_perfctr_provider.cc
397 CPPLINT_EXCLUDE += src/queue.h
398 CPPLINT_EXCLUDE += src/tree.h
399 CPPLINT_EXCLUDE += src/v8abbr.h
400
401 CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard src/*.cc src/*.h src/*.c))
402
403 cpplint:
404         @$(PYTHON) tools/cpplint.py $(CPPLINT_FILES)
405
406 lint: jslint cpplint
407
408 .PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean check uninstall install install-includes install-bin all staticlib dynamiclib test test-all website-upload pkg blog blogclean tar binary release-only bench-http-simple bench-idle bench-all bench bench-misc bench-array bench-buffer bench-net bench-http bench-fs bench-tls