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