blob: 0ec745c939037a4302d932db86355ca9c4d8ed29 [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
5import json
6import sys
Ryan Dahl5cf4cef2010-10-26 01:17:197
Ryan Dahl14b04b02011-11-15 03:02:448root_dir = os.path.dirname(__file__)
9sys.path.insert(0, os.path.join(root_dir, 'deps', 'v8', 'tools'))
10import utils # GuessArchitecture
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
25parser.add_option("--without-ssl",
26 action="store_true",
27 dest="without_ssl",
28 help="Build without SSL")
29
30parser.add_option("--without-snapshot",
31 action="store_true",
32 dest="without_snapshot",
33 help="Build without snapshotting V8 libraries. You might want to set"
34 " this for cross-compiling. [Default: False]")
35
36parser.add_option("--shared-v8",
37 action="store_true",
38 dest="shared_v8",
39 help="Link to a shared V8 DLL instead of static linking")
40
41parser.add_option("--shared-v8-includes",
42 action="store",
43 dest="shared_v8_includes",
44 help="Directory containing V8 header files")
45
46parser.add_option("--shared-v8-libpath",
47 action="store",
48 dest="shared_v8_libpath",
49 help="A directory to search for the shared V8 DLL")
50
51parser.add_option("--shared-v8-libname",
52 action="store",
53 dest="shared_v8_libname",
54 help="Alternative lib name to link to (default: 'v8')")
55
56parser.add_option("--openssl-includes",
57 action="store",
58 dest="openssl_includes",
59 help="A directory to search for the OpenSSL includes")
60
61parser.add_option("--openssl-libpath",
62 action="store",
63 dest="openssl_libpath",
64 help="A directory to search for the OpenSSL libraries")
65
66parser.add_option("--no-ssl2",
67 action="store_true",
68 dest="no_ssl2",
69 help="Disable OpenSSL v2")
70
71parser.add_option("--shared-cares",
72 action="store_true",
73 dest="shared_cares",
74 help="Link to a shared C-Ares DLL instead of static linking")
75
76parser.add_option("--shared-cares-includes",
77 action="store",
78 dest="shared_cares_includes",
79 help="Directory containing C-Ares header files")
80
81parser.add_option("--shared-cares-libpath",
82 action="store",
83 dest="shared_cares_libpath",
84 help="A directory to search for the shared C-Ares DLL")
85
86parser.add_option("--with-dtrace",
87 action="store_true",
88 dest="with_dtrace",
89 help="Build with DTrace (experimental)")
90
91# CHECKME does this still work with recent releases of V8?
92parser.add_option("--gdb",
93 action="store_true",
94 dest="gdb",
95 help="add gdb support")
96
97parser.add_option("--dest-cpu",
98 action="store",
99 dest="dest_cpu",
100 help="CPU architecture to build for. Valid values are: arm, ia32, x64")
101
102(options, args) = parser.parse_args()
103
104
105def pkg_config(pkg):
106 cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
107 libs = cmd.readline().strip()
108 ret = cmd.close()
109 if (ret): return None
110
111 cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
112 cflags = cmd.readline().strip()
113 ret = cmd.close()
114 if (ret): return None
115
116 return (libs, cflags)
117
118
119def uname(switch):
120 f = os.popen('uname %s' % switch)
121 s = f.read().strip()
122 f.close()
123 return s
124
125
126def host_arch():
127 """Host architecture. One of arm, ia32 or x64."""
128 arch = uname('-p')
129
130 if arch == 'unknown':
131 arch = uname('-m')
132
133 return {
134 'arm': 'arm',
135 'x86': 'ia32',
136 'i386': 'ia32',
137 'x86_64': 'x64',
138 }.get(arch, 'ia32')
139
140
141def target_arch():
142 # TODO act on options.dest_cpu
143 return host_arch()
144
145
146def configure_node(o):
147 # TODO add gdb and dest_cpu
148 o['variables']['node_debug'] = 'true' if options.debug else 'false'
149 o['variables']['node_prefix'] = options.prefix if options.prefix else ''
150 o['variables']['node_use_dtrace'] = 'true' if options.with_dtrace else 'false'
151 o['variables']['host_arch'] = host_arch()
152 o['variables']['target_arch'] = target_arch()
153
154 # TODO move to node.gyp
155 if sys.platform == 'sunos5':
156 o['variables']['visibility'] = '' # FIXME -fvisibility=hidden, should be a gcc check
157
158
159def configure_libz(o):
160 o['libraries'] += ['-lz']
161
162
163def configure_v8(o):
164 o['variables']['v8_use_snapshot'] = 'true' if not options.without_snapshot else 'false'
165 o['variables']['node_shared_v8'] = 'true' if options.shared_v8 else 'false'
166
167 # assume shared_v8 if one of these is set?
168 if options.shared_v8_libpath:
169 o['libraries'] += ['-L%s' % options.shared_v8_libpath]
170 if options.shared_v8_libname:
171 o['libraries'] += ['-l%s' % options.shared_v8_libname]
172 if options.shared_v8_includes:
173 o['include_dirs'] += [options.shared_v8_includes]
174
175
176def configure_cares(o):
177 o['variables']['node_shared_cares'] = 'true' if options.shared_cares else 'false'
178
179 # assume shared_cares if one of these is set?
180 if options.shared_cares_libpath:
181 o['libraries'] += ['-L%s' % options.shared_cares_libpath]
182 if options.shared_cares_includes:
183 o['include_dirs'] += [options.shared_cares_includes]
184
185
186def configure_openssl(o):
187 o['variables']['node_use_openssl'] = 'false' if options.without_ssl else 'true'
188
189 if options.without_ssl:
190 return
191
192 if options.no_ssl2:
193 o['defines'] += ['OPENSSL_NO_SSL2=1']
194
195 out = pkg_config('openssl')
196 (libs, cflags) = out if out else ('', '')
197
198 if options.openssl_libpath:
199 o['libraries'] += ['-L%s' % options.openssl_libpath, '-lssl', '-lcrypto']
200 else:
201 o['libraries'] += libs.split()
202
203 if options.openssl_includes:
204 o['include_dirs'] += [options.openssl_includes]
205 else:
206 o['cflags'] += cflags.split()
207
208 if libs or cflags or options.openssl_libpath or options.openssl_includes:
209 o['variables']['node_use_system_openssl'] = 'true'
210 else:
211 o['variables']['node_use_system_openssl'] = 'false'
212
213
214print "configure options:", options
215
216output = {
217 'variables': {},
218 'include_dirs': [],
219 'libraries': [],
220 'defines': [],
221 'cflags': [],
222}
223
224configure_node(output)
225configure_libz(output)
226configure_v8(output)
227configure_cares(output)
228configure_openssl(output)
229
230# variables should be a root level element,
231# move everything else to target_defaults
232variables = output['variables']
233del output['variables']
234output = {
235 'variables': variables,
236 'target_defaults': output
237}
238
239fn = os.path.join(root_dir, 'options.gypi')
240print "creating ", fn
241
242f = open(fn, 'w+')
243f.write("# Do not edit. Generated by the configure script.\n")
244json.dump(output, f, indent=2, skipkeys=True)
245f.write("\n")
246f.close()
247