Skip to content
This repository
Newer
Older
100755 275 lines (210 sloc) 7.207 kb
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
1 #!/usr/bin/env python
5cf4ceff » ry
2010-10-25 add configure
2
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
3 import optparse
4 import os
45605c9b » jbergstroem
2011-12-18 gyp: switch json for pprint when generating config
5 import pprint
b9e1bb3d » bnoordhuis
2011-11-15 build: auto-run tools/gyp_node after ./configure
6 import subprocess
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
7 import sys
5cf4ceff » ry
2010-10-25 add configure
8
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
9 root_dir = os.path.dirname(__file__)
10 sys.path.insert(0, os.path.join(root_dir, 'deps', 'v8', 'tools'))
97c97450 » ry
2010-11-01 Back to WAF
11
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
12 # parse our options
13 parser = optparse.OptionParser()
97c97450 » ry
2010-11-01 Back to WAF
14
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
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
a9f2c4aa » indutny
2011-12-17 --without-npm option
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
6e76a7cb » indutny
2012-01-17 installer: install node-waf
30 parser.add_option("--without-waf",
31 action="store_true",
32 dest="without_waf",
33 help="Don\'t install node-waf")
34
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
35 parser.add_option("--without-ssl",
36 action="store_true",
37 dest="without_ssl",
38 help="Build without SSL")
39
40 parser.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
46 parser.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
51 parser.add_option("--shared-v8-includes",
52 action="store",
53 dest="shared_v8_includes",
54 help="Directory containing V8 header files")
55
56 parser.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
61 parser.add_option("--shared-v8-libname",
62 action="store",
63 dest="shared_v8_libname",
64 help="Alternative lib name to link to (default: 'v8')")
65
e61de70c » ry
2011-12-16 gyp: use built-in openssl by default
66 parser.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
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
71 parser.add_option("--openssl-includes",
72 action="store",
73 dest="openssl_includes",
74 help="A directory to search for the OpenSSL includes")
75
76 parser.add_option("--openssl-libpath",
77 action="store",
78 dest="openssl_libpath",
79 help="A directory to search for the OpenSSL libraries")
80
81 parser.add_option("--no-ssl2",
82 action="store_true",
83 dest="no_ssl2",
84 help="Disable OpenSSL v2")
85
86 parser.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
91 parser.add_option("--shared-cares-includes",
92 action="store",
93 dest="shared_cares_includes",
94 help="Directory containing C-Ares header files")
95
96 parser.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
101 parser.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?
107 parser.add_option("--gdb",
108 action="store_true",
109 dest="gdb",
110 help="add gdb support")
111
112 parser.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
a033261f » bnoordhuis
2011-11-29 build: DRY configure script
120 def 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
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
128 def 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
142 def uname(switch):
143 f = os.popen('uname %s' % switch)
144 s = f.read().strip()
145 f.close()
146 return s
147
148
149 def host_arch():
150 """Host architecture. One of arm, ia32 or x64."""
09ccbef3 » Skomski
2012-02-13 build: detect host_arch better
151 arch = uname('-p')
152 arches = {
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
153 'arm': 'arm',
154 'x86': 'ia32',
155 'i386': 'ia32',
156 'x86_64': 'x64',
09ccbef3 » Skomski
2012-02-13 build: detect host_arch better
157 }
158
159 if arches.get(arch) == None:
160 arch = uname('-m')
161
162 return arches.get(arch, 'ia32')
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
163
164
165 def target_arch():
166 return host_arch()
167
168
169 def configure_node(o):
93465d30 » bnoordhuis
2012-01-15 build: support --dest-cpu configure switch again
170 # TODO add gdb
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
171 o['variables']['node_prefix'] = options.prefix if options.prefix else ''
a033261f » bnoordhuis
2011-11-29 build: DRY configure script
172 o['variables']['node_use_dtrace'] = b(options.with_dtrace)
a9f2c4aa » indutny
2011-12-17 --without-npm option
173 o['variables']['node_install_npm'] = b(not options.without_npm)
6e76a7cb » indutny
2012-01-17 installer: install node-waf
174 o['variables']['node_install_waf'] = b(not options.without_waf)
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
175 o['variables']['host_arch'] = host_arch()
93465d30 » bnoordhuis
2012-01-15 build: support --dest-cpu configure switch again
176 o['variables']['target_arch'] = options.dest_cpu or target_arch()
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
177
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
183 def configure_libz(o):
184 o['libraries'] += ['-lz']
185
186
187 def configure_v8(o):
a033261f » bnoordhuis
2011-11-29 build: DRY configure script
188 o['variables']['v8_use_snapshot'] = b(not options.without_snapshot)
189 o['variables']['node_shared_v8'] = b(options.shared_v8)
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
190
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
200 def configure_cares(o):
a033261f » bnoordhuis
2011-11-29 build: DRY configure script
201 o['variables']['node_shared_cares'] = b(options.shared_cares)
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
202
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
210 def configure_openssl(o):
a033261f » bnoordhuis
2011-11-29 build: DRY configure script
211 o['variables']['node_use_openssl'] = b(not options.without_ssl)
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
212
213 if options.without_ssl:
214 return
215
216 if options.no_ssl2:
217 o['defines'] += ['OPENSSL_NO_SSL2=1']
218
e61de70c » ry
2011-12-16 gyp: use built-in openssl by default
219 if not options.openssl_use_sys:
220 o['variables']['node_use_system_openssl'] = b(False)
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
221 else:
e61de70c » ry
2011-12-16 gyp: use built-in openssl by default
222 out = pkg_config('openssl')
223 (libs, cflags) = out if out else ('', '')
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
224
e61de70c » ry
2011-12-16 gyp: use built-in openssl by default
225 if options.openssl_libpath:
226 o['libraries'] += ['-L%s' % options.openssl_libpath, '-lssl', '-lcrypto']
227 else:
228 o['libraries'] += libs.split()
229
230 if options.openssl_includes:
231 o['include_dirs'] += [options.openssl_includes]
232 else:
233 o['cflags'] += cflags.split()
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
234
e61de70c » ry
2011-12-16 gyp: use built-in openssl by default
235 o['variables']['node_use_system_openssl'] = b(
236 libs or cflags or options.openssl_libpath or options.openssl_includes)
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
237
238
239 output = {
240 'variables': {},
241 'include_dirs': [],
242 'libraries': [],
243 'defines': [],
244 'cflags': [],
245 }
246
247 configure_node(output)
248 configure_libz(output)
249 configure_v8(output)
250 configure_cares(output)
251 configure_openssl(output)
252
253 # variables should be a root level element,
254 # move everything else to target_defaults
255 variables = output['variables']
256 del output['variables']
257 output = {
258 'variables': variables,
259 'target_defaults': output
260 }
624f70e8 » ry
2011-12-23 GYP: rename options.gypi to config.gypi
261 pprint.pprint(output, indent=2)
14b04b06 » ry
2011-11-14 Remove SCONS deprecate WAF
262
e493b295 » bnoordhuis
2012-01-17 build: respect --debug configure switch
263 def write(filename, data):
264 filename = os.path.join(root_dir, filename)
265 print "creating ", filename
266 with open(filename, 'w+') as f:
267 f.write(data)
268
269 write('config.gypi', "# Do not edit. Generated by the configure script.\n" +
270 pprint.pformat(output, indent=2))
271
272 write('config.mk', "# Do not edit. Generated by the configure script.\n" +
273 ("BUILDTYPE=%s\n" % ('Debug' if options.debug else 'Release')))
97c97450 » ry
2010-11-01 Back to WAF
274
48d21dd5 » ry
2011-11-17 Force makefile generation in gyp
275 subprocess.call(['tools/gyp_node','-f', 'make'])
Something went wrong with that request. Please try again.