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