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
75 -rm -f config.gypi icu_config.gypi
77 -rm -rf $(NODE_EXE) $(NODE_G_EXE)
80 -rm -rf deps/icu4c*.tgz deps/icu4c*.zip deps/icu-tmp
81 -rm -f $(BINARYTAR).* $(TARBALL).*
88 test: | cctest # Depends on 'all'.
89 $(PYTHON) tools/test.py --mode=release message parallel sequential -J
94 $(PYTHON) tools/test.py --mode=release parallel -J
97 $(PYTHON) tools/test.py --mode=release --valgrind sequential parallel message
99 test/gc/node_modules/weak/build/Release/weakref.node: $(NODE_EXE)
100 $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \
101 --directory="$(shell pwd)/test/gc/node_modules/weak" \
102 --nodedir="$(shell pwd)"
104 # Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale.
105 test/addons/.docbuildstamp: doc/api/addons.markdown
106 $(RM) -r test/addons/doc-*/
107 $(NODE) tools/doc/addon-verify.js
110 ADDONS_BINDING_GYPS := \
111 $(filter-out test/addons/doc-*/binding.gyp, \
112 $(wildcard test/addons/*/binding.gyp))
114 # Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale.
115 test/addons/.buildstamp: $(ADDONS_BINDING_GYPS) | test/addons/.docbuildstamp
116 # Cannot use $(wildcard test/addons/*/) here, it's evaluated before
117 # embedded addons have been generated from the documentation.
118 for dirname in test/addons/*/; do \
119 $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \
120 --directory="$$PWD/$$dirname" \
125 # .buildstamp and .docbuildstamp need $(NODE_EXE) but cannot depend on it
126 # directly because it calls make recursively. The parent make cannot know
127 # if the subprocess touched anything so it pessimistically assumes that
128 # .buildstamp and .docbuildstamp are out of date and need a rebuild.
129 # Just goes to show that recursive make really is harmful...
130 # TODO(bnoordhuis) Force rebuild after gyp or node-gyp update.
131 build-addons: $(NODE_EXE) test/addons/.buildstamp
133 test-gc: all test/gc/node_modules/weak/build/Release/weakref.node
134 $(PYTHON) tools/test.py --mode=release gc
136 test-build: | all build-addons
138 test-all: test-build test/gc/node_modules/weak/build/Release/weakref.node
139 $(PYTHON) tools/test.py --mode=debug,release
141 test-all-valgrind: test-build
142 $(PYTHON) tools/test.py --mode=debug,release --valgrind
144 test-ci: | build-addons
145 $(PYTHON) tools/test.py -p tap --logfile test.tap --mode=release --flaky-tests=$(FLAKY_TESTS) \
146 $(TEST_CI_ARGS) addons message parallel sequential
148 test-release: test-build
149 $(PYTHON) tools/test.py --mode=release
151 test-debug: test-build
152 $(PYTHON) tools/test.py --mode=debug
154 test-message: test-build
155 $(PYTHON) tools/test.py message
157 test-simple: | cctest # Depends on 'all'.
158 $(PYTHON) tools/test.py parallel sequential
161 $(PYTHON) tools/test.py pummel
164 $(PYTHON) tools/test.py internet
167 $(PYTHON) tools/test.py debugger
169 test-npm: $(NODE_EXE)
170 NODE=$(NODE) tools/test-npm.sh
172 test-npm-publish: $(NODE_EXE)
173 npm_package_config_publishtest=true $(NODE) deps/npm/test/run.js
175 test-addons: test-build
176 $(PYTHON) tools/test.py --mode=release addons
179 $(MAKE) --directory=tools faketime
180 $(PYTHON) tools/test.py --mode=release timers
183 $(MAKE) --directory=tools clean
185 apidoc_sources = $(wildcard doc/api/*.markdown)
186 apidocs = $(addprefix out/,$(apidoc_sources:.markdown=.html)) \
187 $(addprefix out/,$(apidoc_sources:.markdown=.json))
189 apidoc_dirs = out/doc out/doc/api/ out/doc/api/assets
191 apiassets = $(subst api_assets,api/assets,$(addprefix out/,$(wildcard doc/api_assets/*)))
193 doc: $(apidoc_dirs) $(apiassets) $(apidocs) tools/doc/ $(NODE_EXE)
198 out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets/
204 out/doc/api/%.json: doc/api/%.markdown $(NODE_EXE)
205 $(NODE) tools/doc/generate.js --format=json $< > $@
207 out/doc/api/%.html: doc/api/%.markdown $(NODE_EXE)
208 $(NODE) tools/doc/generate.js --format=html --template=doc/template.html $< > $@
210 docopen: out/doc/api/all.html
211 -google-chrome out/doc/api/all.html
217 $(PYTHON) ./configure $(CONFIG_FLAGS)
221 RAWVER=$(shell $(PYTHON) tools/getnodeversion.py)
224 # For nightly builds, you must set DISTTYPE to "nightly", "next-nightly" or
225 # "custom". For the nightly and next-nightly case, you need to set DATESTRING
226 # and COMMIT in order to properly name the build.
227 # For the rc case you need to set CUSTOMTAG to an appropriate CUSTOMTAG number
232 ifeq ($(DISTTYPE),release)
233 FULLVERSION=$(VERSION)
234 else # ifeq ($(DISTTYPE),release)
235 ifeq ($(DISTTYPE),custom)
237 $(error CUSTOMTAG is not set for DISTTYPE=custom)
238 endif # ifndef CUSTOMTAG
240 else # ifeq ($(DISTTYPE),custom)
242 $(error DATESTRING is not set for nightly)
243 endif # ifndef DATESTRING
245 $(error COMMIT is not set for nightly)
246 endif # ifndef COMMIT
247 ifneq ($(DISTTYPE),nightly)
248 ifneq ($(DISTTYPE),next-nightly)
249 $(error DISTTYPE is not release, custom, nightly or next-nightly)
250 endif # ifneq ($(DISTTYPE),next-nightly)
251 endif # ifneq ($(DISTTYPE),nightly)
252 TAG=$(DISTTYPE)$(DATESTRING)$(COMMIT)
253 endif # ifeq ($(DISTTYPE),custom)
254 FULLVERSION=$(VERSION)-$(TAG)
255 endif # ifeq ($(DISTTYPE),release)
257 DISTTYPEDIR ?= $(DISTTYPE)
258 RELEASE=$(shell sed -ne 's/\#define NODE_VERSION_IS_RELEASE \([01]\)/\1/p' src/node_version.h)
259 PLATFORM=$(shell uname | tr '[:upper:]' '[:lower:]')
260 NPMVERSION=v$(shell cat deps/npm/package.json | grep '"version"' | sed 's/^[^:]*: "\([^"]*\)",.*/\1/')
262 ifeq ($(findstring x86_64,$(shell uname -m)),x86_64)
267 ifeq ($(DESTCPU),x64)
270 ifeq ($(DESTCPU),arm)
273 ifeq ($(DESTCPU),ppc64)
276 ifeq ($(DESTCPU),ppc)
285 # enforce "x86" over "ia32" as the generally accepted way of referring to 32-bit intel
289 ifeq ($(DESTCPU),ia32)
293 TARNAME=node-$(FULLVERSION)
294 TARBALL=$(TARNAME).tar
295 BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH)
296 BINARYTAR=$(BINARYNAME).tar
297 # OSX doesn't have xz installed by default, http://macpkg.sourceforge.net/
298 XZ=$(shell which xz > /dev/null 2>&1; echo $$?)
301 PACKAGEMAKER ?= /Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker
305 @if [ "$(shell git status --porcelain | egrep -v '^\?\? ')" = "" ]; then \
309 echo "The git repository is not clean." >&2 ; \
310 echo "Please commit changes before building release tarball." >&2 ; \
312 git status --porcelain | egrep -v '^\?\?' >&2 ; \
316 @if [ "$(DISTTYPE)" != "release" -o "$(RELEASE)" = "1" ]; then \
320 echo "#NODE_VERSION_IS_RELEASE is set to $(RELEASE)." >&2 ; \
321 echo "Did you remember to update src/node_version.h?" >&2 ; \
328 rm -rf out/deps out/Release
329 $(PYTHON) ./configure \
332 --release-urlbase=$(RELEASE_URLBASE) \
333 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
334 $(MAKE) install V=$(V) DESTDIR=$(PKGDIR)
335 SIGN="$(CODESIGN_CERT)" PKGDIR="$(PKGDIR)" bash tools/osx-codesign.sh
336 cat tools/osx-pkg.pmdoc/index.xml.tmpl \
337 | sed -E "s/\\{nodeversion\\}/$(FULLVERSION)/g" \
338 | sed -E "s/\\{npmversion\\}/$(NPMVERSION)/g" \
339 > tools/osx-pkg.pmdoc/index.xml
341 --id "org.node.pkg" \
342 --doc tools/osx-pkg.pmdoc \
344 SIGN="$(PRODUCTSIGN_CERT)" PKG="$(PKG)" bash tools/osx-productsign.sh
349 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
350 scp -p node-$(FULLVERSION).pkg $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).pkg
351 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).pkg.done"
353 $(TARBALL): release-only $(NODE_EXE) doc
354 git checkout-index -a -f --prefix=$(TARNAME)/
355 mkdir -p $(TARNAME)/doc/api
356 cp doc/node.1 $(TARNAME)/doc/node.1
357 cp -r out/doc/api/* $(TARNAME)/doc/api/
358 rm -rf $(TARNAME)/deps/v8/{test,samples,tools/profviz} # too big
359 rm -rf $(TARNAME)/doc/images # too big
360 rm -rf $(TARNAME)/deps/uv/{docs,samples,test}
361 rm -rf $(TARNAME)/deps/openssl/{doc,demos,test}
362 rm -rf $(TARNAME)/deps/zlib/contrib # too big, unused
363 find $(TARNAME)/ -type l | xargs rm # annoying on windows
364 tar -cf $(TARNAME).tar $(TARNAME)
366 gzip -c -f -9 $(TARNAME).tar > $(TARNAME).tar.gz
368 xz -c -f -$(XZ_COMPRESSION) $(TARNAME).tar > $(TARNAME).tar.xz
375 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
376 scp -p node-$(FULLVERSION).tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.gz
377 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.gz.done"
379 scp -p node-$(FULLVERSION).tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.xz
380 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.xz.done"
384 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
385 scp -r out/doc/ $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/docs/
386 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/docs.done"
388 $(TARBALL)-headers: config.gypi release-only
389 $(PYTHON) ./configure \
391 --dest-cpu=$(DESTCPU) \
393 --release-urlbase=$(RELEASE_URLBASE) \
394 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
395 HEADERS_ONLY=1 $(PYTHON) tools/install.py install '$(TARNAME)' '/'
396 find $(TARNAME)/ -type l | xargs rm # annoying on windows
397 tar -cf $(TARNAME)-headers.tar $(TARNAME)
399 gzip -c -f -9 $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.gz
401 xz -c -f -$(XZ_COMPRESSION) $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.xz
403 rm $(TARNAME)-headers.tar
405 tar-headers: $(TARBALL)-headers
407 tar-headers-upload: tar-headers
408 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
409 scp -p $(TARNAME)-headers.tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz
410 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz.done"
412 scp -p $(TARNAME)-headers.tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz
413 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz.done"
416 $(BINARYTAR): release-only
418 rm -rf out/deps out/Release
419 $(PYTHON) ./configure \
421 --dest-cpu=$(DESTCPU) \
423 --release-urlbase=$(RELEASE_URLBASE) \
424 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
425 $(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1
426 cp README.md $(BINARYNAME)
427 cp LICENSE $(BINARYNAME)
428 cp CHANGELOG.md $(BINARYNAME)
429 tar -cf $(BINARYNAME).tar $(BINARYNAME)
431 gzip -c -f -9 $(BINARYNAME).tar > $(BINARYNAME).tar.gz
433 xz -c -f -$(XZ_COMPRESSION) $(BINARYNAME).tar > $(BINARYNAME).tar.xz
439 binary-upload: binary
440 ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
441 scp -p node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz
442 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz.done"
444 scp -p node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz
445 ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz.done"
448 haswrk=$(shell which wrk > /dev/null 2>&1; echo $$?)
451 @echo "please install wrk before proceeding. More information can be found in benchmark/README.md." >&2
456 @$(NODE) benchmark/common.js net
459 @$(NODE) benchmark/common.js crypto
462 @$(NODE) benchmark/common.js tls
465 @$(NODE) benchmark/common.js http
468 @$(NODE) benchmark/common.js fs
471 @$(MAKE) -C benchmark/misc/function_call/
472 @$(NODE) benchmark/common.js misc
475 @$(NODE) benchmark/common.js arrays
478 @$(NODE) benchmark/common.js buffers
481 @$(NODE) benchmark/common.js url
484 @$(NODE) benchmark/common.js events
486 bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events
488 bench: bench-net bench-http bench-fs bench-tls
491 benchmark/http_simple_bench.sh
494 $(NODE) benchmark/idle_server.js &
496 $(NODE) benchmark/idle_clients.js &
499 $(NODE) tools/eslint/bin/eslint.js src lib test --rulesdir tools/eslint-rules --reset --quiet
502 CPPLINT_EXCLUDE += src/node_lttng.cc
503 CPPLINT_EXCLUDE += src/node_root_certs.h
504 CPPLINT_EXCLUDE += src/node_lttng_tp.h
505 CPPLINT_EXCLUDE += src/node_win32_perfctr_provider.cc
506 CPPLINT_EXCLUDE += src/queue.h
507 CPPLINT_EXCLUDE += src/tree.h
508 CPPLINT_EXCLUDE += src/v8abbr.h
509 CPPLINT_EXCLUDE += $(wildcard test/addons/doc-*/*.cc test/addons/doc-*/*.h)
511 CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \
512 deps/debugger-agent/include/* \
513 deps/debugger-agent/src/* \
524 @$(PYTHON) tools/cpplint.py $(CPPLINT_FILES)
528 .PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean \
529 check uninstall install install-includes install-bin all staticlib \
530 dynamiclib test test-all test-addons build-addons website-upload pkg \
531 blog blogclean tar binary release-only bench-http-simple bench-idle \
532 bench-all bench bench-misc bench-array bench-buffer bench-net \
533 bench-http bench-fs bench-tls cctest run-ci