10 STAGINGSERVER ?= node-www
12 OSTYPE := $(shell uname -s | tr '[A-Z]' '[a-z]')
15 EXEEXT := $(shell $(PYTHON) -c \
16 "import sys; print('.exe' if sys.platform == 'win32' else '')")
18 NODE ?= ./node$(EXEEXT)
19 NODE_EXE = node$(EXEEXT)
20 NODE_G_EXE = node_g$(EXEEXT)
22 # Flags for packaging.
23 BUILD_DOWNLOAD_FLAGS ?= --download=all
24 BUILD_INTL_FLAGS ?= --with-intl=small-icu
25 BUILD_RELEASE_FLAGS ?= $(BUILD_DOWNLOAD_FLAGS) $(BUILD_INTL_FLAGS)
27 # Default to verbose builds.
28 # To do quiet/pretty builds, run `make V=` to set V to an empty string,
29 # or set the V environment variable to an empty string.
32 # BUILDTYPE=Debug builds both release and debug builds. If you want to compile
33 # just the debug build, run `make -C out BUILDTYPE=Debug` instead.
34 ifeq ($(BUILDTYPE),Release)
35 all: out/Makefile $(NODE_EXE)
37 all: out/Makefile $(NODE_EXE) $(NODE_G_EXE)
40 # The .PHONY is needed to ensure that we recursively use the out/Makefile
41 # to check for changes.
42 .PHONY: $(NODE_EXE) $(NODE_G_EXE)
44 $(NODE_EXE): config.gypi out/Makefile
45 $(MAKE) -C out BUILDTYPE=Release V=$(V)
46 ln -fs out/Release/$(NODE_EXE) $@
48 $(NODE_G_EXE): config.gypi out/Makefile
49 $(MAKE) -C out BUILDTYPE=Debug V=$(V)
50 ln -fs out/Debug/$(NODE_EXE) $@
52 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
53 $(PYTHON) tools/gyp_node.py -f make
55 config.gypi: configure
57 $(error Stale $@, please re-run ./configure)
59 $(error No $@, please run ./configure first)
63 $(PYTHON) tools/install.py $@ '$(DESTDIR)' '$(PREFIX)'
66 $(PYTHON) tools/install.py $@ '$(DESTDIR)' '$(PREFIX)'
69 -rm -rf out/Makefile $(NODE_EXE) $(NODE_G_EXE) out/$(BUILDTYPE)/$(NODE_EXE)
70 @if [ -d out ]; then find out/ -name '*.o' -o -name '*.a' | xargs rm -rf; fi
76 -rm -f config.gypi icu_config.gypi
78 -rm -rf $(NODE_EXE) $(NODE_G_EXE)
81 -rm -rf deps/icu4c*.tgz deps/icu4c*.zip deps/icu-tmp
82 -rm -f $(BINARYTAR).* $(TARBALL).*
89 test: | cctest # Depends on 'all'.
90 $(PYTHON) tools/test.py --mode=release message parallel sequential -J
95 $(PYTHON) tools/test.py --mode=release parallel -J
98 $(PYTHON) tools/test.py --mode=release --valgrind sequential parallel message
100 test/gc/node_modules/weak/build/Release/weakref.node: $(NODE_EXE)
101 $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \
102 --directory="$(shell pwd)/test/gc/node_modules/weak" \
103 --nodedir="$(shell pwd)"
105 # Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale.
106 test/addons/.docbuildstamp: doc/api/addons.markdown
107 $(RM) -r test/addons/doc-*/
108 $(NODE) tools/doc/addon-verify.js
111 ADDONS_BINDING_GYPS := \
112 $(filter-out test/addons/doc-*/binding.gyp, \
113 $(wildcard test/addons/*/binding.gyp))
115 # Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale.
116 test/addons/.buildstamp: $(ADDONS_BINDING_GYPS) | test/addons/.docbuildstamp
117 # Cannot use $(wildcard test/addons/*/) here, it's evaluated before
118 # embedded addons have been generated from the documentation.
119 for dirname in test/addons/*/; do \
120 $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \
121 --directory="$$PWD/$$dirname" \
126 # .buildstamp and .docbuildstamp need $(NODE_EXE) but cannot depend on it
127 # directly because it calls make recursively. The parent make cannot know
128 # if the subprocess touched anything so it pessimistically assumes that
129 # .buildstamp and .docbuildstamp are out of date and need a rebuild.
130 # Just goes to show that recursive make really is harmful...
131 # TODO(bnoordhuis) Force rebuild after gyp or node-gyp update.
132 build-addons: $(NODE_EXE) test/addons/.buildstamp
134 test-gc: all test/gc/node_modules/weak/build/Release/weakref.node
135 $(PYTHON) tools/test.py --mode=release gc
137 test-build: | all build-addons
139 test-all: test-build test/gc/node_modules/weak/build/Release/weakref.node
140 $(PYTHON) tools/test.py --mode=debug,release
142 test-all-valgrind: test-build
143 $(PYTHON) tools/test.py --mode=debug,release --valgrind
145 test-ci: | build-addons
146 $(PYTHON) tools/test.py -p tap --logfile test.tap --mode=release --flaky-tests=$(FLAKY_TESTS) \
147 $(TEST_CI_ARGS) addons message parallel sequential
149 test-release: test-build
150 $(PYTHON) tools/test.py --mode=release
152 test-debug: test-build
153 $(PYTHON) tools/test.py --mode=debug
155 test-message: test-build
156 $(PYTHON) tools/test.py message
158 test-simple: | cctest # Depends on 'all'.
159 $(PYTHON) tools/test.py parallel sequential
162 $(PYTHON) tools/test.py pummel
165 $(PYTHON) tools/test.py internet
168 $(PYTHON) tools/test.py debugger
170 test-npm: $(NODE_EXE)
171 NODE=$(NODE) tools/test-npm.sh
173 test-npm-publish: $(NODE_EXE)
174 npm_package_config_publishtest=true $(NODE) deps/npm/test/run.js
176 test-addons: test-build
177 $(PYTHON) tools/test.py --mode=release addons
180 $(MAKE) --directory=tools faketime
181 $(PYTHON) tools/test.py --mode=release timers
184 $(MAKE) --directory=tools clean
186 apidoc_sources = $(wildcard doc/api/*.markdown)
187 apidocs = $(addprefix out/,$(apidoc_sources:.markdown=.html)) \
188 $(addprefix out/,$(apidoc_sources:.markdown=.json))
190 apidoc_dirs = out/doc out/doc/api/ out/doc/api/assets
192 apiassets = $(subst api_assets,api/assets,$(addprefix out/,$(wildcard doc/api_assets/*)))
194 doc: $(apidoc_dirs) $(apiassets) $(apidocs) tools/doc/ $(NODE_EXE)
199 out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets/
205 out/doc/api/%.json: doc/api/%.markdown $(NODE_EXE)
206 $(NODE) tools/doc/generate.js --format=json $< > $@
208 out/doc/api/%.html: doc/api/%.markdown $(NODE_EXE)
209 $(NODE) tools/doc/generate.js --format=html --template=doc/template.html $< > $@
211 docopen: out/doc/api/all.html
212 -google-chrome out/doc/api/all.html
218 $(PYTHON) ./configure $(CONFIG_FLAGS)
222 RAWVER=$(shell $(PYTHON) tools/getnodeversion.py)
225 # For nightly builds, you must set DISTTYPE to "nightly", "next-nightly" or
226 # "custom". For the nightly and next-nightly case, you need to set DATESTRING
227 # and COMMIT in order to properly name the build.
228 # For the rc case you need to set CUSTOMTAG to an appropriate CUSTOMTAG number
233 ifeq ($(DISTTYPE),release)
234 FULLVERSION=$(VERSION)
235 else # ifeq ($(DISTTYPE),release)
236 ifeq ($(DISTTYPE),custom)
238 $(error CUSTOMTAG is not set for DISTTYPE=custom)
239 endif # ifndef CUSTOMTAG
241 else # ifeq ($(DISTTYPE),custom)
243 $(error DATESTRING is not set for nightly)
244 endif # ifndef DATESTRING
246 $(error COMMIT is not set for nightly)
247 endif # ifndef COMMIT
248 ifneq ($(DISTTYPE),nightly)
249 ifneq ($(DISTTYPE),next-nightly)
250 $(error DISTTYPE is not release, custom, nightly or next-nightly)
251 endif # ifneq ($(DISTTYPE),next-nightly)
252 endif # ifneq ($(DISTTYPE),nightly)
253 TAG=$(DISTTYPE)$(DATESTRING)$(COMMIT)
254 endif # ifeq ($(DISTTYPE),custom)
255 FULLVERSION=$(VERSION)-$(TAG)
256 endif # ifeq ($(DISTTYPE),release)
258 DISTTYPEDIR ?= $(DISTTYPE)
259 RELEASE=$(shell sed -ne 's/\#define NODE_VERSION_IS_RELEASE \([01]\)/\1/p' src/node_version.h)
260 PLATFORM=$(shell uname | tr '[:upper:]' '[:lower:]')
261 NPMVERSION=v$(shell cat deps/npm/package.json | grep '"version"' | sed 's/^[^:]*: "\([^"]*\)",.*/\1/')
263 ifeq ($(findstring x86_64,$(shell uname -m)),x86_64)
268 ifeq ($(DESTCPU),x64)
271 ifeq ($(DESTCPU),arm)
274 ifeq ($(DESTCPU),ppc64)
277 ifeq ($(DESTCPU),ppc)
286 # enforce "x86" over "ia32" as the generally accepted way of referring to 32-bit intel
290 ifeq ($(DESTCPU),ia32)
294 TARNAME=node-$(FULLVERSION)
295 TARBALL=$(TARNAME).tar
296 BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH)
297 BINARYTAR=$(BINARYNAME).tar
298 # OSX doesn't have xz installed by default, http://macpkg.sourceforge.net/
299 XZ=$(shell which xz > /dev/null 2>&1; echo $$?)
302 PACKAGEMAKER ?= /Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker
306 @if [ "$(shell git status --porcelain | egrep -v '^\?\? ')" = "" ]; then \
310 echo "The git repository is not clean." >&2 ; \
311 echo "Please commit changes before building release tarball." >&2 ; \
313 git status --porcelain | egrep -v '^\?\?' >&2 ; \
317 @if [ "$(DISTTYPE)" != "release" -o "$(RELEASE)" = "1" ]; then \
321 echo "#NODE_VERSION_IS_RELEASE is set to $(RELEASE)." >&2 ; \
322 echo "Did you remember to update src/node_version.h?" >&2 ; \
329 rm -rf out/deps out/Release
330 $(PYTHON) ./configure \
333 --release-urlbase=$(RELEASE_URLBASE) \
334 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
335 $(MAKE) install V=$(V) DESTDIR=$(PKGDIR)
336 SIGN="$(CODESIGN_CERT)" PKGDIR="$(PKGDIR)" bash tools/osx-codesign.sh
337 cat tools/osx-pkg.pmdoc/index.xml.tmpl \
338 | sed -E "s/\\{nodeversion\\}/$(FULLVERSION)/g" \
339 | sed -E "s/\\{npmversion\\}/$(NPMVERSION)/g" \
340 > tools/osx-pkg.pmdoc/index.xml
342 --id "org.nodejs.pkg" \
343 --doc tools/osx-pkg.pmdoc \
345 SIGN="$(PRODUCTSIGN_CERT)" PKG="$(PKG)" bash tools/osx-productsign.sh
350 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
351 chmod 664 node-$(FULLVERSION).pkg
352 scp -p node-$(FULLVERSION).pkg $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).pkg
353 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).pkg.done"
355 $(TARBALL): release-only $(NODE_EXE) doc
356 git checkout-index -a -f --prefix=$(TARNAME)/
357 mkdir -p $(TARNAME)/doc/api
358 cp doc/node.1 $(TARNAME)/doc/node.1
359 cp -r out/doc/api/* $(TARNAME)/doc/api/
360 rm -rf $(TARNAME)/deps/v8/{test,samples,tools/profviz} # too big
361 rm -rf $(TARNAME)/doc/images # too big
362 rm -rf $(TARNAME)/deps/uv/{docs,samples,test}
363 rm -rf $(TARNAME)/deps/openssl/{doc,demos,test}
364 rm -rf $(TARNAME)/deps/zlib/contrib # too big, unused
365 find $(TARNAME)/ -type l | xargs rm # annoying on windows
366 tar -cf $(TARNAME).tar $(TARNAME)
368 gzip -c -f -9 $(TARNAME).tar > $(TARNAME).tar.gz
370 xz -c -f -$(XZ_COMPRESSION) $(TARNAME).tar > $(TARNAME).tar.xz
377 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
378 chmod 664 node-$(FULLVERSION).tar.gz
379 scp -p node-$(FULLVERSION).tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.gz
380 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.gz.done"
382 chmod 664 node-$(FULLVERSION).tar.xz
383 scp -p node-$(FULLVERSION).tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.xz
384 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.xz.done"
388 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
389 chmod -R ug=rw-x+X,o=r+X out/doc/
390 scp -pr out/doc/ $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/docs/
391 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/docs.done"
393 $(TARBALL)-headers: config.gypi release-only
394 $(PYTHON) ./configure \
396 --dest-cpu=$(DESTCPU) \
398 --release-urlbase=$(RELEASE_URLBASE) \
399 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
400 HEADERS_ONLY=1 $(PYTHON) tools/install.py install '$(TARNAME)' '/'
401 find $(TARNAME)/ -type l | xargs rm # annoying on windows
402 tar -cf $(TARNAME)-headers.tar $(TARNAME)
404 gzip -c -f -9 $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.gz
406 xz -c -f -$(XZ_COMPRESSION) $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.xz
408 rm $(TARNAME)-headers.tar
410 tar-headers: $(TARBALL)-headers
412 tar-headers-upload: tar-headers
413 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
414 chmod 664 $(TARNAME)-headers.tar.gz
415 scp -p $(TARNAME)-headers.tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz
416 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz.done"
418 chmod 664 $(TARNAME)-headers.tar.xz
419 scp -p $(TARNAME)-headers.tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz
420 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz.done"
423 $(BINARYTAR): release-only
425 rm -rf out/deps out/Release
426 $(PYTHON) ./configure \
428 --dest-cpu=$(DESTCPU) \
430 --release-urlbase=$(RELEASE_URLBASE) \
431 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
432 $(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1
433 cp README.md $(BINARYNAME)
434 cp LICENSE $(BINARYNAME)
435 cp CHANGELOG.md $(BINARYNAME)
436 tar -cf $(BINARYNAME).tar $(BINARYNAME)
438 gzip -c -f -9 $(BINARYNAME).tar > $(BINARYNAME).tar.gz
440 xz -c -f -$(XZ_COMPRESSION) $(BINARYNAME).tar > $(BINARYNAME).tar.xz
446 binary-upload: binary
447 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
448 chmod 664 node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz
449 scp -p node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz
450 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz.done"
452 chmod 664 node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz
453 scp -p node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz
454 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz.done"
457 haswrk=$(shell which wrk > /dev/null 2>&1; echo $$?)
460 @echo "please install wrk before proceeding. More information can be found in benchmark/README.md." >&2
465 @$(NODE) benchmark/common.js net
468 @$(NODE) benchmark/common.js crypto
471 @$(NODE) benchmark/common.js tls
474 @$(NODE) benchmark/common.js http
477 @$(NODE) benchmark/common.js fs
480 @$(MAKE) -C benchmark/misc/function_call/
481 @$(NODE) benchmark/common.js misc
484 @$(NODE) benchmark/common.js arrays
487 @$(NODE) benchmark/common.js buffers
490 @$(NODE) benchmark/common.js url
493 @$(NODE) benchmark/common.js events
495 bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events
497 bench: bench-net bench-http bench-fs bench-tls
500 benchmark/http_simple_bench.sh
503 $(NODE) benchmark/idle_server.js &
505 $(NODE) benchmark/idle_clients.js &
508 $(NODE) tools/eslint/bin/eslint.js src lib test --rulesdir tools/eslint-rules --reset --quiet
511 CPPLINT_EXCLUDE += src/node_lttng.cc
512 CPPLINT_EXCLUDE += src/node_root_certs.h
513 CPPLINT_EXCLUDE += src/node_lttng_tp.h
514 CPPLINT_EXCLUDE += src/node_win32_perfctr_provider.cc
515 CPPLINT_EXCLUDE += src/queue.h
516 CPPLINT_EXCLUDE += src/tree.h
517 CPPLINT_EXCLUDE += src/v8abbr.h
518 CPPLINT_EXCLUDE += $(wildcard test/addons/doc-*/*.cc test/addons/doc-*/*.h)
520 CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \
521 deps/debugger-agent/include/* \
522 deps/debugger-agent/src/* \
533 @$(PYTHON) tools/cpplint.py $(CPPLINT_FILES)
537 .PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean \
538 check uninstall install install-includes install-bin all staticlib \
539 dynamiclib test test-all test-addons build-addons website-upload pkg \
540 blog blogclean tar binary release-only bench-http-simple bench-idle \
541 bench-all bench bench-misc bench-array bench-buffer bench-net \
542 bench-http bench-fs bench-tls cctest run-ci