blob: 64cb864479b7f3916e99e82745aca7ccaae313c9 [file] [log] [blame]
Ryan Dahl14b04b02011-11-15 03:02:441#!/usr/bin/env python
Ryan Dahl5cf4cef2010-10-26 01:17:192
Ryan Dahl14b04b02011-11-15 03:02:443import optparse
4import os
jbergstroem45605c92011-12-18 22:53:075import pprint
Ben Noordhuisb9e1bb32011-11-15 16:17:056import subprocess
Ryan Dahl14b04b02011-11-15 03:02:447import sys
Ryan Dahl5cf4cef2010-10-26 01:17:198
Ryan Dahl14b04b02011-11-15 03:02:449root_dir = os.path.dirname(__file__)
10sys.path.insert(0, os.path.join(root_dir, 'deps', 'v8', 'tools'))
Ryan Dahl97c97452010-11-01 23:03:3211
Ryan Dahl14b04b02011-11-15 03:02:4412# parse our options
13parser = optparse.OptionParser()
Ryan Dahl97c97452010-11-01 23:03:3214
Ryan Dahl14b04b02011-11-15 03:02:4415parser.add_option("--debug",
16 action="store_true",
17 dest="debug",
18 help="Also build debug build")
Ryan Dahl97c97452010-11-01 23:03:3219
Ryan Dahl14b04b02011-11-15 03:02:4420parser.add_option("--prefix",
21 action="store",
22 dest="prefix",
23 help="Select the install prefix (defaults to /usr/local)")
24
Fedor Indutnya9f2c4a2011-12-17 08:09:1425parser.add_option("--without-npm",
26 action="store_true",
27 dest="without_npm",
28 help="Don\'t install the bundled npm package manager")
29
Ben Noordhuisb3d49382011-11-29 15:41:4130parser.add_option("--without-isolates",
31 action="store_true",
32 dest="without_isolates",
33 help="Build without isolates (no threads, single loop) [Default: False]")
34
Ryan Dahl14b04b02011-11-15 03:02:4435parser.add_option("--without-ssl",
36 action="store_true",
37 dest="without_ssl",
38 help="Build without SSL")
39
40parser.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
46parser.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
51parser.add_option("--shared-v8-includes",
52 action="store",
53 dest="shared_v8_includes",
54 help="Directory containing V8 header files")
55
56parser.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
61parser.add_option("--shared-v8-libname",
62 action="store",
63 dest="shared_v8_libname",
64 help="Alternative lib name to link to (default: 'v8')")
65
Ryan Dahle61de702011-12-16 23:00:2366parser.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
Ryan Dahl14b04b02011-11-15 03:02:4471parser.add_option("--openssl-includes",
72 action="store",
73 dest="openssl_includes",
74 help="A directory to search for the OpenSSL includes")
75
76parser.add_option("--openssl-libpath",
77 action="store",
78 dest="openssl_libpath",
79 help="A directory to search for the OpenSSL libraries")
80
81parser.add_option("--no-ssl2",
82 action="store_true",
83 dest="no_ssl2",
84 help="Disable OpenSSL v2")
85
86parser.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
91parser.add_option("--shared-cares-includes",
92 action="store",
93 dest="shared_cares_includes",
94 help="Directory containing C-Ares header files")
95
96parser.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
101parser.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?
107parser.add_option("--gdb",
108 action="store_true",
109 dest="gdb",
110 help="add gdb support")
111
112parser.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
Ben Noordhuisa0332612011-11-29 15:27:52120def 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
Ryan Dahl14b04b02011-11-15 03:02:44128def 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
142def uname(switch):
143 f = os.popen('uname %s' % switch)
144 s = f.read().strip()
145 f.close()
146 return s
147
148
149def 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
164def target_arch():
Ryan Dahl14b04b02011-11-15 03:02:44165 return host_arch()
166
167
168def configure_node(o):
Ben Noordhuis93465d32012-01-15 15:50:58169 # TODO add gdb
Ben Noordhuisb3d49382011-11-29 15:41:41170 o['variables']['node_use_isolates'] = b(not options.without_isolates)
Ben Noordhuisa0332612011-11-29 15:27:52171 o['variables']['node_debug'] = b(options.debug)
Ryan Dahl14b04b02011-11-15 03:02:44172 o['variables']['node_prefix'] = options.prefix if options.prefix else ''
Ben Noordhuisa0332612011-11-29 15:27:52173 o['variables']['node_use_dtrace'] = b(options.with_dtrace)
Fedor Indutnya9f2c4a2011-12-17 08:09:14174 o['variables']['node_install_npm'] = b(not options.without_npm)
Ryan Dahl14b04b02011-11-15 03:02:44175 o['variables']['host_arch'] = host_arch()
Ben Noordhuis93465d32012-01-15 15:50:58176 o['variables']['target_arch'] = options.dest_cpu or target_arch()
Ryan Dahl14b04b02011-11-15 03:02:44177
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
183def configure_libz(o):
184 o['libraries'] += ['-lz']
185
186
187def configure_v8(o):
Ben Noordhuisa0332612011-11-29 15:27:52188 o['variables']['v8_use_snapshot'] = b(not options.without_snapshot)
189 o['variables']['node_shared_v8'] = b(options.shared_v8)
Ryan Dahl14b04b02011-11-15 03:02:44190
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
200def configure_cares(o):
Ben Noordhuisa0332612011-11-29 15:27:52201 o['variables']['node_shared_cares'] = b(options.shared_cares)
Ryan Dahl14b04b02011-11-15 03:02:44202
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
210def configure_openssl(o):
Ben Noordhuisa0332612011-11-29 15:27:52211 o['variables']['node_use_openssl'] = b(not options.without_ssl)
Ryan Dahl14b04b02011-11-15 03:02:44212
213 if options.without_ssl:
214 return
215
216 if options.no_ssl2:
217 o['defines'] += ['OPENSSL_NO_SSL2=1']
218
Ryan Dahle61de702011-12-16 23:00:23219 if not options.openssl_use_sys:
220 o['variables']['node_use_system_openssl'] = b(False)
Ryan Dahl14b04b02011-11-15 03:02:44221 else:
Ryan Dahle61de702011-12-16 23:00:23222 out = pkg_config('openssl')
223 (libs, cflags) = out if out else ('', '')
Ryan Dahl14b04b02011-11-15 03:02:44224
Ryan Dahle61de702011-12-16 23:00:23225 if options.openssl_libpath:
226 o['libraries'] += ['-L%s' % options.openssl_libpath, '-lssl', '-lcrypto']
227 else:
228 o['libraries'] += libs.split()
Ryan Dahl14b04b02011-11-15 03:02:44229
Ryan Dahle61de702011-12-16 23:00:23230 if options.openssl_includes:
231 o['include_dirs'] += [options.openssl_includes]
232 else:
233 o['cflags'] += cflags.split()
234
235 o['variables']['node_use_system_openssl'] = b(
236 libs or cflags or options.openssl_libpath or options.openssl_includes)
Ryan Dahl14b04b02011-11-15 03:02:44237
238
Ryan Dahl14b04b02011-11-15 03:02:44239output = {
240 'variables': {},
241 'include_dirs': [],
242 'libraries': [],
243 'defines': [],
244 'cflags': [],
245}
246
247configure_node(output)
248configure_libz(output)
249configure_v8(output)
250configure_cares(output)
251configure_openssl(output)
252
253# variables should be a root level element,
254# move everything else to target_defaults
255variables = output['variables']
256del output['variables']
257output = {
258 'variables': variables,
259 'target_defaults': output
260}
Ryan Dahl624f70e2011-12-23 22:24:50261pprint.pprint(output, indent=2)
Ryan Dahl14b04b02011-11-15 03:02:44262
Ryan Dahl624f70e2011-12-23 22:24:50263fn = os.path.join(root_dir, 'config.gypi')
Ryan Dahl14b04b02011-11-15 03:02:44264print "creating ", fn
265
266f = open(fn, 'w+')
267f.write("# Do not edit. Generated by the configure script.\n")
jbergstroem45605c92011-12-18 22:53:07268pprint.pprint(output, stream=f, indent=2)
Ryan Dahl14b04b02011-11-15 03:02:44269f.write("\n")
270f.close()
271
Ryan Dahl48d21dd2011-11-18 01:18:29272subprocess.call(['tools/gyp_node','-f', 'make'])