test: add test for a unref'ed timer leak
[platform/upstream/nodejs.git] / Makefile
1 -include config.mk
2
3 BUILDTYPE ?= Release
4 PYTHON ?= python
5 DESTDIR ?=
6 SIGN ?=
7 PREFIX ?= /usr/local
8
9 # Determine EXEEXT
10 EXEEXT := $(shell $(PYTHON) -c \
11                 "import sys; print('.exe' if sys.platform == 'win32' else '')")
12
13 NODE ?= ./iojs$(EXEEXT)
14 NODE_EXE = iojs$(EXEEXT)
15 NODE_G_EXE = iojs_g$(EXEEXT)
16
17 # Default to verbose builds.
18 # To do quiet/pretty builds, run `make V=` to set V to an empty string,
19 # or set the V environment variable to an empty string.
20 V ?= 1
21
22 # BUILDTYPE=Debug builds both release and debug builds. If you want to compile
23 # just the debug build, run `make -C out BUILDTYPE=Debug` instead.
24 ifeq ($(BUILDTYPE),Release)
25 all: out/Makefile $(NODE_EXE)
26 else
27 all: out/Makefile $(NODE_EXE) $(NODE_G_EXE)
28 endif
29
30 # The .PHONY is needed to ensure that we recursively use the out/Makefile
31 # to check for changes.
32 .PHONY: $(NODE_EXE) $(NODE_G_EXE)
33
34 $(NODE_EXE): config.gypi out/Makefile
35         $(MAKE) -C out BUILDTYPE=Release V=$(V)
36         ln -fs out/Release/$(NODE_EXE) $@
37
38 $(NODE_G_EXE): config.gypi out/Makefile
39         $(MAKE) -C out BUILDTYPE=Debug V=$(V)
40         ln -fs out/Debug/$(NODE_EXE) $@
41
42 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
43         $(PYTHON) tools/gyp_node.py -f make
44
45 config.gypi: configure
46         if [ -f $@ ]; then
47                 $(error Stale $@, please re-run ./configure)
48         else
49                 $(error No $@, please run ./configure first)
50         fi
51
52 install: all
53         $(PYTHON) tools/install.py $@ '$(DESTDIR)' '$(PREFIX)'
54
55 uninstall:
56         $(PYTHON) tools/install.py $@ '$(DESTDIR)' '$(PREFIX)'
57
58 clean:
59         -rm -rf out/Makefile $(NODE_EXE) $(NODE_G_EXE) out/$(BUILDTYPE)/$(NODE_EXE) blog.html email.md
60         @if [ -d out ]; then find out/ -name '*.o' -o -name '*.a' | xargs rm -rf; fi
61         -rm -rf node_modules
62
63 distclean:
64         -rm -rf out
65         -rm -f config.gypi icu_config.gypi
66         -rm -f config.mk
67         -rm -rf $(NODE_EXE) $(NODE_G_EXE) blog.html email.md
68         -rm -rf node_modules
69         -rm -rf deps/icu
70         -rm -rf deps/icu4c*.tgz deps/icu4c*.zip deps/icu-tmp
71         -rm -f $(BINARYTAR).* $(TARBALL).*
72
73 check: test
74
75 cctest: all
76         @out/$(BUILDTYPE)/$@
77
78 test: | cctest  # Depends on 'all'.
79         $(PYTHON) tools/test.py --mode=release message parallel sequential -J
80         $(MAKE) jslint
81         $(MAKE) cpplint
82
83 test-parallel: all
84         $(PYTHON) tools/test.py --mode=release parallel -J
85
86 test-valgrind: all
87         $(PYTHON) tools/test.py --mode=release --valgrind sequential parallel message
88
89 test/gc/node_modules/weak/build/Release/weakref.node: $(NODE_EXE)
90         ./$(NODE_EXE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \
91                 --directory="$(shell pwd)/test/gc/node_modules/weak" \
92                 --nodedir="$(shell pwd)"
93
94 build-addons: $(NODE_EXE)
95         rm -rf test/addons/doc-*/
96         ./$(NODE_EXE) tools/doc/addon-verify.js
97         $(foreach dir, \
98                         $(sort $(dir $(wildcard test/addons/*/*.gyp))), \
99                         ./$(NODE_EXE) deps/npm/node_modules/node-gyp/bin/node-gyp rebuild \
100                                         --directory="$(shell pwd)/$(dir)" \
101                                         --nodedir="$(shell pwd)" && ) echo "build done"
102
103 test-gc: all test/gc/node_modules/weak/build/Release/weakref.node
104         $(PYTHON) tools/test.py --mode=release gc
105
106 test-build: all build-addons
107
108 test-all: test-build test/gc/node_modules/weak/build/Release/weakref.node
109         $(PYTHON) tools/test.py --mode=debug,release
110
111 test-all-valgrind: test-build
112         $(PYTHON) tools/test.py --mode=debug,release --valgrind
113
114 test-ci:
115         $(PYTHON) tools/test.py -p tap --logfile test.tap -J parallel sequential message
116
117 test-release: test-build
118         $(PYTHON) tools/test.py --mode=release
119
120 test-debug: test-build
121         $(PYTHON) tools/test.py --mode=debug
122
123 test-message: test-build
124         $(PYTHON) tools/test.py message
125
126 test-simple: | cctest  # Depends on 'all'.
127         $(PYTHON) tools/test.py parallel sequential
128
129 test-pummel: all
130         $(PYTHON) tools/test.py pummel
131
132 test-internet: all
133         $(PYTHON) tools/test.py internet
134
135 test-debugger: all
136         $(PYTHON) tools/test.py debugger
137
138 test-npm: $(NODE_EXE)
139         rm -rf npm-cache npm-tmp npm-prefix
140         mkdir npm-cache npm-tmp npm-prefix
141         cd deps/npm ; npm_config_cache="$(shell pwd)/npm-cache" \
142              npm_config_prefix="$(shell pwd)/npm-prefix" \
143              npm_config_tmp="$(shell pwd)/npm-tmp" \
144              ../../$(NODE_EXE) cli.js install --ignore-scripts
145         cd deps/npm ; npm_config_cache="$(shell pwd)/npm-cache" \
146              npm_config_prefix="$(shell pwd)/npm-prefix" \
147              npm_config_tmp="$(shell pwd)/npm-tmp" \
148              ../../$(NODE_EXE) cli.js run-script test-all && \
149              ../../$(NODE_EXE) cli.js prune --prod && \
150              cd ../.. && \
151              rm -rf npm-cache npm-tmp npm-prefix
152
153 test-npm-publish: $(NODE_EXE)
154         npm_package_config_publishtest=true ./$(NODE_EXE) deps/npm/test/run.js
155
156 test-addons: test-build
157         $(PYTHON) tools/test.py --mode=release addons
158
159 test-timers:
160         $(MAKE) --directory=tools faketime
161         $(PYTHON) tools/test.py --mode=release timers
162
163 test-timers-clean:
164         $(MAKE) --directory=tools clean
165
166 apidoc_sources = $(wildcard doc/api/*.markdown)
167 apidocs = $(addprefix out/,$(apidoc_sources:.markdown=.html)) \
168           $(addprefix out/,$(apidoc_sources:.markdown=.json))
169
170 apidoc_dirs = out/doc out/doc/api/ out/doc/api/assets
171
172 apiassets = $(subst api_assets,api/assets,$(addprefix out/,$(wildcard doc/api_assets/*)))
173
174 doc: $(apidoc_dirs) $(apiassets) $(apidocs) tools/doc/ $(NODE_EXE)
175
176 $(apidoc_dirs):
177         mkdir -p $@
178
179 out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets/
180         cp $< $@
181
182 out/doc/%: doc/%
183         cp -r $< $@
184
185 out/doc/api/%.json: doc/api/%.markdown $(NODE_EXE)
186         out/Release/$(NODE_EXE) tools/doc/generate.js --format=json $< > $@
187
188 out/doc/api/%.html: doc/api/%.markdown $(NODE_EXE)
189         out/Release/$(NODE_EXE) tools/doc/generate.js --format=html --template=doc/template.html $< > $@
190
191 docopen: out/doc/api/all.html
192         -google-chrome out/doc/api/all.html
193
194 docclean:
195         -rm -rf out/doc
196
197 RAWVER=$(shell $(PYTHON) tools/getnodeversion.py)
198 VERSION=v$(RAWVER)
199 FULLVERSION=$(VERSION)
200 RELEASE=$(shell $(PYTHON) tools/getnodeisrelease.py)
201 PLATFORM=$(shell uname | tr '[:upper:]' '[:lower:]')
202 NPMVERSION=v$(shell cat deps/npm/package.json | grep '"version"' | sed 's/^[^:]*: "\([^"]*\)",.*/\1/')
203 ifeq ($(findstring x86_64,$(shell uname -m)),x86_64)
204 DESTCPU ?= x64
205 else
206 DESTCPU ?= ia32
207 endif
208 ifeq ($(DESTCPU),x64)
209 ARCH=x64
210 else
211 ifeq ($(DESTCPU),arm)
212 ARCH=arm
213 else
214 ARCH=x86
215 endif
216 endif
217 ifdef NIGHTLY
218 TAG = nightly-$(NIGHTLY)
219 FULLVERSION=$(VERSION)-$(TAG)
220 endif
221 TARNAME=iojs-$(FULLVERSION)
222 TARBALL=$(TARNAME).tar
223 BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH)
224 BINARYTAR=$(BINARYNAME).tar
225 XZ=$(shell which xz > /dev/null 2>&1; echo $$?)
226 PKG=out/$(TARNAME).pkg
227 PACKAGEMAKER ?= /Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker
228
229 PKGSRC=iojs-$(DESTCPU)-$(RAWVER).tgz
230 ifdef NIGHTLY
231 PKGSRC=iojs-$(DESTCPU)-$(RAWVER)-$(TAG).tgz
232 endif
233
234 dist: doc $(TARBALL) $(PKG)
235
236 PKGDIR=out/dist-osx
237
238 release-only:
239         @if [ "$(shell git status --porcelain | egrep -v '^\?\? ')" = "" ]; then \
240                 exit 0 ; \
241         else \
242           echo "" >&2 ; \
243                 echo "The git repository is not clean." >&2 ; \
244                 echo "Please commit changes before building release tarball." >&2 ; \
245                 echo "" >&2 ; \
246                 git status --porcelain | egrep -v '^\?\?' >&2 ; \
247                 echo "" >&2 ; \
248                 exit 1 ; \
249         fi
250         @if [ "$(NIGHTLY)" != "" -o "$(RELEASE)" = "1" ]; then \
251                 exit 0; \
252         else \
253           echo "" >&2 ; \
254                 echo "#NODE_VERSION_IS_RELEASE is set to $(RELEASE)." >&2 ; \
255           echo "Did you remember to update src/node_version.h?" >&2 ; \
256           echo "" >&2 ; \
257                 exit 1 ; \
258         fi
259
260 pkg: $(PKG)
261
262 $(PKG): release-only
263         rm -rf $(PKGDIR)
264         rm -rf out/deps out/Release
265         $(PYTHON) ./configure --dest-cpu=ia32 --tag=$(TAG)
266         $(MAKE) install V=$(V) DESTDIR=$(PKGDIR)/32
267         rm -rf out/deps out/Release
268         $(PYTHON) ./configure --dest-cpu=x64 --tag=$(TAG)
269         $(MAKE) install V=$(V) DESTDIR=$(PKGDIR)
270         SIGN="$(APP_SIGN)" PKGDIR="$(PKGDIR)" bash tools/osx-codesign.sh
271         lipo $(PKGDIR)/32/usr/local/bin/iojs \
272                 $(PKGDIR)/usr/local/bin/iojs \
273                 -output $(PKGDIR)/usr/local/bin/iojs-universal \
274                 -create
275         mv $(PKGDIR)/usr/local/bin/iojs-universal $(PKGDIR)/usr/local/bin/iojs
276         rm -rf $(PKGDIR)/32
277         cat tools/osx-pkg.pmdoc/index.xml.tmpl | sed -e 's|__iojsversion__|'$(FULLVERSION)'|g' | sed -e 's|__npmversion__|'$(NPMVERSION)'|g' > tools/osx-pkg.pmdoc/index.xml
278         $(PACKAGEMAKER) \
279                 --id "org.nodejs.Node" \
280                 --doc tools/osx-pkg.pmdoc \
281                 --out $(PKG)
282         SIGN="$(INT_SIGN)" PKG="$(PKG)" bash tools/osx-productsign.sh
283
284 $(TARBALL): release-only $(NODE_EXE) doc
285         git checkout-index -a -f --prefix=$(TARNAME)/
286         mkdir -p $(TARNAME)/doc/api
287         cp doc/iojs.1 $(TARNAME)/doc/iojs.1
288         cp -r out/doc/api/* $(TARNAME)/doc/api/
289         rm -rf $(TARNAME)/deps/v8/{test,samples,tools/profviz} # too big
290         rm -rf $(TARNAME)/doc/images # too big
291         rm -rf $(TARNAME)/deps/uv/{docs,samples,test}
292         rm -rf $(TARNAME)/deps/openssl/{doc,demos,test}
293         rm -rf $(TARNAME)/deps/zlib/contrib # too big, unused
294         find $(TARNAME)/ -type l | xargs rm # annoying on windows
295         tar -cf $(TARNAME).tar $(TARNAME)
296         rm -rf $(TARNAME)
297         gzip -c -f -9 $(TARNAME).tar > $(TARNAME).tar.gz
298 ifeq ($(XZ), 0)
299         xz -c -f -9 $(TARNAME).tar > $(TARNAME).tar.xz
300 endif
301         rm $(TARNAME).tar
302
303 tar: $(TARBALL)
304
305 $(BINARYTAR): release-only
306         rm -rf $(BINARYNAME)
307         rm -rf out/deps out/Release
308         $(PYTHON) ./configure --prefix=/ --dest-cpu=$(DESTCPU) --tag=$(TAG) $(CONFIG_FLAGS)
309         $(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1
310         cp README.md $(BINARYNAME)
311         cp LICENSE $(BINARYNAME)
312         cp CHANGELOG.md $(BINARYNAME)
313         tar -cf $(BINARYNAME).tar $(BINARYNAME)
314         rm -rf $(BINARYNAME)
315         gzip -c -f -9 $(BINARYNAME).tar > $(BINARYNAME).tar.gz
316 ifeq ($(XZ), 0)
317         xz -c -f -9 $(BINARYNAME).tar > $(BINARYNAME).tar.xz
318 endif
319         rm $(BINARYNAME).tar
320
321 binary: $(BINARYTAR)
322
323 $(PKGSRC): release-only
324         rm -rf dist out
325         $(PYTHON) configure --prefix=/ \
326                 --dest-cpu=$(DESTCPU) --tag=$(TAG) $(CONFIG_FLAGS)
327         $(MAKE) install DESTDIR=dist
328         (cd dist; find * -type f | sort) > packlist
329         pkg_info -X pkg_install | \
330                 egrep '^(MACHINE_ARCH|OPSYS|OS_VERSION|PKGTOOLS_VERSION)' > build-info
331         pkg_create -B build-info -c tools/pkgsrc/comment -d tools/pkgsrc/description \
332                 -f packlist -I /opt/local -p dist -U $(PKGSRC)
333
334 pkgsrc: $(PKGSRC)
335
336 haswrk=$(shell which wrk > /dev/null 2>&1; echo $$?)
337 wrk:
338 ifneq ($(haswrk), 0)
339         @echo "please install wrk before proceeding. More information can be found in benchmark/README.md." >&2
340         @exit 1
341 endif
342
343 bench-net: all
344         @$(NODE) benchmark/common.js net
345
346 bench-crypto: all
347         @$(NODE) benchmark/common.js crypto
348
349 bench-tls: all
350         @$(NODE) benchmark/common.js tls
351
352 bench-http: wrk all
353         @$(NODE) benchmark/common.js http
354
355 bench-fs: all
356         @$(NODE) benchmark/common.js fs
357
358 bench-misc: all
359         @$(MAKE) -C benchmark/misc/function_call/
360         @$(NODE) benchmark/common.js misc
361
362 bench-array: all
363         @$(NODE) benchmark/common.js arrays
364
365 bench-buffer: all
366         @$(NODE) benchmark/common.js buffers
367
368 bench-url: all
369         @$(NODE) benchmark/common.js url
370
371 bench-events: all
372         @$(NODE) benchmark/common.js events
373
374 bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events
375
376 bench: bench-net bench-http bench-fs bench-tls
377
378 bench-http-simple:
379          benchmark/http_simple_bench.sh
380
381 bench-idle:
382         ./$(NODE_EXE) benchmark/idle_server.js &
383         sleep 1
384         ./$(NODE_EXE) benchmark/idle_clients.js &
385
386 jslintfix:
387         PYTHONPATH=tools/closure_linter/:tools/gflags/ $(PYTHON) tools/closure_linter/closure_linter/fixjsstyle.py --strict --nojsdoc -r lib/ -r src/ --exclude_files lib/punycode.js
388
389 jslint:
390         PYTHONPATH=tools/closure_linter/:tools/gflags/ $(PYTHON) tools/closure_linter/closure_linter/gjslint.py --unix_mode --strict --nojsdoc -r lib/ -r src/ --exclude_files lib/punycode.js
391
392 CPPLINT_EXCLUDE ?=
393 CPPLINT_EXCLUDE += src/node_lttng.cc
394 CPPLINT_EXCLUDE += src/node_root_certs.h
395 CPPLINT_EXCLUDE += src/node_lttng_tp.h
396 CPPLINT_EXCLUDE += src/node_win32_perfctr_provider.cc
397 CPPLINT_EXCLUDE += src/queue.h
398 CPPLINT_EXCLUDE += src/tree.h
399 CPPLINT_EXCLUDE += src/v8abbr.h
400
401 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/*))
402
403 cpplint:
404         @$(PYTHON) tools/cpplint.py $(CPPLINT_FILES)
405
406 lint: jslint cpplint
407
408 .PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean \
409         check uninstall install install-includes install-bin all staticlib \
410         dynamiclib test test-all test-addons build-addons website-upload pkg \
411         blog blogclean tar binary release-only bench-http-simple bench-idle \
412         bench-all bench bench-misc bench-array bench-buffer bench-net \
413         bench-http bench-fs bench-tls cctest