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