forked from coordcn/luaio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·187 lines (143 loc) · 4.23 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
#!/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 subprocess
root_dir = os.path.dirname(os.path.abspath(__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="",
help="Select the install prefix (defaults to "")")
parser.add_option("--arch",
action="store",
dest="arch",
help="Select the default architecture (ia32,x64,arm)")
parser.add_option("--openssl-no-asm",
action="store_true",
dest="openssl_no_asm",
help="Do not build optimized assembly for OpenSSL")
parser.add_option('--openssl-fips',
action='store',
dest='openssl_fips',
help='Build OpenSSL using FIPS canister .o file in supplied folder')
parser.add_option('--ninja',
action='store_true',
dest='use_ninja',
help='generate files for the ninja build system')
parser.add_option('--xcode',
action='store_true',
dest='use_xcode',
help='generate build files for use with xcode')
(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 'ia32'
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_luaio(o):
# TODO add gdb and dest_cpu
o['variables']['node_byteorder'] = sys.byteorder
o['variables']['luaio_debug'] = 'true' if options.debug else 'false'
o['variables']['luaio_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()
def configure_libuv(o):
o['variables']['uv_library'] = 'static_library'
def configure_openssl(o):
o['variables']['openssl_no_asm'] = 1 if options.openssl_no_asm else 0
if options.openssl_fips:
o['variables']['openssl_fips'] = options.openssl_fips
fips_dir = os.path.join(root_dir, 'deps', 'openssl', 'fips')
fips_ld = os.path.abspath(os.path.join(fips_dir, 'fipsld'))
o['make_fips_settings'] = [
['LINK', fips_ld + ' <(openssl_fips)/bin/fipsld'],
]
else:
o['variables']['openssl_fips'] = ''
#print "configure options:", options
output = {
'variables': {},
'include_dirs': [],
'libraries': [],
'defines': [],
'cflags': [],
}
configure_luaio(output)
configure_libuv(output)
configure_openssl(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..."
gyp_args = [sys.executable, 'luaio.py', '--no-parallel']
sys.exit(subprocess.call(gyp_args))