forked from luvit/luvit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·204 lines (161 loc) · 4.95 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env python
"""
From <https://github.com/joyent/node/blob/master/configure-gyp>
"""
import optparse
import os
import json
import sys
import glob
import shutil
root_dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(root_dir, 'tools', 'gyp', 'pylib'))
import gyp
# parse our options
parser = optparse.OptionParser()
parser.add_option("--debug",
action="store_true",
dest="debug",
help="Build debug build")
parser.add_option("--prefix",
action="store",
dest="prefix",
default="/usr/local",
help="Select the install prefix (defaults to /usr/local)")
parser.add_option("--arch",
action="store",
dest="arch",
help="Select the default architecture (ia32,x64,arm)")
parser.add_option("--without-ssl",
action="store_true",
dest="without_ssl",
help="Disable SSL Support")
parser.add_option("--without-fat",
action="store_true",
dest="skinny",
help="Compile in Skinny mode, removing less commonly used features, but reducing footprint.")
(options, args) = parser.parse_args()
def pkg_config(pkg):
cmd = os.popen('pkg-config --libs %s' % pkg, 'r')
libs = cmd.readline().strip()
ret = cmd.close()
if (ret): return None
cmd = os.popen('pkg-config --cflags %s' % pkg, 'r')
cflags = cmd.readline().strip()
ret = cmd.close()
if (ret): return None
return (libs, cflags)
def uname(switch):
f = os.popen('uname %s' % switch)
s = f.read().strip()
f.close()
return s
def host_arch_win():
"""Host architecture check using environ vars (better way to do this?)"""
arch = os.environ.get('PROCESSOR_ARCHITECTURE', 'x86')
matchup = {
'AMD64' : 'x64',
'x86' : 'ia32',
'arm' : 'arm',
'mips' : 'mips',
}
return matchup.get(arch, 'ia32')
def host_arch():
"""Host architecture. One of arm, ia32 or x64."""
if sys.platform == "win32":
return host_arch_win()
if sys.platform == "darwin":
return 'x64'
arch = uname('-p')
if arch == 'unknown':
arch = uname('-m')
if arch.startswith('arm'):
# handle arm, armv3l, armv6l, etc.
return 'arm'
return {
'x86': 'ia32',
'i386': 'ia32',
'i486': 'ia32',
'i586': 'ia32',
'i686': 'ia32',
'x86_64': 'x64',
'amd64': 'x64',
}.get(arch, arch)
def target_arch():
# TODO act on options.dest_cpu
return host_arch()
def configure_luvit(o):
# TODO add gdb and dest_cpu
o['variables']['luvit_debug'] = 'true' if options.debug else 'false'
o['variables']['luvit_prefix'] = options.prefix if options.prefix else ''
o['variables']['host_arch'] = host_arch()
o['variables']['target_arch'] = options.arch if options.arch else target_arch()
o['variables']['without_ssl'] = 'true' if options.without_ssl else 'false'
o['variables']['luvit_skinny'] = 'true' if options.skinny else 'false'
t_os = gyp.common.GetFlavor({})
t_arch = o['variables']['target_arch']
possible_dirs = ['deps/openssl/openssl-configs/%s-%s' % (t_os, t_arch),
'deps/openssl/openssl-configs/%s' % t_arch,
'deps/openssl/openssl-configs/%s' % t_os]
for d in possible_dirs:
if os.path.exists(d):
return
print ""
print "Error: Unsupported target architecture: %s-%s" % (t_os, t_arch)
print ""
print "Could not find configuration for openssl in one of: \n %s" % ('\n '.join(possible_dirs))
sys.exit(1)
print "configure options:", options
output = {
'variables': {},
'include_dirs': [],
'libraries': [],
'defines': [],
'cflags': [],
}
configure_luvit(output)
# variables should be a root level element,
# move everything else to target_defaults
variables = output['variables']
del output['variables']
output = {
'variables': variables,
'target_defaults': output
}
fn = os.path.join(root_dir, 'options.gypi')
print "creating ", fn
f = open(fn, 'w+')
f.write("# Do not edit. Generated by the configure script.\n")
json.dump(output, f, indent=2, skipkeys=True)
f.write("\n")
f.close()
print "Generating build system with GYP..."
def render_openssl_symlinks(src, dest):
src = os.path.abspath(src)
dest = os.path.abspath(dest)
for x in glob.glob(os.path.join(src, '*.h')):
with open(x) as f:
d = f.read().strip()
srcf = os.path.abspath(os.path.join(src, d))
destf = os.path.join(dest, os.path.basename(srcf))
# use copy2, so we preserve mtimes, reducing rebuilds
shutil.copy2(srcf, destf)
if sys.platform == "win32":
render_openssl_symlinks('deps/openssl/openssl/include/openssl',
'deps/openssl/openssl-configs/realized/openssl')
code = os.system("python tools\gyp_luvit -f msvs -G msvs_version=auto")
else:
code = os.system("tools/gyp_luvit")
if code == 0:
print ""
print "Done!"
print ""
if sys.platform == "win32":
print "Now run `python build.py` to build!"
else:
print "Now run `make -C out` to build!"
print ""
else:
print ""
print "Error occured. Please investigate details above."
print ""