8 STAGINGSERVER ?= node-www
10 OSTYPE := $(shell uname -s | tr '[A-Z]' '[a-z]')
13 EXEEXT := $(shell $(PYTHON) -c \
14 "import sys; print('.exe' if sys.platform == 'win32' else '')")
16 NODE ?= ./node$(EXEEXT)
17 NODE_EXE = node$(EXEEXT)
18 NODE_G_EXE = node_g$(EXEEXT)
20 # Flags for packaging.
21 BUILD_DOWNLOAD_FLAGS ?= --download=all
22 BUILD_INTL_FLAGS ?= --with-intl=small-icu
23 BUILD_RELEASE_FLAGS ?= $(BUILD_DOWNLOAD_FLAGS) $(BUILD_INTL_FLAGS)
25 # Default to verbose builds.
26 # To do quiet/pretty builds, run `make V=` to set V to an empty string,
27 # or set the V environment variable to an empty string.
30 # BUILDTYPE=Debug builds both release and debug builds. If you want to compile
31 # just the debug build, run `make -C out BUILDTYPE=Debug` instead.
32 ifeq ($(BUILDTYPE),Release)
33 all: out/Makefile $(NODE_EXE)
35 all: out/Makefile $(NODE_EXE) $(NODE_G_EXE)
38 # The .PHONY is needed to ensure that we recursively use the out/Makefile
39 # to check for changes.
40 .PHONY: $(NODE_EXE) $(NODE_G_EXE)
42 $(NODE_EXE): config.gypi out/Makefile
43 $(MAKE) -C out BUILDTYPE=Release V=$(V)
44 ln -fs out/Release/$(NODE_EXE) $@
46 $(NODE_G_EXE): config.gypi out/Makefile
47 $(MAKE) -C out BUILDTYPE=Debug V=$(V)
48 ln -fs out/Debug/$(NODE_EXE) $@
50 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
51 $(PYTHON) tools/gyp_node.py -f make
53 config.gypi: configure
55 $(error Stale $@, please re-run ./configure)
57 $(error No $@, please run ./configure first)
61 $(PYTHON) tools/install.py $@ '$(DESTDIR)' '$(PREFIX)'
64 $(PYTHON) tools/install.py $@ '$(DESTDIR)' '$(PREFIX)'
67 -rm -rf out/Makefile $(NODE_EXE) $(NODE_G_EXE) out/$(BUILDTYPE)/$(NODE_EXE)
68 @if [ -d out ]; then find out/ -name '*.o' -o -name '*.a' | xargs rm -rf; fi
73 -rm -f config.gypi icu_config.gypi
75 -rm -rf $(NODE_EXE) $(NODE_G_EXE)
78 -rm -rf deps/icu4c*.tgz deps/icu4c*.zip deps/icu-tmp
79 -rm -f $(BINARYTAR).* $(TARBALL).*
86 test: | cctest # Depends on 'all'.
87 $(PYTHON) tools/test.py --mode=release message parallel sequential -J
92 $(PYTHON) tools/test.py --mode=release parallel -J
95 $(PYTHON) tools/test.py --mode=release --valgrind sequential parallel message
97 test/gc/node_modules/weak/build/Release/weakref.node: $(NODE_EXE)
98 $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \
99 --directory="$(shell pwd)/test/gc/node_modules/weak" \
100 --nodedir="$(shell pwd)"
102 # Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale.
103 test/addons/.docbuildstamp: doc/api/addons.markdown
104 $(RM) -r test/addons/doc-*/
105 $(NODE) tools/doc/addon-verify.js
108 ADDONS_BINDING_GYPS := \
109 $(filter-out test/addons/doc-*/binding.gyp, \
110 $(wildcard test/addons/*/binding.gyp))
112 # Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale.
113 test/addons/.buildstamp: $(ADDONS_BINDING_GYPS) | test/addons/.docbuildstamp
114 # Cannot use $(wildcard test/addons/*/) here, it's evaluated before
115 # embedded addons have been generated from the documentation.
116 for dirname in test/addons/*/; do \
117 $(NODE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \
118 --directory="$$PWD/$$dirname" \
123 # .buildstamp and .docbuildstamp need $(NODE_EXE) but cannot depend on it
124 # directly because it calls make recursively. The parent make cannot know
125 # if the subprocess touched anything so it pessimistically assumes that
126 # .buildstamp and .docbuildstamp are out of date and need a rebuild.
127 # Just goes to show that recursive make really is harmful...
128 # TODO(bnoordhuis) Force rebuild after gyp or node-gyp update.
129 build-addons: $(NODE_EXE) test/addons/.buildstamp
131 test-gc: all test/gc/node_modules/weak/build/Release/weakref.node
132 $(PYTHON) tools/test.py --mode=release gc
134 test-build: | all build-addons
136 test-all: test-build test/gc/node_modules/weak/build/Release/weakref.node
137 $(PYTHON) tools/test.py --mode=debug,release
139 test-all-valgrind: test-build
140 $(PYTHON) tools/test.py --mode=debug,release --valgrind
142 test-ci: | build-addons
143 $(PYTHON) tools/test.py -p tap --logfile test.tap --mode=release \
144 addons message parallel sequential
146 test-release: test-build
147 $(PYTHON) tools/test.py --mode=release
149 test-debug: test-build
150 $(PYTHON) tools/test.py --mode=debug
152 test-message: test-build
153 $(PYTHON) tools/test.py message
155 test-simple: | cctest # Depends on 'all'.
156 $(PYTHON) tools/test.py parallel sequential
159 $(PYTHON) tools/test.py pummel
162 $(PYTHON) tools/test.py internet
165 $(PYTHON) tools/test.py debugger
167 test-npm: $(NODE_EXE)
168 NODE=$(NODE) tools/test-npm.sh
170 test-npm-publish: $(NODE_EXE)
171 npm_package_config_publishtest=true $(NODE) deps/npm/test/run.js
173 test-addons: test-build
174 $(PYTHON) tools/test.py --mode=release addons
177 $(MAKE) --directory=tools faketime
178 $(PYTHON) tools/test.py --mode=release timers
181 $(MAKE) --directory=tools clean
183 apidoc_sources = $(wildcard doc/api/*.markdown)
184 apidocs = $(addprefix out/,$(apidoc_sources:.markdown=.html)) \
185 $(addprefix out/,$(apidoc_sources:.markdown=.json))
187 apidoc_dirs = out/doc out/doc/api/ out/doc/api/assets
189 apiassets = $(subst api_assets,api/assets,$(addprefix out/,$(wildcard doc/api_assets/*)))
191 doc: $(apidoc_dirs) $(apiassets) $(apidocs) tools/doc/ $(NODE_EXE)
196 out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets/
202 out/doc/api/%.json: doc/api/%.markdown $(NODE_EXE)
203 $(NODE) tools/doc/generate.js --format=json $< > $@
205 out/doc/api/%.html: doc/api/%.markdown $(NODE_EXE)
206 $(NODE) tools/doc/generate.js --format=html --template=doc/template.html $< > $@
208 docopen: out/doc/api/all.html
209 -google-chrome out/doc/api/all.html
215 $(PYTHON) ./configure $(CONFIG_FLAGS)
219 RAWVER=$(shell $(PYTHON) tools/getnodeversion.py)
222 # For nightly builds, you must set DISTTYPE to "nightly", "next-nightly" or
223 # "custom". For the nightly and next-nightly case, you need to set DATESTRING
224 # and COMMIT in order to properly name the build.
225 # For the rc case you need to set CUSTOMTAG to an appropriate CUSTOMTAG number
230 ifeq ($(DISTTYPE),release)
231 FULLVERSION=$(VERSION)
232 else # ifeq ($(DISTTYPE),release)
233 ifeq ($(DISTTYPE),custom)
235 $(error CUSTOMTAG is not set for DISTTYPE=custom)
236 endif # ifndef CUSTOMTAG
238 else # ifeq ($(DISTTYPE),custom)
240 $(error DATESTRING is not set for nightly)
241 endif # ifndef DATESTRING
243 $(error COMMIT is not set for nightly)
244 endif # ifndef COMMIT
245 ifneq ($(DISTTYPE),nightly)
246 ifneq ($(DISTTYPE),next-nightly)
247 $(error DISTTYPE is not release, custom, nightly or next-nightly)
248 endif # ifneq ($(DISTTYPE),next-nightly)
249 endif # ifneq ($(DISTTYPE),nightly)
250 TAG=$(DISTTYPE)$(DATESTRING)$(COMMIT)
251 endif # ifeq ($(DISTTYPE),custom)
252 FULLVERSION=$(VERSION)-$(TAG)
253 endif # ifeq ($(DISTTYPE),release)
255 DISTTYPEDIR ?= $(DISTTYPE)
256 RELEASE=$(shell sed -ne 's/\#define NODE_VERSION_IS_RELEASE \([01]\)/\1/p' src/node_version.h)
257 PLATFORM=$(shell uname | tr '[:upper:]' '[:lower:]')
258 NPMVERSION=v$(shell cat deps/npm/package.json | grep '"version"' | sed 's/^[^:]*: "\([^"]*\)",.*/\1/')
260 ifeq ($(findstring x86_64,$(shell uname -m)),x86_64)
265 ifeq ($(DESTCPU),x64)
268 ifeq ($(DESTCPU),arm)
271 ifeq ($(DESTCPU),ppc64)
274 ifeq ($(DESTCPU),ppc)
283 # enforce "x86" over "ia32" as the generally accepted way of referring to 32-bit intel
287 ifeq ($(DESTCPU),ia32)
291 TARNAME=node-$(FULLVERSION)
292 TARBALL=$(TARNAME).tar
293 BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH)
294 BINARYTAR=$(BINARYNAME).tar
295 # OSX doesn't have xz installed by default, http://macpkg.sourceforge.net/
296 XZ=$(shell which xz > /dev/null 2>&1; echo $$?)
299 PACKAGEMAKER ?= /Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker
303 @if [ "$(shell git status --porcelain | egrep -v '^\?\? ')" = "" ]; then \
307 echo "The git repository is not clean." >&2 ; \
308 echo "Please commit changes before building release tarball." >&2 ; \
310 git status --porcelain | egrep -v '^\?\?' >&2 ; \
314 @if [ "$(DISTTYPE)" != "release" -o "$(RELEASE)" = "1" ]; then \
318 echo "#NODE_VERSION_IS_RELEASE is set to $(RELEASE)." >&2 ; \
319 echo "Did you remember to update src/node_version.h?" >&2 ; \
326 rm -rf out/deps out/Release
327 $(PYTHON) ./configure \
330 --release-urlbase=$(RELEASE_URLBASE) \
331 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
332 $(MAKE) install V=$(V) DESTDIR=$(PKGDIR)
333 SIGN="$(CODESIGN_CERT)" PKGDIR="$(PKGDIR)" bash tools/osx-codesign.sh
334 cat tools/osx-pkg.pmdoc/index.xml.tmpl \
335 | sed -E "s/\\{nodeversion\\}/$(FULLVERSION)/g" \
336 | sed -E "s/\\{npmversion\\}/$(NPMVERSION)/g" \
337 > tools/osx-pkg.pmdoc/index.xml
339 --id "org.node.pkg" \
340 --doc tools/osx-pkg.pmdoc \
342 SIGN="$(PRODUCTSIGN_CERT)" PKG="$(PKG)" bash tools/osx-productsign.sh
347 ssh $(STAGINGSERVER) "mkdir -p staging/$(DISTTYPEDIR)/$(FULLVERSION)"
348 scp -p node-$(FULLVERSION).pkg $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).pkg
349 ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).pkg.done"
351 $(TARBALL): release-only $(NODE_EXE) doc
352 git checkout-index -a -f --prefix=$(TARNAME)/
353 mkdir -p $(TARNAME)/doc/api
354 cp doc/node.1 $(TARNAME)/doc/node.1
355 cp -r out/doc/api/* $(TARNAME)/doc/api/
356 rm -rf $(TARNAME)/deps/v8/{test,samples,tools/profviz} # too big
357 rm -rf $(TARNAME)/doc/images # too big
358 rm -rf $(TARNAME)/deps/uv/{docs,samples,test}
359 rm -rf $(TARNAME)/deps/openssl/{doc,demos,test}
360 rm -rf $(TARNAME)/deps/zlib/contrib # too big, unused
361 find $(TARNAME)/ -type l | xargs rm # annoying on windows
362 tar -cf $(TARNAME).tar $(TARNAME)
364 gzip -c -f -9 $(TARNAME).tar > $(TARNAME).tar.gz
366 xz -c -f -$(XZ_COMPRESSION) $(TARNAME).tar > $(TARNAME).tar.xz
373 ssh $(STAGINGSERVER) "mkdir -p staging/$(DISTTYPEDIR)/$(FULLVERSION)"
374 scp -p node-$(FULLVERSION).tar.gz $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.gz
375 ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.gz.done"
377 scp -p node-$(FULLVERSION).tar.xz $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.xz
378 ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION).tar.xz.done"
382 ssh $(STAGINGSERVER) "mkdir -p staging/$(DISTTYPEDIR)/$(FULLVERSION)"
383 scp -r out/doc/ $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/
384 ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/doc.done"
386 $(TARBALL)-headers: config.gypi release-only
387 $(PYTHON) ./configure \
389 --dest-cpu=$(DESTCPU) \
391 --release-urlbase=$(RELEASE_URLBASE) \
392 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
393 HEADERS_ONLY=1 $(PYTHON) tools/install.py install '$(TARNAME)' '/'
394 find $(TARNAME)/ -type l | xargs rm # annoying on windows
395 tar -cf $(TARNAME)-headers.tar $(TARNAME)
397 gzip -c -f -9 $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.gz
399 xz -c -f -$(XZ_COMPRESSION) $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.xz
401 rm $(TARNAME)-headers.tar
403 tar-headers: $(TARBALL)-headers
405 tar-headers-upload: tar-headers
406 ssh $(STAGINGSERVER) "mkdir -p staging/$(DISTTYPEDIR)/$(FULLVERSION)"
407 scp -p $(TARNAME)-headers.tar.gz $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz
408 ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz.done"
410 scp -p $(TARNAME)-headers.tar.xz $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz
411 ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz.done"
414 $(BINARYTAR): release-only
416 rm -rf out/deps out/Release
417 $(PYTHON) ./configure \
419 --dest-cpu=$(DESTCPU) \
421 --release-urlbase=$(RELEASE_URLBASE) \
422 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
423 $(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1
424 cp README.md $(BINARYNAME)
425 cp LICENSE $(BINARYNAME)
426 cp CHANGELOG.md $(BINARYNAME)
427 tar -cf $(BINARYNAME).tar $(BINARYNAME)
429 gzip -c -f -9 $(BINARYNAME).tar > $(BINARYNAME).tar.gz
431 xz -c -f -$(XZ_COMPRESSION) $(BINARYNAME).tar > $(BINARYNAME).tar.xz
437 binary-upload: binary
438 ssh $(STAGINGSERVER) "mkdir -p staging/$(DISTTYPEDIR)/$(FULLVERSION)"
439 scp -p node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz
440 ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz.done"
442 scp -p node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz
443 ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/node-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz.done"
446 haswrk=$(shell which wrk > /dev/null 2>&1; echo $$?)
449 @echo "please install wrk before proceeding. More information can be found in benchmark/README.md." >&2
454 @$(NODE) benchmark/common.js net
457 @$(NODE) benchmark/common.js crypto
460 @$(NODE) benchmark/common.js tls
463 @$(NODE) benchmark/common.js http
466 @$(NODE) benchmark/common.js fs
469 @$(MAKE) -C benchmark/misc/function_call/
470 @$(NODE) benchmark/common.js misc
473 @$(NODE) benchmark/common.js arrays
476 @$(NODE) benchmark/common.js buffers
479 @$(NODE) benchmark/common.js url
482 @$(NODE) benchmark/common.js events
484 bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events
486 bench: bench-net bench-http bench-fs bench-tls
489 benchmark/http_simple_bench.sh
492 $(NODE) benchmark/idle_server.js &
494 $(NODE) benchmark/idle_clients.js &
497 $(NODE) tools/eslint/bin/eslint.js src lib test --rulesdir tools/eslint-rules --reset --quiet
500 CPPLINT_EXCLUDE += src/node_lttng.cc
501 CPPLINT_EXCLUDE += src/node_root_certs.h
502 CPPLINT_EXCLUDE += src/node_lttng_tp.h
503 CPPLINT_EXCLUDE += src/node_win32_perfctr_provider.cc
504 CPPLINT_EXCLUDE += src/queue.h
505 CPPLINT_EXCLUDE += src/tree.h
506 CPPLINT_EXCLUDE += src/v8abbr.h
507 CPPLINT_EXCLUDE += $(wildcard test/addons/doc-*/*.cc test/addons/doc-*/*.h)
509 CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \
510 deps/debugger-agent/include/* \
511 deps/debugger-agent/src/* \
522 @$(PYTHON) tools/cpplint.py $(CPPLINT_FILES)
526 .PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean \
527 check uninstall install install-includes install-bin all staticlib \
528 dynamiclib test test-all test-addons build-addons website-upload pkg \
529 blog blogclean tar binary release-only bench-http-simple bench-idle \
530 bench-all bench bench-misc bench-array bench-buffer bench-net \
531 bench-http bench-fs bench-tls cctest run-ci