Skip to content

HTTPS clone URL

Subversion checkout URL

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