build: rename ChangeLog to CHANGELOG.md in build
[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 website_files = \
192         out/doc/sh_main.js    \
193         out/doc/sh_javascript.min.js
194
195 doc: $(apidoc_dirs) $(website_files) $(apiassets) $(apidocs) tools/doc/ $(NODE_EXE)
196
197 $(apidoc_dirs):
198         mkdir -p $@
199
200 out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets/
201         cp $< $@
202
203 out/doc/changelog.html: CHANGELOG.md doc/changelog-head.html doc/changelog-foot.html tools/build-changelog.sh $(NODE_EXE)
204         bash tools/build-changelog.sh
205
206 out/doc/%: doc/%
207         cp -r $< $@
208
209 out/doc/api/%.json: doc/api/%.markdown $(NODE_EXE)
210         out/Release/$(NODE_EXE) tools/doc/generate.js --format=json $< > $@
211
212 out/doc/api/%.html: doc/api/%.markdown $(NODE_EXE)
213         out/Release/$(NODE_EXE) tools/doc/generate.js --format=html --template=doc/template.html $< > $@
214
215 email.md: CHANGELOG.md tools/email-footer.md
216         bash tools/changelog-head.sh | sed 's|^\* #|* \\#|g' > $@
217         cat tools/email-footer.md | sed -e 's|__VERSION__|'$(VERSION)'|g' >> $@
218
219 blog.html: email.md
220         cat $< | ./$(NODE_EXE) tools/doc/node_modules/.bin/marked > $@
221
222 docopen: out/doc/api/all.html
223         -google-chrome out/doc/api/all.html
224
225 docclean:
226         -rm -rf out/doc
227
228 RAWVER=$(shell $(PYTHON) tools/getnodeversion.py)
229 VERSION=v$(RAWVER)
230 RELEASE=$(shell $(PYTHON) tools/getnodeisrelease.py)
231 PLATFORM=$(shell uname | tr '[:upper:]' '[:lower:]')
232 ifeq ($(findstring x86_64,$(shell uname -m)),x86_64)
233 DESTCPU ?= x64
234 else
235 DESTCPU ?= ia32
236 endif
237 ifeq ($(DESTCPU),x64)
238 ARCH=x64
239 else
240 ifeq ($(DESTCPU),arm)
241 ARCH=arm
242 else
243 ARCH=x86
244 endif
245 endif
246 TARNAME=iojs-$(VERSION)
247 ifdef NIGHTLY
248 TAG = nightly-$(NIGHTLY)
249 TARNAME=iojs-$(VERSION)-$(TAG)
250 endif
251 TARBALL=$(TARNAME).tar
252 BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH)
253 BINARYTAR=$(BINARYNAME).tar
254 XZ=$(shell which xz > /dev/null 2>&1; echo $$?)
255 PKG=out/$(TARNAME).pkg
256 packagemaker=/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker
257
258 PKGSRC=iojs-$(DESTCPU)-$(RAWVER).tgz
259 ifdef NIGHTLY
260 PKGSRC=iojs-$(DESTCPU)-$(RAWVER)-$(TAG).tgz
261 endif
262
263 dist: doc $(TARBALL) $(PKG)
264
265 PKGDIR=out/dist-osx
266
267 release-only:
268         @if [ "$(shell git status --porcelain | egrep -v '^\?\? ')" = "" ]; then \
269                 exit 0 ; \
270         else \
271           echo "" >&2 ; \
272                 echo "The git repository is not clean." >&2 ; \
273                 echo "Please commit changes before building release tarball." >&2 ; \
274                 echo "" >&2 ; \
275                 git status --porcelain | egrep -v '^\?\?' >&2 ; \
276                 echo "" >&2 ; \
277                 exit 1 ; \
278         fi
279         @if [ "$(NIGHTLY)" != "" -o "$(RELEASE)" = "1" ]; then \
280                 exit 0; \
281         else \
282           echo "" >&2 ; \
283                 echo "#NODE_VERSION_IS_RELEASE is set to $(RELEASE)." >&2 ; \
284           echo "Did you remember to update src/node_version.cc?" >&2 ; \
285           echo "" >&2 ; \
286                 exit 1 ; \
287         fi
288
289 pkg: $(PKG)
290
291 $(PKG): release-only
292         rm -rf $(PKGDIR)
293         rm -rf out/deps out/Release
294         $(PYTHON) ./configure --without-snapshot --dest-cpu=ia32 --tag=$(TAG)
295         $(MAKE) install V=$(V) DESTDIR=$(PKGDIR)/32
296         rm -rf out/deps out/Release
297         $(PYTHON) ./configure --without-snapshot --dest-cpu=x64 --tag=$(TAG)
298         $(MAKE) install V=$(V) DESTDIR=$(PKGDIR)
299         SIGN="$(APP_SIGN)" PKGDIR="$(PKGDIR)" bash tools/osx-codesign.sh
300         lipo $(PKGDIR)/32/usr/local/bin/iojs \
301                 $(PKGDIR)/usr/local/bin/iojs \
302                 -output $(PKGDIR)/usr/local/bin/iojs-universal \
303                 -create
304         mv $(PKGDIR)/usr/local/bin/iojs-universal $(PKGDIR)/usr/local/bin/iojs
305         rm -rf $(PKGDIR)/32
306         $(packagemaker) \
307                 --id "org.nodejs.Node" \
308                 --doc tools/osx-pkg.pmdoc \
309                 --out $(PKG)
310         SIGN="$(INT_SIGN)" PKG="$(PKG)" bash tools/osx-productsign.sh
311
312 $(TARBALL): release-only $(NODE_EXE) doc
313         git archive --format=tar --prefix=$(TARNAME)/ HEAD | tar xf -
314         mkdir -p $(TARNAME)/doc/api
315         cp doc/iojs.1 $(TARNAME)/doc/iojs.1
316         cp -r out/doc/api/* $(TARNAME)/doc/api/
317         rm -rf $(TARNAME)/deps/v8/test # too big
318         rm -rf $(TARNAME)/doc/images # too big
319         rm -rf $(TARNAME)/deps/zlib/contrib # too big, unused
320         find $(TARNAME)/ -type l | xargs rm # annoying on windows
321         tar -cf $(TARNAME).tar $(TARNAME)
322         rm -rf $(TARNAME)
323         gzip -c -f -9 $(TARNAME).tar > $(TARNAME).tar.gz
324 ifeq ($(XZ), 0)
325         xz -c -f -9 $(TARNAME).tar > $(TARNAME).tar.xz
326 endif
327         rm $(TARNAME).tar
328
329 tar: $(TARBALL)
330
331 $(BINARYTAR): release-only
332         rm -rf $(BINARYNAME)
333         rm -rf out/deps out/Release
334         $(PYTHON) ./configure --prefix=/ --without-snapshot --dest-cpu=$(DESTCPU) --tag=$(TAG) $(CONFIG_FLAGS)
335         $(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1
336         cp README.md $(BINARYNAME)
337         cp LICENSE $(BINARYNAME)
338         cp CHANGELOG.md $(BINARYNAME)
339         tar -cf $(BINARYNAME).tar $(BINARYNAME)
340         rm -rf $(BINARYNAME)
341         gzip -c -f -9 $(BINARYNAME).tar > $(BINARYNAME).tar.gz
342 ifeq ($(XZ), 0)
343         xz -c -f -9 $(BINARYNAME).tar > $(BINARYNAME).tar.xz
344 endif
345         rm $(BINARYNAME).tar
346
347 binary: $(BINARYTAR)
348
349 $(PKGSRC): release-only
350         rm -rf dist out
351         $(PYTHON) configure --prefix=/ --without-snapshot \
352                 --dest-cpu=$(DESTCPU) --tag=$(TAG) $(CONFIG_FLAGS)
353         $(MAKE) install DESTDIR=dist
354         (cd dist; find * -type f | sort) > packlist
355         pkg_info -X pkg_install | \
356                 egrep '^(MACHINE_ARCH|OPSYS|OS_VERSION|PKGTOOLS_VERSION)' > build-info
357         pkg_create -B build-info -c tools/pkgsrc/comment -d tools/pkgsrc/description \
358                 -f packlist -I /opt/local -p dist -U $(PKGSRC)
359
360 pkgsrc: $(PKGSRC)
361
362 wrkclean:
363         $(MAKE) -C tools/wrk/ clean
364         rm tools/wrk/wrk
365
366 wrk: tools/wrk/wrk
367 tools/wrk/wrk:
368         $(MAKE) -C tools/wrk/
369
370 bench-net: all
371         @$(NODE) benchmark/common.js net
372
373 bench-crypto: all
374         @$(NODE) benchmark/common.js crypto
375
376 bench-tls: all
377         @$(NODE) benchmark/common.js tls
378
379 bench-http: wrk all
380         @$(NODE) benchmark/common.js http
381
382 bench-fs: all
383         @$(NODE) benchmark/common.js fs
384
385 bench-misc: all
386         @$(MAKE) -C benchmark/misc/function_call/
387         @$(NODE) benchmark/common.js misc
388
389 bench-array: all
390         @$(NODE) benchmark/common.js arrays
391
392 bench-buffer: all
393         @$(NODE) benchmark/common.js buffers
394
395 bench-all: bench bench-misc bench-array bench-buffer
396
397 bench: bench-net bench-http bench-fs bench-tls
398
399 bench-http-simple:
400          benchmark/http_simple_bench.sh
401
402 bench-idle:
403         ./$(NODE_EXE) benchmark/idle_server.js &
404         sleep 1
405         ./$(NODE_EXE) benchmark/idle_clients.js &
406
407 jslintfix:
408         PYTHONPATH=tools/closure_linter/ $(PYTHON) tools/closure_linter/closure_linter/fixjsstyle.py --strict --nojsdoc -r lib/ -r src/ --exclude_files lib/punycode.js
409
410 jslint:
411         PYTHONPATH=tools/closure_linter/ $(PYTHON) tools/closure_linter/closure_linter/gjslint.py --unix_mode --strict --nojsdoc -r lib/ -r src/ --exclude_files lib/punycode.js
412
413 CPPLINT_EXCLUDE ?=
414 CPPLINT_EXCLUDE += src/node_dtrace.cc
415 CPPLINT_EXCLUDE += src/node_dtrace.cc
416 CPPLINT_EXCLUDE += src/node_root_certs.h
417 CPPLINT_EXCLUDE += src/node_win32_perfctr_provider.cc
418 CPPLINT_EXCLUDE += src/queue.h
419 CPPLINT_EXCLUDE += src/tree.h
420 CPPLINT_EXCLUDE += src/v8abbr.h
421
422 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/*))
423
424 cpplint:
425         @$(PYTHON) tools/cpplint.py $(CPPLINT_FILES)
426
427 lint: jslint cpplint
428
429 .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