tools: refactor `make test-npm` into test-npm.sh
[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 --mode=release message parallel sequential
116         $(MAKE) jslint
117         $(MAKE) cpplint
118
119 test-release: test-build
120         $(PYTHON) tools/test.py --mode=release
121
122 test-debug: test-build
123         $(PYTHON) tools/test.py --mode=debug
124
125 test-message: test-build
126         $(PYTHON) tools/test.py message
127
128 test-simple: | cctest  # Depends on 'all'.
129         $(PYTHON) tools/test.py parallel sequential
130
131 test-pummel: all
132         $(PYTHON) tools/test.py pummel
133
134 test-internet: all
135         $(PYTHON) tools/test.py internet
136
137 test-debugger: all
138         $(PYTHON) tools/test.py debugger
139
140 test-npm: $(NODE_EXE)
141         NODE_EXE=$(NODE_EXE) tools/test-npm.sh
142
143 test-npm-publish: $(NODE_EXE)
144         npm_package_config_publishtest=true ./$(NODE_EXE) deps/npm/test/run.js
145
146 test-addons: test-build
147         $(PYTHON) tools/test.py --mode=release addons
148
149 test-timers:
150         $(MAKE) --directory=tools faketime
151         $(PYTHON) tools/test.py --mode=release timers
152
153 test-timers-clean:
154         $(MAKE) --directory=tools clean
155
156 apidoc_sources = $(wildcard doc/api/*.markdown)
157 apidocs = $(addprefix out/,$(apidoc_sources:.markdown=.html)) \
158           $(addprefix out/,$(apidoc_sources:.markdown=.json))
159
160 apidoc_dirs = out/doc out/doc/api/ out/doc/api/assets
161
162 apiassets = $(subst api_assets,api/assets,$(addprefix out/,$(wildcard doc/api_assets/*)))
163
164 doc: $(apidoc_dirs) $(apiassets) $(apidocs) tools/doc/ $(NODE_EXE)
165
166 $(apidoc_dirs):
167         mkdir -p $@
168
169 out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets/
170         cp $< $@
171
172 out/doc/%: doc/%
173         cp -r $< $@
174
175 out/doc/api/%.json: doc/api/%.markdown $(NODE_EXE)
176         out/Release/$(NODE_EXE) tools/doc/generate.js --format=json $< > $@
177
178 out/doc/api/%.html: doc/api/%.markdown $(NODE_EXE)
179         out/Release/$(NODE_EXE) tools/doc/generate.js --format=html --template=doc/template.html $< > $@
180
181 docopen: out/doc/api/all.html
182         -google-chrome out/doc/api/all.html
183
184 docclean:
185         -rm -rf out/doc
186
187 RAWVER=$(shell $(PYTHON) tools/getnodeversion.py)
188 VERSION=v$(RAWVER)
189 FULLVERSION=$(VERSION)
190 RELEASE=$(shell sed -ne 's/\#define NODE_VERSION_IS_RELEASE \([01]\)/\1/p' src/node_version.h)
191 PLATFORM=$(shell uname | tr '[:upper:]' '[:lower:]')
192 NPMVERSION=v$(shell cat deps/npm/package.json | grep '"version"' | sed 's/^[^:]*: "\([^"]*\)",.*/\1/')
193 ifeq ($(findstring x86_64,$(shell uname -m)),x86_64)
194 DESTCPU ?= x64
195 else
196 DESTCPU ?= ia32
197 endif
198 ifeq ($(DESTCPU),x64)
199 ARCH=x64
200 else
201 ifeq ($(DESTCPU),arm)
202 ARCH=arm
203 else
204 ARCH=x86
205 endif
206 endif
207 ifdef NIGHTLY
208 TAG = nightly-$(NIGHTLY)
209 FULLVERSION=$(VERSION)-$(TAG)
210 endif
211 TARNAME=iojs-$(FULLVERSION)
212 TARBALL=$(TARNAME).tar
213 BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH)
214 BINARYTAR=$(BINARYNAME).tar
215 XZ=$(shell which xz > /dev/null 2>&1; echo $$?)
216 XZ_COMPRESSION ?= 9
217 PKG=out/$(TARNAME).pkg
218 PACKAGEMAKER ?= /Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker
219
220 PKGSRC=iojs-$(DESTCPU)-$(RAWVER).tgz
221 ifdef NIGHTLY
222 PKGSRC=iojs-$(DESTCPU)-$(RAWVER)-$(TAG).tgz
223 endif
224
225 dist: doc $(TARBALL) $(PKG)
226
227 PKGDIR=out/dist-osx
228
229 release-only:
230         @if [ "$(shell git status --porcelain | egrep -v '^\?\? ')" = "" ]; then \
231                 exit 0 ; \
232         else \
233           echo "" >&2 ; \
234                 echo "The git repository is not clean." >&2 ; \
235                 echo "Please commit changes before building release tarball." >&2 ; \
236                 echo "" >&2 ; \
237                 git status --porcelain | egrep -v '^\?\?' >&2 ; \
238                 echo "" >&2 ; \
239                 exit 1 ; \
240         fi
241         @if [ "$(NIGHTLY)" != "" -o "$(RELEASE)" = "1" ]; then \
242                 exit 0; \
243         else \
244           echo "" >&2 ; \
245                 echo "#NODE_VERSION_IS_RELEASE is set to $(RELEASE)." >&2 ; \
246           echo "Did you remember to update src/node_version.h?" >&2 ; \
247           echo "" >&2 ; \
248                 exit 1 ; \
249         fi
250
251 pkg: $(PKG)
252
253 $(PKG): release-only
254         rm -rf $(PKGDIR)
255         rm -rf out/deps out/Release
256         $(PYTHON) ./configure --dest-cpu=ia32 --tag=$(TAG)
257         $(MAKE) install V=$(V) DESTDIR=$(PKGDIR)/32
258         rm -rf out/deps out/Release
259         $(PYTHON) ./configure --dest-cpu=x64 --tag=$(TAG)
260         $(MAKE) install V=$(V) DESTDIR=$(PKGDIR)
261         SIGN="$(APP_SIGN)" PKGDIR="$(PKGDIR)" bash tools/osx-codesign.sh
262         lipo $(PKGDIR)/32/usr/local/bin/iojs \
263                 $(PKGDIR)/usr/local/bin/iojs \
264                 -output $(PKGDIR)/usr/local/bin/iojs-universal \
265                 -create
266         mv $(PKGDIR)/usr/local/bin/iojs-universal $(PKGDIR)/usr/local/bin/iojs
267         rm -rf $(PKGDIR)/32
268         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
269         $(PACKAGEMAKER) \
270                 --id "org.nodejs.Node" \
271                 --doc tools/osx-pkg.pmdoc \
272                 --out $(PKG)
273         SIGN="$(INT_SIGN)" PKG="$(PKG)" bash tools/osx-productsign.sh
274
275 $(TARBALL): release-only $(NODE_EXE) doc
276         git checkout-index -a -f --prefix=$(TARNAME)/
277         mkdir -p $(TARNAME)/doc/api
278         cp doc/iojs.1 $(TARNAME)/doc/iojs.1
279         cp -r out/doc/api/* $(TARNAME)/doc/api/
280         rm -rf $(TARNAME)/deps/v8/{test,samples,tools/profviz} # too big
281         rm -rf $(TARNAME)/doc/images # too big
282         rm -rf $(TARNAME)/deps/uv/{docs,samples,test}
283         rm -rf $(TARNAME)/deps/openssl/{doc,demos,test}
284         rm -rf $(TARNAME)/deps/zlib/contrib # too big, unused
285         find $(TARNAME)/ -type l | xargs rm # annoying on windows
286         tar -cf $(TARNAME).tar $(TARNAME)
287         rm -rf $(TARNAME)
288         gzip -c -f -9 $(TARNAME).tar > $(TARNAME).tar.gz
289 ifeq ($(XZ), 0)
290         xz -c -f -$(XZ_COMPRESSION) $(TARNAME).tar > $(TARNAME).tar.xz
291 endif
292         rm $(TARNAME).tar
293
294 tar: $(TARBALL)
295
296 $(BINARYTAR): release-only
297         rm -rf $(BINARYNAME)
298         rm -rf out/deps out/Release
299         $(PYTHON) ./configure --prefix=/ --dest-cpu=$(DESTCPU) --tag=$(TAG) $(CONFIG_FLAGS)
300         $(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1
301         cp README.md $(BINARYNAME)
302         cp LICENSE $(BINARYNAME)
303         cp CHANGELOG.md $(BINARYNAME)
304         tar -cf $(BINARYNAME).tar $(BINARYNAME)
305         rm -rf $(BINARYNAME)
306         gzip -c -f -9 $(BINARYNAME).tar > $(BINARYNAME).tar.gz
307 ifeq ($(XZ), 0)
308         xz -c -f -$(XZ_COMPRESSION) $(BINARYNAME).tar > $(BINARYNAME).tar.xz
309 endif
310         rm $(BINARYNAME).tar
311
312 binary: $(BINARYTAR)
313
314 $(PKGSRC): release-only
315         rm -rf dist out
316         $(PYTHON) configure --prefix=/ \
317                 --dest-cpu=$(DESTCPU) --tag=$(TAG) $(CONFIG_FLAGS)
318         $(MAKE) install DESTDIR=dist
319         (cd dist; find * -type f | sort) > packlist
320         pkg_info -X pkg_install | \
321                 egrep '^(MACHINE_ARCH|OPSYS|OS_VERSION|PKGTOOLS_VERSION)' > build-info
322         pkg_create -B build-info -c tools/pkgsrc/comment -d tools/pkgsrc/description \
323                 -f packlist -I /opt/local -p dist -U $(PKGSRC)
324
325 pkgsrc: $(PKGSRC)
326
327 haswrk=$(shell which wrk > /dev/null 2>&1; echo $$?)
328 wrk:
329 ifneq ($(haswrk), 0)
330         @echo "please install wrk before proceeding. More information can be found in benchmark/README.md." >&2
331         @exit 1
332 endif
333
334 bench-net: all
335         @$(NODE) benchmark/common.js net
336
337 bench-crypto: all
338         @$(NODE) benchmark/common.js crypto
339
340 bench-tls: all
341         @$(NODE) benchmark/common.js tls
342
343 bench-http: wrk all
344         @$(NODE) benchmark/common.js http
345
346 bench-fs: all
347         @$(NODE) benchmark/common.js fs
348
349 bench-misc: all
350         @$(MAKE) -C benchmark/misc/function_call/
351         @$(NODE) benchmark/common.js misc
352
353 bench-array: all
354         @$(NODE) benchmark/common.js arrays
355
356 bench-buffer: all
357         @$(NODE) benchmark/common.js buffers
358
359 bench-url: all
360         @$(NODE) benchmark/common.js url
361
362 bench-events: all
363         @$(NODE) benchmark/common.js events
364
365 bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events
366
367 bench: bench-net bench-http bench-fs bench-tls
368
369 bench-http-simple:
370          benchmark/http_simple_bench.sh
371
372 bench-idle:
373         ./$(NODE_EXE) benchmark/idle_server.js &
374         sleep 1
375         ./$(NODE_EXE) benchmark/idle_clients.js &
376
377 jslint:
378         ./$(NODE_EXE) tools/eslint/bin/eslint.js src/*.js lib/*.js --reset --quiet
379
380 CPPLINT_EXCLUDE ?=
381 CPPLINT_EXCLUDE += src/node_lttng.cc
382 CPPLINT_EXCLUDE += src/node_root_certs.h
383 CPPLINT_EXCLUDE += src/node_lttng_tp.h
384 CPPLINT_EXCLUDE += src/node_win32_perfctr_provider.cc
385 CPPLINT_EXCLUDE += src/queue.h
386 CPPLINT_EXCLUDE += src/tree.h
387 CPPLINT_EXCLUDE += src/v8abbr.h
388
389 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/*))
390
391 cpplint:
392         @$(PYTHON) tools/cpplint.py $(CPPLINT_FILES)
393
394 lint: jslint cpplint
395
396 .PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean \
397         check uninstall install install-includes install-bin all staticlib \
398         dynamiclib test test-all test-addons build-addons website-upload pkg \
399         blog blogclean tar binary release-only bench-http-simple bench-idle \
400         bench-all bench bench-misc bench-array bench-buffer bench-net \
401         bench-http bench-fs bench-tls cctest