Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 282 lines (215 sloc) 7.475 kb
14b04b0 ry Remove SCONS deprecate WAF
ry authored
1 #!/usr/bin/env python
5cf4cef ry add configure
ry authored
2
14b04b0 ry Remove SCONS deprecate WAF
ry authored
3 import optparse
4 import os
45605c9 Johan Bergström gyp: switch json for pprint when generating config
jbergstroem authored
5 import pprint
b9e1bb3 Ben Noordhuis build: auto-run tools/gyp_node after ./configure
bnoordhuis authored
6 import subprocess
14b04b0 ry Remove SCONS deprecate WAF
ry authored
7 import sys
5cf4cef ry add configure
ry authored
8
14b04b0 ry Remove SCONS deprecate WAF
ry authored
9 root_dir = os.path.dirname(__file__)
10 sys.path.insert(0, os.path.join(root_dir, 'deps', 'v8', 'tools'))
97c9745 ry Back to WAF
ry authored
11
14b04b0 ry Remove SCONS deprecate WAF
ry authored
12 # parse our options
13 parser = optparse.OptionParser()
97c9745 ry Back to WAF
ry authored
14
14b04b0 ry Remove SCONS deprecate WAF
ry authored
15 parser.add_option("--debug",
16 action="store_true",
17 dest="debug",
18 help="Also build debug build")
19
20 parser.add_option("--prefix",
21 action="store",
22 dest="prefix",
23 help="Select the install prefix (defaults to /usr/local)")
24
a9f2c4a Fedor Indutny --without-npm option
indutny authored
25 parser.add_option("--without-npm",
26 action="store_true",
27 dest="without_npm",
28 help="Don\'t install the bundled npm package manager")
29
6e76a7c Fedor Indutny installer: install node-waf
indutny authored
30 parser.add_option("--without-waf",
31 action="store_true",
32 dest="without_waf",
33 help="Don\'t install node-waf")
34
b3d4938 Ben Noordhuis build: add --without-isolates configure switch
bnoordhuis authored
35 parser.add_option("--without-isolates",
36 action="store_true",
37 dest="without_isolates",
38 help="Build without isolates (no threads, single loop) [Default: False]")
39
14b04b0 ry Remove SCONS deprecate WAF
ry authored
40 parser.add_option("--without-ssl",
41 action="store_true",
42 dest="without_ssl",
43 help="Build without SSL")
44
45 parser.add_option("--without-snapshot",
46 action="store_true",
47 dest="without_snapshot",
48 help="Build without snapshotting V8 libraries. You might want to set"
49 " this for cross-compiling. [Default: False]")
50
51 parser.add_option("--shared-v8",
52 action="store_true",
53 dest="shared_v8",
54 help="Link to a shared V8 DLL instead of static linking")
55
56 parser.add_option("--shared-v8-includes",
57 action="store",
58 dest="shared_v8_includes",
59 help="Directory containing V8 header files")
60
61 parser.add_option("--shared-v8-libpath",
62 action="store",
63 dest="shared_v8_libpath",
64 help="A directory to search for the shared V8 DLL")
65
66 parser.add_option("--shared-v8-libname",
67 action="store",
68 dest="shared_v8_libname",
69 help="Alternative lib name to link to (default: 'v8')")
70
e61de70 ry gyp: use built-in openssl by default
ry authored
71 parser.add_option("--openssl-use-sys",
72 action="store",
73 dest="openssl_use_sys",
74 help="Use the system OpenSSL instead of one included with Node")
75
14b04b0 ry Remove SCONS deprecate WAF
ry authored
76 parser.add_option("--openssl-includes",
77 action="store",
78 dest="openssl_includes",
79 help="A directory to search for the OpenSSL includes")
80
81 parser.add_option("--openssl-libpath",
82 action="store",
83 dest="openssl_libpath",
84 help="A directory to search for the OpenSSL libraries")
85
86 parser.add_option("--no-ssl2",
87 action="store_true",
88 dest="no_ssl2",
89 help="Disable OpenSSL v2")
90
91 parser.add_option("--shared-cares",
92 action="store_true",
93 dest="shared_cares",
94 help="Link to a shared C-Ares DLL instead of static linking")
95
96 parser.add_option("--shared-cares-includes",
97 action="store",
98 dest="shared_cares_includes",
99 help="Directory containing C-Ares header files")
100
101 parser.add_option("--shared-cares-libpath",
102 action="store",
103 dest="shared_cares_libpath",
104 help="A directory to search for the shared C-Ares DLL")
105
106 parser.add_option("--with-dtrace",
107 action="store_true",
108 dest="with_dtrace",
109 help="Build with DTrace (experimental)")
110
111 # CHECKME does this still work with recent releases of V8?
112 parser.add_option("--gdb",
113 action="store_true",
114 dest="gdb",
115 help="add gdb support")
116
117 parser.add_option("--dest-cpu",
118 action="store",
119 dest="dest_cpu",
120 help="CPU architecture to build for. Valid values are: arm, ia32, x64")
121
122 (options, args) = parser.parse_args()
123
124
a033261 Ben Noordhuis build: DRY configure script
bnoordhuis authored
125 def b(value):
126 """Returns the string 'true' if value is truthy, 'false' otherwise."""
127 if value:
128 return 'true'
129 else:
130 return 'false'
131
132
14b04b0 ry Remove SCONS deprecate WAF
ry authored
133 def pkg_config(pkg):
134 cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
135 libs = cmd.readline().strip()
136 ret = cmd.close()
137 if (ret): return None
138
139 cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
140 cflags = cmd.readline().strip()
141 ret = cmd.close()
142 if (ret): return None
143
144 return (libs, cflags)
145
146
147 def uname(switch):
148 f = os.popen('uname %s' % switch)
149 s = f.read().strip()
150 f.close()
151 return s
152
153
154 def host_arch():
155 """Host architecture. One of arm, ia32 or x64."""
156 arch = uname('-p')
157
158 if arch == 'unknown':
159 arch = uname('-m')
160
161 return {
162 'arm': 'arm',
163 'x86': 'ia32',
164 'i386': 'ia32',
165 'x86_64': 'x64',
166 }.get(arch, 'ia32')
167
168
169 def target_arch():
170 return host_arch()
171
172
173 def configure_node(o):
93465d3 Ben Noordhuis build: support --dest-cpu configure switch again
bnoordhuis authored
174 # TODO add gdb
b3d4938 Ben Noordhuis build: add --without-isolates configure switch
bnoordhuis authored
175 o['variables']['node_use_isolates'] = b(not options.without_isolates)
a033261 Ben Noordhuis build: DRY configure script
bnoordhuis authored
176 o['variables']['node_debug'] = b(options.debug)
14b04b0 ry Remove SCONS deprecate WAF
ry authored
177 o['variables']['node_prefix'] = options.prefix if options.prefix else ''
a033261 Ben Noordhuis build: DRY configure script
bnoordhuis authored
178 o['variables']['node_use_dtrace'] = b(options.with_dtrace)
a9f2c4a Fedor Indutny --without-npm option
indutny authored
179 o['variables']['node_install_npm'] = b(not options.without_npm)
6e76a7c Fedor Indutny installer: install node-waf
indutny authored
180 o['variables']['node_install_waf'] = b(not options.without_waf)
14b04b0 ry Remove SCONS deprecate WAF
ry authored
181 o['variables']['host_arch'] = host_arch()
93465d3 Ben Noordhuis build: support --dest-cpu configure switch again
bnoordhuis authored
182 o['variables']['target_arch'] = options.dest_cpu or target_arch()
14b04b0 ry Remove SCONS deprecate WAF
ry authored
183
184 # TODO move to node.gyp
185 if sys.platform == 'sunos5':
186 o['variables']['visibility'] = '' # FIXME -fvisibility=hidden, should be a gcc check
187
188
189 def configure_libz(o):
190 o['libraries'] += ['-lz']
191
192
193 def configure_v8(o):
a033261 Ben Noordhuis build: DRY configure script
bnoordhuis authored
194 o['variables']['v8_use_snapshot'] = b(not options.without_snapshot)
195 o['variables']['node_shared_v8'] = b(options.shared_v8)
14b04b0 ry Remove SCONS deprecate WAF
ry authored
196
197 # assume shared_v8 if one of these is set?
198 if options.shared_v8_libpath:
199 o['libraries'] += ['-L%s' % options.shared_v8_libpath]
200 if options.shared_v8_libname:
201 o['libraries'] += ['-l%s' % options.shared_v8_libname]
202 if options.shared_v8_includes:
203 o['include_dirs'] += [options.shared_v8_includes]
204
205
206 def configure_cares(o):
a033261 Ben Noordhuis build: DRY configure script
bnoordhuis authored
207 o['variables']['node_shared_cares'] = b(options.shared_cares)
14b04b0 ry Remove SCONS deprecate WAF
ry authored
208
209 # assume shared_cares if one of these is set?
210 if options.shared_cares_libpath:
211 o['libraries'] += ['-L%s' % options.shared_cares_libpath]
212 if options.shared_cares_includes:
213 o['include_dirs'] += [options.shared_cares_includes]
214
215
216 def configure_openssl(o):
a033261 Ben Noordhuis build: DRY configure script
bnoordhuis authored
217 o['variables']['node_use_openssl'] = b(not options.without_ssl)
14b04b0 ry Remove SCONS deprecate WAF
ry authored
218
219 if options.without_ssl:
220 return
221
222 if options.no_ssl2:
223 o['defines'] += ['OPENSSL_NO_SSL2=1']
224
e61de70 ry gyp: use built-in openssl by default
ry authored
225 if not options.openssl_use_sys:
226 o['variables']['node_use_system_openssl'] = b(False)
14b04b0 ry Remove SCONS deprecate WAF
ry authored
227 else:
e61de70 ry gyp: use built-in openssl by default
ry authored
228 out = pkg_config('openssl')
229 (libs, cflags) = out if out else ('', '')
14b04b0 ry Remove SCONS deprecate WAF
ry authored
230
e61de70 ry gyp: use built-in openssl by default
ry authored
231 if options.openssl_libpath:
232 o['libraries'] += ['-L%s' % options.openssl_libpath, '-lssl', '-lcrypto']
233 else:
234 o['libraries'] += libs.split()
235
236 if options.openssl_includes:
237 o['include_dirs'] += [options.openssl_includes]
238 else:
239 o['cflags'] += cflags.split()
14b04b0 ry Remove SCONS deprecate WAF
ry authored
240
e61de70 ry gyp: use built-in openssl by default
ry authored
241 o['variables']['node_use_system_openssl'] = b(
242 libs or cflags or options.openssl_libpath or options.openssl_includes)
14b04b0 ry Remove SCONS deprecate WAF
ry authored
243
244
245 output = {
246 'variables': {},
247 'include_dirs': [],
248 'libraries': [],
249 'defines': [],
250 'cflags': [],
251 }
252
253 configure_node(output)
254 configure_libz(output)
255 configure_v8(output)
256 configure_cares(output)
257 configure_openssl(output)
258
259 # variables should be a root level element,
260 # move everything else to target_defaults
261 variables = output['variables']
262 del output['variables']
263 output = {
264 'variables': variables,
265 'target_defaults': output
266 }
624f70e ry GYP: rename options.gypi to config.gypi
ry authored
267 pprint.pprint(output, indent=2)
14b04b0 ry Remove SCONS deprecate WAF
ry authored
268
e493b29 Ben Noordhuis build: respect --debug configure switch
bnoordhuis authored
269 def write(filename, data):
270 filename = os.path.join(root_dir, filename)
271 print "creating ", filename
272 with open(filename, 'w+') as f:
273 f.write(data)
274
275 write('config.gypi', "# Do not edit. Generated by the configure script.\n" +
276 pprint.pformat(output, indent=2))
277
278 write('config.mk', "# Do not edit. Generated by the configure script.\n" +
279 ("BUILDTYPE=%s\n" % ('Debug' if options.debug else 'Release')))
97c9745 ry Back to WAF
ry authored
280
48d21dd ry Force makefile generation in gyp
ry authored
281 subprocess.call(['tools/gyp_node','-f', 'make'])
Something went wrong with that request. Please try again.