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' -o -name '*.d' | xargs rm -rf; fi
72 @if [ -d deps/icu ]; then echo deleting deps/icu; rm -rf deps/icu; fi
77 -rm -f config.gypi icu_config.gypi config_fips.gypi
79 -rm -rf $(NODE_EXE) $(NODE_G_EXE)
82 -rm -rf deps/icu4c*.tgz deps/icu4c*.zip deps/icu-tmp
83 -rm -f $(BINARYTAR).* $(TARBALL).*
90 test: | cctest # Depends on 'all'.
91 $(PYTHON) tools/test.py --mode=release message parallel sequential -J
96 $(PYTHON) tools/test.py --mode=release parallel -J
99 $(PYTHON) tools/test.py --mode=release --valgrind sequential parallel message
101 test/gc/node_modules/weak/build/Release/weakref.node: $(NODE_EXE)
102 $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \
103 --directory="$(shell pwd)/test/gc/node_modules/weak" \
104 --nodedir="$(shell pwd)"
106 # Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale.
107 test/addons/.docbuildstamp: doc/api/addons.markdown
108 $(RM) -r test/addons/??_*/
109 $(NODE) tools/doc/addon-verify.js
112 ADDONS_BINDING_GYPS := \
113 $(filter-out test/addons/??_*/binding.gyp, \
114 $(wildcard test/addons/*/binding.gyp))
116 # Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale.
117 test/addons/.buildstamp: $(ADDONS_BINDING_GYPS) | test/addons/.docbuildstamp
118 # Cannot use $(wildcard test/addons/*/) here, it's evaluated before
119 # embedded addons have been generated from the documentation.
120 for dirname in test/addons/*/; do \
121 $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \
122 --directory="$$PWD/$$dirname" \
127 # .buildstamp and .docbuildstamp need $(NODE_EXE) but cannot depend on it
128 # directly because it calls make recursively. The parent make cannot know
129 # if the subprocess touched anything so it pessimistically assumes that
130 # .buildstamp and .docbuildstamp are out of date and need a rebuild.
131 # Just goes to show that recursive make really is harmful...
132 # TODO(bnoordhuis) Force rebuild after gyp or node-gyp update.
133 build-addons: $(NODE_EXE) test/addons/.buildstamp
135 test-gc: all test/gc/node_modules/weak/build/Release/weakref.node
136 $(PYTHON) tools/test.py --mode=release gc
138 test-build: | all build-addons
140 test-all: test-build test/gc/node_modules/weak/build/Release/weakref.node
141 $(PYTHON) tools/test.py --mode=debug,release
143 test-all-valgrind: test-build
144 $(PYTHON) tools/test.py --mode=debug,release --valgrind
146 test-ci: | build-addons
147 $(PYTHON) tools/test.py -p tap --logfile test.tap --mode=release --flaky-tests=$(FLAKY_TESTS) \
148 $(TEST_CI_ARGS) addons message parallel sequential
150 test-release: test-build
151 $(PYTHON) tools/test.py --mode=release
153 test-debug: test-build
154 $(PYTHON) tools/test.py --mode=debug
156 test-message: test-build
157 $(PYTHON) tools/test.py message
159 test-simple: | cctest # Depends on 'all'.
160 $(PYTHON) tools/test.py parallel sequential
163 $(PYTHON) tools/test.py pummel
166 $(PYTHON) tools/test.py internet
169 $(PYTHON) tools/test.py debugger
171 test-known-issues: all
172 $(PYTHON) tools/test.py known_issues --expect-fail
174 test-npm: $(NODE_EXE)
175 NODE=$(NODE) tools/test-npm.sh
177 test-npm-publish: $(NODE_EXE)
178 npm_package_config_publishtest=true $(NODE) deps/npm/test/run.js
180 test-addons: test-build
181 $(PYTHON) tools/test.py --mode=release addons
184 $(MAKE) --directory=tools faketime
185 $(PYTHON) tools/test.py --mode=release timers
188 $(MAKE) --directory=tools clean
190 apidoc_sources = $(wildcard doc/api/*.markdown)
191 apidocs = $(addprefix out/,$(apidoc_sources:.markdown=.html)) \
192 $(addprefix out/,$(apidoc_sources:.markdown=.json))
194 apidoc_dirs = out/doc out/doc/api/ out/doc/api/assets
196 apiassets = $(subst api_assets,api/assets,$(addprefix out/,$(wildcard doc/api_assets/*)))
198 doc: $(apidoc_dirs) $(apiassets) $(apidocs) tools/doc/ $(NODE_EXE)
203 out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets/
209 out/doc/api/%.json: doc/api/%.markdown $(NODE_EXE)
210 $(NODE) tools/doc/generate.js --format=json $< > $@
212 out/doc/api/%.html: doc/api/%.markdown $(NODE_EXE)
213 $(NODE) tools/doc/generate.js --format=html --template=doc/template.html $< > $@
215 docopen: out/doc/api/all.html
216 -google-chrome out/doc/api/all.html
222 $(PYTHON) ./configure $(CONFIG_FLAGS)
226 RAWVER=$(shell $(PYTHON) tools/getnodeversion.py)
229 # For nightly builds, you must set DISTTYPE to "nightly", "next-nightly" or
230 # "custom". For the nightly and next-nightly case, you need to set DATESTRING
231 # and COMMIT in order to properly name the build.
232 # For the rc case you need to set CUSTOMTAG to an appropriate CUSTOMTAG number
237 ifeq ($(DISTTYPE),release)
238 FULLVERSION=$(VERSION)
239 else # ifeq ($(DISTTYPE),release)
240 ifeq ($(DISTTYPE),custom)
242 $(error CUSTOMTAG is not set for DISTTYPE=custom)
243 endif # ifndef CUSTOMTAG
245 else # ifeq ($(DISTTYPE),custom)
247 $(error DATESTRING is not set for nightly)
248 endif # ifndef DATESTRING
250 $(error COMMIT is not set for nightly)
251 endif # ifndef COMMIT
252 ifneq ($(DISTTYPE),nightly)
253 ifneq ($(DISTTYPE),next-nightly)
254 $(error DISTTYPE is not release, custom, nightly or next-nightly)
255 endif # ifneq ($(DISTTYPE),next-nightly)
256 endif # ifneq ($(DISTTYPE),nightly)
257 TAG=$(DISTTYPE)$(DATESTRING)$(COMMIT)
258 endif # ifeq ($(DISTTYPE),custom)
259 FULLVERSION=$(VERSION)-$(TAG)
260 endif # ifeq ($(DISTTYPE),release)
262 DISTTYPEDIR ?= $(DISTTYPE)
263 RELEASE=$(shell sed -ne 's/\#define NODE_VERSION_IS_RELEASE \([01]\)/\1/p' src/node_version.h)
264 PLATFORM=$(shell uname | tr '[:upper:]' '[:lower:]')
265 NPMVERSION=v$(shell cat deps/npm/package.json | grep '"version"' | sed 's/^[^:]*: "\([^"]*\)",.*/\1/')
267 ifeq ($(findstring x86_64,$(shell uname -m)),x86_64)
272 ifeq ($(DESTCPU),x64)
275 ifeq ($(DESTCPU),arm)
278 ifeq ($(DESTCPU),aarch64)
281 ifeq ($(DESTCPU),ppc64)
284 ifeq ($(DESTCPU),ppc)
294 # enforce "x86" over "ia32" as the generally accepted way of referring to 32-bit intel
298 ifeq ($(DESTCPU),ia32)
302 TARNAME=node-$(FULLVERSION)
303 TARBALL=$(TARNAME).tar
304 BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH)
305 BINARYTAR=$(BINARYNAME).tar
306 # OSX doesn't have xz installed by default, http://macpkg.sourceforge.net/
307 XZ=$(shell which xz > /dev/null 2>&1; echo $$?)
310 PACKAGEMAKER ?= /Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker
314 @if [ "$(shell git status --porcelain | egrep -v '^\?\? ')" = "" ]; then \
318 echo "The git repository is not clean." >&2 ; \
319 echo "Please commit changes before building release tarball." >&2 ; \
321 git status --porcelain | egrep -v '^\?\?' >&2 ; \
325 @if [ "$(DISTTYPE)" != "release" -o "$(RELEASE)" = "1" ]; then \
329 echo "#NODE_VERSION_IS_RELEASE is set to $(RELEASE)." >&2 ; \
330 echo "Did you remember to update src/node_version.h?" >&2 ; \
337 rm -rf out/deps out/Release
338 $(PYTHON) ./configure \
341 --release-urlbase=$(RELEASE_URLBASE) \
342 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
343 $(MAKE) install V=$(V) DESTDIR=$(PKGDIR)
344 SIGN="$(CODESIGN_CERT)" PKGDIR="$(PKGDIR)" bash tools/osx-codesign.sh
345 cat tools/osx-pkg.pmdoc/index.xml.tmpl \
346 | sed -E "s/\\{nodeversion\\}/$(FULLVERSION)/g" \
347 | sed -E "s/\\{npmversion\\}/$(NPMVERSION)/g" \
348 > tools/osx-pkg.pmdoc/index.xml
350 --id "org.nodejs.pkg" \
351 --doc tools/osx-pkg.pmdoc \
353 SIGN="$(PRODUCTSIGN_CERT)" PKG="$(PKG)" bash tools/osx-productsign.sh
358 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
359 chmod 664 node-$(FULLVERSION).pkg
360 scp -p node-$(FULLVERSION).pkg $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).pkg
361 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).pkg.done"
363 $(TARBALL): release-only $(NODE_EXE) doc
364 git checkout-index -a -f --prefix=$(TARNAME)/
365 mkdir -p $(TARNAME)/doc/api
366 cp doc/node.1 $(TARNAME)/doc/node.1
367 cp -r out/doc/api/* $(TARNAME)/doc/api/
368 rm -rf $(TARNAME)/deps/v8/{test,samples,tools/profviz} # too big
369 rm -rf $(TARNAME)/doc/images # too big
370 rm -rf $(TARNAME)/deps/uv/{docs,samples,test}
371 rm -rf $(TARNAME)/deps/openssl/{doc,demos,test}
372 rm -rf $(TARNAME)/deps/zlib/contrib # too big, unused
373 rm -rf $(TARNAME)/.github # github issue templates
374 find $(TARNAME)/ -type l | xargs rm # annoying on windows
375 tar -cf $(TARNAME).tar $(TARNAME)
377 gzip -c -f -9 $(TARNAME).tar > $(TARNAME).tar.gz
379 xz -c -f -$(XZ_COMPRESSION) $(TARNAME).tar > $(TARNAME).tar.xz
386 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
387 chmod 664 node-$(FULLVERSION).tar.gz
388 scp -p node-$(FULLVERSION).tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.gz
389 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.gz.done"
391 chmod 664 node-$(FULLVERSION).tar.xz
392 scp -p node-$(FULLVERSION).tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.xz
393 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.xz.done"
397 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
398 chmod -R ug=rw-x+X,o=r+X out/doc/
399 scp -pr out/doc/ $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/docs/
400 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/docs.done"
402 $(TARBALL)-headers: config.gypi release-only
403 $(PYTHON) ./configure \
405 --dest-cpu=$(DESTCPU) \
407 --release-urlbase=$(RELEASE_URLBASE) \
408 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
409 HEADERS_ONLY=1 $(PYTHON) tools/install.py install '$(TARNAME)' '/'
410 find $(TARNAME)/ -type l | xargs rm # annoying on windows
411 tar -cf $(TARNAME)-headers.tar $(TARNAME)
413 gzip -c -f -9 $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.gz
415 xz -c -f -$(XZ_COMPRESSION) $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.xz
417 rm $(TARNAME)-headers.tar
419 tar-headers: $(TARBALL)-headers
421 tar-headers-upload: tar-headers
422 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
423 chmod 664 $(TARNAME)-headers.tar.gz
424 scp -p $(TARNAME)-headers.tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz
425 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz.done"
427 chmod 664 $(TARNAME)-headers.tar.xz
428 scp -p $(TARNAME)-headers.tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz
429 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz.done"
432 $(BINARYTAR): release-only
434 rm -rf out/deps out/Release
435 $(PYTHON) ./configure \
437 --dest-cpu=$(DESTCPU) \
439 --release-urlbase=$(RELEASE_URLBASE) \
440 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
441 $(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1
442 cp README.md $(BINARYNAME)
443 cp LICENSE $(BINARYNAME)
444 cp CHANGELOG.md $(BINARYNAME)
445 tar -cf $(BINARYNAME).tar $(BINARYNAME)
447 gzip -c -f -9 $(BINARYNAME).tar > $(BINARYNAME).tar.gz
449 xz -c -f -$(XZ_COMPRESSION) $(BINARYNAME).tar > $(BINARYNAME).tar.xz
455 binary-upload: binary
456 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
457 chmod 664 node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz
458 scp -p node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz
459 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz.done"
461 chmod 664 node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz
462 scp -p node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz
463 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz.done"
466 haswrk=$(shell which wrk > /dev/null 2>&1; echo $$?)
469 @echo "please install wrk before proceeding. More information can be found in benchmark/README.md." >&2
474 @$(NODE) benchmark/common.js net
477 @$(NODE) benchmark/common.js crypto
480 @$(NODE) benchmark/common.js tls
483 @$(NODE) benchmark/common.js http
486 @$(NODE) benchmark/common.js fs
489 @$(MAKE) -C benchmark/misc/function_call/
490 @$(NODE) benchmark/common.js misc
493 @$(NODE) benchmark/common.js arrays
496 @$(NODE) benchmark/common.js buffers
499 @$(NODE) benchmark/common.js url
502 @$(NODE) benchmark/common.js events
505 @$(NODE) benchmark/common.js util
507 bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events
509 bench: bench-net bench-http bench-fs bench-tls
514 benchmark/http_simple_bench.sh
517 $(NODE) benchmark/idle_server.js &
519 $(NODE) benchmark/idle_clients.js &
522 $(NODE) tools/eslint/bin/eslint.js benchmark lib src test tools/doc \
523 tools/eslint-rules --rulesdir tools/eslint-rules
526 CPPLINT_EXCLUDE += src/node_lttng.cc
527 CPPLINT_EXCLUDE += src/node_root_certs.h
528 CPPLINT_EXCLUDE += src/node_lttng_tp.h
529 CPPLINT_EXCLUDE += src/node_win32_perfctr_provider.cc
530 CPPLINT_EXCLUDE += src/queue.h
531 CPPLINT_EXCLUDE += src/tree.h
532 CPPLINT_EXCLUDE += src/v8abbr.h
533 CPPLINT_EXCLUDE += $(wildcard test/addons/??_*/*.cc test/addons/??_*/*.h)
535 CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \
536 deps/debugger-agent/include/* \
537 deps/debugger-agent/src/* \
548 @$(PYTHON) tools/cpplint.py $(CPPLINT_FILES)
554 .PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean \
555 check uninstall install install-includes install-bin all staticlib \
556 dynamiclib test test-all test-addons build-addons website-upload pkg \
557 blog blogclean tar binary release-only bench-http-simple bench-idle \
558 bench-all bench bench-misc bench-array bench-buffer bench-net \
559 bench-http bench-fs bench-tls cctest run-ci lint-ci bench-ci