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