Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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