net: `Server.listen`, `Server.close` and `Socket.connect` return `this`
[platform/upstream/nodejs.git] / configure-gyp
1 #!/usr/bin/env python
2
3 import optparse
4 import os
5 import json
6 import sys
7
8 root_dir = os.path.dirname(__file__)
9 sys.path.insert(0, os.path.join(root_dir, 'deps', 'v8', 'tools'))
10 import utils # GuessArchitecture
11
12 # parse our options
13 parser = optparse.OptionParser()
14
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
25 parser.add_option("--without-ssl",
26     action="store_true",
27     dest="without_ssl",
28     help="Build without SSL")
29
30 parser.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
36 parser.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
41 parser.add_option("--shared-v8-includes",
42     action="store",
43     dest="shared_v8_includes",
44     help="Directory containing V8 header files")
45
46 parser.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
51 parser.add_option("--shared-v8-libname",
52     action="store",
53     dest="shared_v8_libname",
54     help="Alternative lib name to link to (default: 'v8')")
55
56 parser.add_option("--openssl-includes",
57     action="store",
58     dest="openssl_includes",
59     help="A directory to search for the OpenSSL includes")
60
61 parser.add_option("--openssl-libpath",
62     action="store",
63     dest="openssl_libpath",
64     help="A directory to search for the OpenSSL libraries")
65
66 parser.add_option("--no-ssl2",
67     action="store_true",
68     dest="no_ssl2",
69     help="Disable OpenSSL v2")
70
71 parser.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
76 parser.add_option("--shared-cares-includes",
77     action="store",
78     dest="shared_cares_includes",
79     help="Directory containing C-Ares header files")
80
81 parser.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
86 parser.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?
92 parser.add_option("--gdb",
93     action="store_true",
94     dest="gdb",
95     help="add gdb support")
96
97 parser.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
105 def 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
119 def uname(switch):
120   f = os.popen('uname %s' % switch)
121   s = f.read().strip()
122   f.close()
123   return s
124
125
126 def 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
141 def target_arch():
142   # TODO act on options.dest_cpu
143   return host_arch()
144
145
146 def 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
159 def configure_libz(o):
160   o['libraries'] += ['-lz']
161
162
163 def 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
176 def 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
186 def 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
214 print "configure options:", options
215
216 output = {
217   'variables': {},
218   'include_dirs': [],
219   'libraries': [],
220   'defines': [],
221   'cflags': [],
222 }
223
224 configure_node(output)
225 configure_libz(output)
226 configure_v8(output)
227 configure_cares(output)
228 configure_openssl(output)
229
230 # variables should be a root level element,
231 # move everything else to target_defaults
232 variables = output['variables']
233 del output['variables']
234 output = {
235   'variables': variables,
236   'target_defaults': output
237 }
238
239 fn = os.path.join(root_dir, 'options.gypi')
240 print "creating ", fn
241
242 f = open(fn, 'w+')
243 f.write("# Do not edit. Generated by the configure script.\n")
244 json.dump(output, f, indent=2, skipkeys=True)
245 f.write("\n")
246 f.close()
247