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