Merge remote-tracking branch 'ry/v0.8' into master
[platform/upstream/nodejs.git] / Makefile
1 -include config.mk
2
3 BUILDTYPE ?= Release
4 PYTHON ?= python
5 NINJA ?= ninja
6 DESTDIR ?=
7 SIGN ?=
8
9 # Default to verbose builds.
10 # To do quiet/pretty builds, run `make V=` to set V to an empty string,
11 # or set the V environment variable to an empty string.
12 V ?= 1
13
14 # BUILDTYPE=Debug builds both release and debug builds. If you want to compile
15 # just the debug build, run `make -C out BUILDTYPE=Debug` instead.
16 ifeq ($(BUILDTYPE),Release)
17 all: out/Makefile node
18 else
19 all: out/Makefile node node_g
20 endif
21
22 # The .PHONY is needed to ensure that we recursively use the out/Makefile
23 # to check for changes.
24 .PHONY: node node_g
25
26 ifeq ($(USE_NINJA),1)
27 node: config.gypi
28         $(NINJA) -C out/Release/
29         ln -fs out/Release/node node
30
31 node_g: config.gypi
32         $(NINJA) -C out/Debug/
33         ln -fs out/Debug/node $@
34 else
35 node: config.gypi out/Makefile
36         $(MAKE) -C out BUILDTYPE=Release V=$(V)
37         ln -fs out/Release/node node
38
39 node_g: config.gypi out/Makefile
40         $(MAKE) -C out BUILDTYPE=Debug V=$(V)
41         ln -fs out/Debug/node $@
42 endif
43
44 out/Makefile: common.gypi deps/uv/uv.gyp deps/http_parser/http_parser.gyp deps/zlib/zlib.gyp deps/v8/build/common.gypi deps/v8/tools/gyp/v8.gyp node.gyp config.gypi
45 ifeq ($(USE_NINJA),1)
46         touch out/Makefile
47         $(PYTHON) tools/gyp_node -f ninja
48 else
49         $(PYTHON) tools/gyp_node -f make
50 endif
51
52 config.gypi: configure
53         ./configure
54
55 install: all
56         $(PYTHON) tools/install.py $@ $(DESTDIR)
57
58 uninstall:
59         $(PYTHON) tools/install.py $@ $(DESTDIR)
60
61 clean:
62         -rm -rf out/Makefile node node_g out/$(BUILDTYPE)/node blog.html email.md
63         -find out/ -name '*.o' -o -name '*.a' | xargs rm -rf
64         -rm -rf node_modules
65
66 distclean:
67         -rm -rf out
68         -rm -f config.gypi
69         -rm -f config.mk
70         -rm -rf node node_g blog.html email.md
71         -rm -rf node_modules
72
73 test: all
74         $(PYTHON) tools/test.py --mode=release simple message
75         $(MAKE) jslint
76
77 test-http1: all
78         $(PYTHON) tools/test.py --mode=release --use-http1 simple message
79
80 test-valgrind: all
81         $(PYTHON) tools/test.py --mode=release --valgrind simple message
82
83 test/gc/node_modules/weak/build:
84         @if [ ! -f node ]; then make all; fi
85         ./node 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 test-gc: all test/gc/node_modules/weak/build
90         $(PYTHON) tools/test.py --mode=release gc
91
92 test-all: all test/gc/node_modules/weak/build
93         $(PYTHON) tools/test.py --mode=debug,release
94         make test-npm
95
96 test-all-http1: all
97         $(PYTHON) tools/test.py --mode=debug,release --use-http1
98
99 test-all-valgrind: all
100         $(PYTHON) tools/test.py --mode=debug,release --valgrind
101
102 test-release: all
103         $(PYTHON) tools/test.py --mode=release
104
105 test-debug: all
106         $(PYTHON) tools/test.py --mode=debug
107
108 test-message: all
109         $(PYTHON) tools/test.py message
110
111 test-simple: all
112         $(PYTHON) tools/test.py simple
113
114 test-pummel: all
115         $(PYTHON) tools/test.py pummel
116
117 test-internet: all
118         $(PYTHON) tools/test.py internet
119
120 test-npm: node
121         ./node deps/npm/test/run.js
122
123 test-npm-publish: node
124         npm_package_config_publishtest=true ./node deps/npm/test/run.js
125
126 apidoc_sources = $(wildcard doc/api/*.markdown)
127 apidocs = $(addprefix out/,$(apidoc_sources:.markdown=.html)) \
128           $(addprefix out/,$(apidoc_sources:.markdown=.json))
129
130 apidoc_dirs = out/doc out/doc/api/ out/doc/api/assets out/doc/about out/doc/community out/doc/download out/doc/logos out/doc/images
131
132 apiassets = $(subst api_assets,api/assets,$(addprefix out/,$(wildcard doc/api_assets/*)))
133
134 doc_images = $(addprefix out/,$(wildcard doc/images/* doc/*.jpg doc/*.png))
135
136 website_files = \
137         out/doc/index.html    \
138         out/doc/v0.4_announcement.html   \
139         out/doc/cla.html      \
140         out/doc/sh_main.js    \
141         out/doc/sh_javascript.min.js \
142         out/doc/sh_vim-dark.css \
143         out/doc/sh.css \
144         out/doc/favicon.ico   \
145         out/doc/pipe.css \
146         out/doc/about/index.html \
147         out/doc/community/index.html \
148         out/doc/download/index.html \
149         out/doc/logos/index.html \
150         out/doc/changelog.html \
151         $(doc_images)
152
153 doc: $(apidoc_dirs) $(website_files) $(apiassets) $(apidocs) tools/doc/ blog node
154
155 blogclean:
156         rm -rf out/blog
157
158 blog: doc/blog out/Release/node tools/blog
159         out/Release/node tools/blog/generate.js doc/blog/ out/blog/ doc/blog.html doc/rss.xml
160
161 $(apidoc_dirs):
162         mkdir -p $@
163
164 out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets/
165         cp $< $@
166
167 out/doc/changelog.html: ChangeLog doc/changelog-head.html doc/changelog-foot.html tools/build-changelog.sh node
168         bash tools/build-changelog.sh
169
170 out/doc/%.html: doc/%.html node
171         cat $< | sed -e 's|__VERSION__|'$(VERSION)'|g' > $@
172
173 out/doc/%: doc/%
174         cp -r $< $@
175
176 out/doc/api/%.json: doc/api/%.markdown node
177         out/Release/node tools/doc/generate.js --format=json $< > $@
178
179 out/doc/api/%.html: doc/api/%.markdown node
180         out/Release/node tools/doc/generate.js --format=html --template=doc/template.html $< > $@
181
182 email.md: ChangeLog tools/email-footer.md
183         bash tools/changelog-head.sh | sed 's|^\* #|* \\#|g' > $@
184         cat tools/email-footer.md | sed -e 's|__VERSION__|'$(VERSION)'|g' >> $@
185
186 blog.html: email.md
187         cat $< | ./node tools/doc/node_modules/.bin/marked > $@
188
189 blog-upload: blog
190         rsync -r out/blog/ node@nodejs.org:~/web/nodejs.org/blog/
191
192 website-upload: doc
193         rsync -r out/doc/ node@nodejs.org:~/web/nodejs.org/
194         ssh node@nodejs.org '\
195     rm -f ~/web/nodejs.org/dist/latest &&\
196     ln -s $(VERSION) ~/web/nodejs.org/dist/latest &&\
197     rm -f ~/web/nodejs.org/docs/latest &&\
198     ln -s $(VERSION) ~/web/nodejs.org/docs/latest &&\
199     rm -f ~/web/nodejs.org/dist/node-latest.tar.gz &&\
200     ln -s $(VERSION)/node-$(VERSION).tar.gz ~/web/nodejs.org/dist/node-latest.tar.gz'
201
202 docopen: out/doc/api/all.html
203         -google-chrome out/doc/api/all.html
204
205 docclean:
206         -rm -rf out/doc
207
208 VERSION=v$(shell $(PYTHON) tools/getnodeversion.py)
209 RELEASE=$(shell $(PYTHON) tools/getnodeisrelease.py)
210 PLATFORM=$(shell uname | tr '[:upper:]' '[:lower:]')
211 ifeq ($(findstring x86_64,$(shell uname -m)),x86_64)
212 DESTCPU ?= x64
213 else
214 DESTCPU ?= ia32
215 endif
216 ifeq ($(DESTCPU),x64)
217 ARCH=x64
218 else
219 ARCH=x86
220 endif
221 TARNAME=node-$(VERSION)
222 TARBALL=$(TARNAME).tar.gz
223 BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH)
224 BINARYTAR=$(BINARYNAME).tar.gz
225 PKG=out/$(TARNAME).pkg
226 packagemaker=/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker
227
228 dist: doc $(TARBALL) $(PKG)
229
230 PKGDIR=out/dist-osx
231
232 release-only:
233         @if [ "$(shell git status --porcelain | egrep -v '^\?\? ')" = "" ]; then \
234                 exit 0 ; \
235         else \
236           echo "" >&2 ; \
237                 echo "The git repository is not clean." >&2 ; \
238                 echo "Please commit changes before building release tarball." >&2 ; \
239                 echo "" >&2 ; \
240                 git status --porcelain | egrep -v '^\?\?' >&2 ; \
241                 echo "" >&2 ; \
242                 exit 1 ; \
243         fi
244         @if [ "$(RELEASE)" = "1" ]; then \
245                 exit 0; \
246         else \
247           echo "" >&2 ; \
248                 echo "#NODE_VERSION_IS_RELEASE is set to $(RELEASE)." >&2 ; \
249           echo "Did you remember to update src/node_version.cc?" >&2 ; \
250           echo "" >&2 ; \
251                 exit 1 ; \
252         fi
253
254 pkg: $(PKG)
255
256 $(PKG): release-only
257         rm -rf $(PKGDIR)
258         rm -rf out/deps out/Release
259         ./configure --prefix=$(PKGDIR)/32/usr/local --without-snapshot --dest-cpu=ia32
260         $(MAKE) install V=$(V)
261         rm -rf out/deps out/Release
262         ./configure --prefix=$(PKGDIR)/usr/local --without-snapshot --dest-cpu=x64
263         $(MAKE) install V=$(V)
264         SIGN="$(SIGN)" PKGDIR="$(PKGDIR)" bash tools/osx-codesign.sh
265         lipo $(PKGDIR)/32/usr/local/bin/node \
266                 $(PKGDIR)/usr/local/bin/node \
267                 -output $(PKGDIR)/usr/local/bin/node-universal \
268                 -create
269         mv $(PKGDIR)/usr/local/bin/node-universal $(PKGDIR)/usr/local/bin/node
270         rm -rf $(PKGDIR)/32
271         $(packagemaker) \
272                 --id "org.nodejs.Node" \
273                 --doc tools/osx-pkg.pmdoc \
274                 --out $(PKG)
275         SIGN="$(SIGN)" PKG="$(PKG)" bash tools/osx-productsign.sh
276
277 $(TARBALL): release-only node doc
278         git archive --format=tar --prefix=$(TARNAME)/ HEAD | tar xf -
279         mkdir -p $(TARNAME)/doc/api
280         cp doc/node.1 $(TARNAME)/doc/node.1
281         cp -r out/doc/api/* $(TARNAME)/doc/api/
282         rm -rf $(TARNAME)/deps/v8/test # too big
283         rm -rf $(TARNAME)/doc/images # too big
284         find $(TARNAME)/ -type l | xargs rm # annoying on windows
285         tar -cf $(TARNAME).tar $(TARNAME)
286         rm -rf $(TARNAME)
287         gzip -f -9 $(TARNAME).tar
288
289 tar: $(TARBALL)
290
291 $(BINARYTAR): release-only
292         rm -rf $(BINARYNAME)
293         rm -rf out/deps out/Release
294         ./configure --prefix=/ --without-snapshot --dest-cpu=$(DESTCPU)
295         $(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1
296         cp README.md $(BINARYNAME)
297         cp LICENSE $(BINARYNAME)
298         cp ChangeLog $(BINARYNAME)
299         tar -cf $(BINARYNAME).tar $(BINARYNAME)
300         rm -rf $(BINARYNAME)
301         gzip -f -9 $(BINARYNAME).tar
302
303 binary: $(BINARYTAR)
304
305 dist-upload: $(TARBALL) $(PKG)
306         ssh node@nodejs.org mkdir -p web/nodejs.org/dist/$(VERSION)
307         scp $(TARBALL) node@nodejs.org:~/web/nodejs.org/dist/$(VERSION)/$(TARBALL)
308         scp $(PKG) node@nodejs.org:~/web/nodejs.org/dist/$(VERSION)/$(TARNAME).pkg
309
310 bench:
311          benchmark/http_simple_bench.sh
312
313 bench-idle:
314         ./node benchmark/idle_server.js &
315         sleep 1
316         ./node benchmark/idle_clients.js &
317
318 jslintfix:
319         PYTHONPATH=tools/closure_linter/ $(PYTHON) tools/closure_linter/closure_linter/fixjsstyle.py --strict --nojsdoc -r lib/ -r src/ --exclude_files lib/punycode.js
320
321 jslint:
322         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
323
324 cpplint:
325         @$(PYTHON) tools/cpplint.py $(wildcard src/*.cc src/*.h src/*.c)
326
327 lint: jslint cpplint
328
329 .PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean check uninstall install install-includes install-bin all staticlib dynamiclib test test-all website-upload pkg blog blogclean tar binary release-only