build: first set of updates to enable PPC support
[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 ifeq ($(DESTCPU),ppc64)
246 ARCH=ppc64
247 else
248 ifeq ($(DESTCPU),ppc)
249 ARCH=ppc
250 else
251 ARCH=x86
252 endif
253 endif
254 endif
255 endif
256
257 # enforce "x86" over "ia32" as the generally accepted way of referring to 32-bit intel
258 ifeq ($(ARCH),ia32)
259 override ARCH=x86
260 endif
261 ifeq ($(DESTCPU),ia32)
262 override DESTCPU=x86
263 endif
264
265 TARNAME=iojs-$(FULLVERSION)
266 TARBALL=$(TARNAME).tar
267 BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH)
268 BINARYTAR=$(BINARYNAME).tar
269 # OSX doesn't have xz installed by default, http://macpkg.sourceforge.net/
270 XZ=$(shell which xz > /dev/null 2>&1; echo $$?)
271 XZ_COMPRESSION ?= 9
272 PKG=$(TARNAME).pkg
273 PACKAGEMAKER ?= /Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker
274 PKGDIR=out/dist-osx
275
276 release-only:
277         @if [ "$(shell git status --porcelain | egrep -v '^\?\? ')" = "" ]; then \
278                 exit 0 ; \
279         else \
280                 echo "" >&2 ; \
281                 echo "The git repository is not clean." >&2 ; \
282                 echo "Please commit changes before building release tarball." >&2 ; \
283                 echo "" >&2 ; \
284                 git status --porcelain | egrep -v '^\?\?' >&2 ; \
285                 echo "" >&2 ; \
286                 exit 1 ; \
287         fi
288         @if [ "$(DISTTYPE)" != "release" -o "$(RELEASE)" = "1" ]; then \
289                 exit 0; \
290         else \
291                 echo "" >&2 ; \
292                 echo "#NODE_VERSION_IS_RELEASE is set to $(RELEASE)." >&2 ; \
293                 echo "Did you remember to update src/node_version.h?" >&2 ; \
294                 echo "" >&2 ; \
295                 exit 1 ; \
296         fi
297
298 $(PKG): release-only
299         rm -rf $(PKGDIR)
300         rm -rf out/deps out/Release
301         $(PYTHON) ./configure \
302                 --dest-cpu=x64 \
303                 --tag=$(TAG) \
304                 --release-urlbase=$(RELEASE_URLBASE) \
305                 $(CONFIG_FLAGS)
306         $(MAKE) install V=$(V) DESTDIR=$(PKGDIR)
307         SIGN="$(CODESIGN_CERT)" PKGDIR="$(PKGDIR)" bash tools/osx-codesign.sh
308         cat tools/osx-pkg.pmdoc/index.xml.tmpl \
309                 | sed -E "s/\\{iojsversion\\}/$(FULLVERSION)/g" \
310                 | sed -E "s/\\{npmversion\\}/$(NPMVERSION)/g" \
311                 > tools/osx-pkg.pmdoc/index.xml
312         $(PACKAGEMAKER) \
313                 --id "org.iojs.pkg" \
314                 --doc tools/osx-pkg.pmdoc \
315                 --out $(PKG)
316         SIGN="$(PRODUCTSIGN_CERT)" PKG="$(PKG)" bash tools/osx-productsign.sh
317
318 pkg: $(PKG)
319
320 pkg-upload: pkg
321         ssh $(STAGINGSERVER) "mkdir -p staging/$(DISTTYPEDIR)/$(FULLVERSION)"
322         scp -p iojs-$(FULLVERSION).pkg $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/iojs-$(FULLVERSION).pkg
323         ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/iojs-$(FULLVERSION).pkg.done"
324
325 $(TARBALL): release-only $(NODE_EXE) doc
326         git checkout-index -a -f --prefix=$(TARNAME)/
327         mkdir -p $(TARNAME)/doc/api
328         cp doc/iojs.1 $(TARNAME)/doc/iojs.1
329         cp -r out/doc/api/* $(TARNAME)/doc/api/
330         rm -rf $(TARNAME)/deps/v8/{test,samples,tools/profviz} # too big
331         rm -rf $(TARNAME)/doc/images # too big
332         rm -rf $(TARNAME)/deps/uv/{docs,samples,test}
333         rm -rf $(TARNAME)/deps/openssl/{doc,demos,test}
334         rm -rf $(TARNAME)/deps/zlib/contrib # too big, unused
335         find $(TARNAME)/ -type l | xargs rm # annoying on windows
336         tar -cf $(TARNAME).tar $(TARNAME)
337         rm -rf $(TARNAME)
338         gzip -c -f -9 $(TARNAME).tar > $(TARNAME).tar.gz
339 ifeq ($(XZ), 0)
340         xz -c -f -$(XZ_COMPRESSION) $(TARNAME).tar > $(TARNAME).tar.xz
341 endif
342         rm $(TARNAME).tar
343
344 tar: $(TARBALL)
345
346 tar-upload: tar
347         ssh $(STAGINGSERVER) "mkdir -p staging/$(DISTTYPEDIR)/$(FULLVERSION)"
348         scp -p iojs-$(FULLVERSION).tar.gz $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/iojs-$(FULLVERSION).tar.gz
349         ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/iojs-$(FULLVERSION).tar.gz.done"
350 ifeq ($(XZ), 0)
351         scp -p iojs-$(FULLVERSION).tar.xz $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/iojs-$(FULLVERSION).tar.xz
352         ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/iojs-$(FULLVERSION).tar.xz.done"
353 endif
354
355 doc-upload: tar
356         ssh $(STAGINGSERVER) "mkdir -p staging/$(DISTTYPEDIR)/$(FULLVERSION)"
357         scp -r out/doc/ $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/
358         ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/doc.done"
359
360 $(TARBALL)-headers: config.gypi release-only
361         $(PYTHON) ./configure \
362                 --prefix=/ \
363                 --dest-cpu=$(DESTCPU) \
364                 --tag=$(TAG) \
365                 --release-urlbase=$(RELEASE_URLBASE) \
366                 $(CONFIG_FLAGS)
367         HEADERS_ONLY=1 $(PYTHON) tools/install.py install '$(TARNAME)' '/'
368         find $(TARNAME)/ -type l | xargs rm # annoying on windows
369         tar -cf $(TARNAME)-headers.tar $(TARNAME)
370         rm -rf $(TARNAME)
371         gzip -c -f -9 $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.gz
372 ifeq ($(XZ), 0)
373         xz -c -f -$(XZ_COMPRESSION) $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.xz
374 endif
375         rm $(TARNAME)-headers.tar
376
377 tar-headers: $(TARBALL)-headers
378
379 tar-headers-upload: tar-headers
380         ssh $(STAGINGSERVER) "mkdir -p staging/$(DISTTYPEDIR)/$(FULLVERSION)"
381         scp -p $(TARNAME)-headers.tar.gz $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz
382         ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz.done"
383 ifeq ($(XZ), 0)
384         scp -p $(TARNAME)-headers.tar.xz $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz
385         ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz.done"
386 endif
387
388 $(BINARYTAR): release-only
389         rm -rf $(BINARYNAME)
390         rm -rf out/deps out/Release
391         $(PYTHON) ./configure \
392                 --prefix=/ \
393                 --dest-cpu=$(DESTCPU) \
394                 --tag=$(TAG) \
395                 --release-urlbase=$(RELEASE_URLBASE) \
396                 $(CONFIG_FLAGS)
397         $(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1
398         cp README.md $(BINARYNAME)
399         cp LICENSE $(BINARYNAME)
400         cp CHANGELOG.md $(BINARYNAME)
401         tar -cf $(BINARYNAME).tar $(BINARYNAME)
402         rm -rf $(BINARYNAME)
403         gzip -c -f -9 $(BINARYNAME).tar > $(BINARYNAME).tar.gz
404 ifeq ($(XZ), 0)
405         xz -c -f -$(XZ_COMPRESSION) $(BINARYNAME).tar > $(BINARYNAME).tar.xz
406 endif
407         rm $(BINARYNAME).tar
408
409 binary: $(BINARYTAR)
410
411 binary-upload: binary
412         ssh $(STAGINGSERVER) "mkdir -p staging/$(DISTTYPEDIR)/$(FULLVERSION)"
413         scp -p iojs-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/iojs-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz
414         ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/iojs-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.gz.done"
415 ifeq ($(XZ), 0)
416         scp -p iojs-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz $(STAGINGSERVER):staging/$(DISTTYPEDIR)/$(FULLVERSION)/iojs-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz
417         ssh $(STAGINGSERVER) "touch staging/$(DISTTYPEDIR)/$(FULLVERSION)/iojs-$(FULLVERSION)-$(OSTYPE)-$(ARCH).tar.xz.done"
418 endif
419
420 haswrk=$(shell which wrk > /dev/null 2>&1; echo $$?)
421 wrk:
422 ifneq ($(haswrk), 0)
423         @echo "please install wrk before proceeding. More information can be found in benchmark/README.md." >&2
424         @exit 1
425 endif
426
427 bench-net: all
428         @$(NODE) benchmark/common.js net
429
430 bench-crypto: all
431         @$(NODE) benchmark/common.js crypto
432
433 bench-tls: all
434         @$(NODE) benchmark/common.js tls
435
436 bench-http: wrk all
437         @$(NODE) benchmark/common.js http
438
439 bench-fs: all
440         @$(NODE) benchmark/common.js fs
441
442 bench-misc: all
443         @$(MAKE) -C benchmark/misc/function_call/
444         @$(NODE) benchmark/common.js misc
445
446 bench-array: all
447         @$(NODE) benchmark/common.js arrays
448
449 bench-buffer: all
450         @$(NODE) benchmark/common.js buffers
451
452 bench-url: all
453         @$(NODE) benchmark/common.js url
454
455 bench-events: all
456         @$(NODE) benchmark/common.js events
457
458 bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events
459
460 bench: bench-net bench-http bench-fs bench-tls
461
462 bench-http-simple:
463         benchmark/http_simple_bench.sh
464
465 bench-idle:
466         $(NODE) benchmark/idle_server.js &
467         sleep 1
468         $(NODE) benchmark/idle_clients.js &
469
470 jslint:
471         $(NODE) tools/eslint/bin/eslint.js src lib test --rulesdir tools/eslint-rules --reset --quiet
472
473 CPPLINT_EXCLUDE ?=
474 CPPLINT_EXCLUDE += src/node_lttng.cc
475 CPPLINT_EXCLUDE += src/node_root_certs.h
476 CPPLINT_EXCLUDE += src/node_lttng_tp.h
477 CPPLINT_EXCLUDE += src/node_win32_perfctr_provider.cc
478 CPPLINT_EXCLUDE += src/queue.h
479 CPPLINT_EXCLUDE += src/tree.h
480 CPPLINT_EXCLUDE += src/v8abbr.h
481
482 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/*))
483
484 cpplint:
485         @$(PYTHON) tools/cpplint.py $(CPPLINT_FILES)
486
487 lint: jslint cpplint
488
489 .PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean \
490         check uninstall install install-includes install-bin all staticlib \
491         dynamiclib test test-all test-addons build-addons website-upload pkg \
492         blog blogclean tar binary release-only bench-http-simple bench-idle \
493         bench-all bench bench-misc bench-array bench-buffer bench-net \
494         bench-http bench-fs bench-tls cctest run-ci