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