blob: dbe7f243e1678a84fdc8b9dd90c3b06a63bbbf4c [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
Ryan Dahl14b04b02011-11-15 03:02:4430parser.add_option("--without-ssl",
31 action="store_true",
32 dest="without_ssl",
33 help="Build without SSL")
34
35parser.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
41parser.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
46parser.add_option("--shared-v8-includes",
47 action="store",
48 dest="shared_v8_includes",
49 help="Directory containing V8 header files")
50
51parser.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
56parser.add_option("--shared-v8-libname",
57 action="store",
58 dest="shared_v8_libname",
59 help="Alternative lib name to link to (default: 'v8')")
60
Ryan Dahle61de702011-12-16 23:00:2361parser.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
Ryan Dahl14b04b02011-11-15 03:02:4466parser.add_option("--openssl-includes",
67 action="store",
68 dest="openssl_includes",
69 help="A directory to search for the OpenSSL includes")
70
71parser.add_option("--openssl-libpath",
72 action="store",
73 dest="openssl_libpath",
74 help="A directory to search for the OpenSSL libraries")
75
76parser.add_option("--no-ssl2",
77 action="store_true",
78 dest="no_ssl2",
79 help="Disable OpenSSL v2")
80
81parser.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
86parser.add_option("--shared-cares-includes",
87 action="store",
88 dest="shared_cares_includes",
89 help="Directory containing C-Ares header files")
90
91parser.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
96parser.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?
102parser.add_option("--gdb",
103 action="store_true",
104 dest="gdb",
105 help="add gdb support")
106
107parser.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
Ben Noordhuisa0332612011-11-29 15:27:52115def 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
Ryan Dahl14b04b02011-11-15 03:02:44123def 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
137def uname(switch):
138 f = os.popen('uname %s' % switch)
139 s = f.read().strip()
140 f.close()
141 return s
142
143
144def 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
159def target_arch():
160 # TODO act on options.dest_cpu
161 return host_arch()
162
163
164def configure_node(o):
165 # TODO add gdb and dest_cpu
Ben Noordhuisa0332612011-11-29 15:27:52166 o['variables']['node_debug'] = b(options.debug)
Ryan Dahl14b04b02011-11-15 03:02:44167 o['variables']['node_prefix'] = options.prefix if options.prefix else ''
Ben Noordhuisa0332612011-11-29 15:27:52168 o['variables']['node_use_dtrace'] = b(options.with_dtrace)
Fedor Indutnya9f2c4a2011-12-17 08:09:14169 o['variables']['node_install_npm'] = b(not options.without_npm)
Ryan Dahl14b04b02011-11-15 03:02:44170 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
178def configure_libz(o):
179 o['libraries'] += ['-lz']
180
181
182def configure_v8(o):
Ben Noordhuisa0332612011-11-29 15:27:52183 o['variables']['v8_use_snapshot'] = b(not options.without_snapshot)
184 o['variables']['node_shared_v8'] = b(options.shared_v8)
Ryan Dahl14b04b02011-11-15 03:02:44185
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
195def configure_cares(o):
Ben Noordhuisa0332612011-11-29 15:27:52196 o['variables']['node_shared_cares'] = b(options.shared_cares)
Ryan Dahl14b04b02011-11-15 03:02:44197
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
205def configure_openssl(o):
Ben Noordhuisa0332612011-11-29 15:27:52206 o['variables']['node_use_openssl'] = b(not options.without_ssl)
Ryan Dahl14b04b02011-11-15 03:02:44207
208 if options.without_ssl:
209 return
210
211 if options.no_ssl2:
212 o['defines'] += ['OPENSSL_NO_SSL2=1']
213
Ryan Dahle61de702011-12-16 23:00:23214 if not options.openssl_use_sys:
215 o['variables']['node_use_system_openssl'] = b(False)
Ryan Dahl14b04b02011-11-15 03:02:44216 else:
Ryan Dahle61de702011-12-16 23:00:23217 out = pkg_config('openssl')
218 (libs, cflags) = out if out else ('', '')
Ryan Dahl14b04b02011-11-15 03:02:44219
Ryan Dahle61de702011-12-16 23:00:23220 if options.openssl_libpath:
221 o['libraries'] += ['-L%s' % options.openssl_libpath, '-lssl', '-lcrypto']
222 else:
223 o['libraries'] += libs.split()
Ryan Dahl14b04b02011-11-15 03:02:44224
Ryan Dahle61de702011-12-16 23:00:23225 if options.openssl_includes:
226 o['include_dirs'] += [options.openssl_includes]
227 else:
228 o['cflags'] += cflags.split()
229
230 o['variables']['node_use_system_openssl'] = b(
231 libs or cflags or options.openssl_libpath or options.openssl_includes)
Ryan Dahl14b04b02011-11-15 03:02:44232
233
Ryan Dahl14b04b02011-11-15 03:02:44234output = {
235 'variables': {},
236 'include_dirs': [],
237 'libraries': [],
238 'defines': [],
239 'cflags': [],
240}
241
242configure_node(output)
243configure_libz(output)
244configure_v8(output)
245configure_cares(output)
246configure_openssl(output)
247
248# variables should be a root level element,
249# move everything else to target_defaults
250variables = output['variables']
251del output['variables']
252output = {
253 'variables': variables,
254 'target_defaults': output
255}
Ryan Dahl624f70e2011-12-23 22:24:50256pprint.pprint(output, indent=2)
Ryan Dahl14b04b02011-11-15 03:02:44257
Ryan Dahl624f70e2011-12-23 22:24:50258fn = os.path.join(root_dir, 'config.gypi')
Ryan Dahl14b04b02011-11-15 03:02:44259print "creating ", fn
260
261f = open(fn, 'w+')
262f.write("# Do not edit. Generated by the configure script.\n")
jbergstroem45605c92011-12-18 22:53:07263pprint.pprint(output, stream=f, indent=2)
Ryan Dahl14b04b02011-11-15 03:02:44264f.write("\n")
265f.close()
266
Ryan Dahl48d21dd2011-11-18 01:18:29267subprocess.call(['tools/gyp_node','-f', 'make'])