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