-
Notifications
You must be signed in to change notification settings - Fork 2
/
SConstruct
183 lines (151 loc) · 4.08 KB
/
SConstruct
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
import os
import sys
import glob
import re
def shelloutput(cmd):
pipe = os.popen(cmd, 'r')
ret = pipe.read()
pipe.close()
return ret.strip()
def gccversion():
ver = re.search('\d*\.\d*\.\d*', shelloutput('gcc --version')).group(0)
return map(int, ver.split('.'))
def arch():
if os.name == 'nt':
arch = 'i386'
else:
arch = shelloutput('uname -m')
if arch == 'ppc':
arch = 'powerpc'
if arch == 'amd64':
arch = 'x64'
if arch == 'x86_64':
arch = 'x64'
if arch == 'i686':
arch = 'i386'
if arch == 'sgimips':
arch = 'mips'
if ARGUMENTS.get('arch', 0):
arch = ARGUMENTS.get('arch')
return arch
def normalized_os():
ret = sys.platform
if ret[0:6] == 'netbsd':
ret = 'netbsd'
if ret[0:7] == 'freebsd':
ret = 'freebsd'
if ret[0:5] == 'linux':
ret = 'linux'
if ret[0:9] == 'dragonfly':
ret = 'dragonfly'
return ret
tarch = arch()
tools = []
if os.name == 'nt':
tools = ['mingw']
env = Environment(ARCH=tarch, TOOLS=['mingw'], OS=normalized_os())
ring0 = ARGUMENTS.get('ring0', False)
if ring0:
env.Tool('crossmingw', '.')
env['LINK'] = env['CC']
env['OS'] = 'win32'
#env['ENV']['PATH'] = os.environ['PATH']
env.Append(CCFLAGS='-O2 -g')
env.Append(LINKFLAGS='-g')
if tarch == 'x64':
env.Append(CPPDEFINES=['X86_64'])
else:
if tarch == 'i386' and env['OS'] == 'darwin' and not ring0:
env.Append(ASFLAGS='-arch i386')
if tarch == 'i386' and env['OS'] != 'darwin':
env.Replace(AS='as --32')
env.Append(CPPFLAGS='-m32')
env.Append(LINKFLAGS='-m32')
gccmajor, gccminor, gccrev = gccversion()
if gccmajor < 3:
env.Append(CPPDEFINES=[['__LONG_LONG_MAX__', '9223372036854775807']])
else:
env.Append(CCFLAGS='-fno-reorder-blocks')
def slurp(f):
f = open(str(f))
res = f.read()
f.close()
return res
def barf(f, contents):
f = open(str(f), 'w')
f.write(contents)
f.close
def gentab(env, target, source):
res = ''
prims = slurp(source[0]).split('PRIM(')[1:]
for prim in prims:
res += '&&' + prim.split(')')[0] + ',\n'
barf(target[0], res)
def cat(env, target, source):
res = ''
for src in source:
res += slurp(src)
barf(target[0], res)
cat = Builder(action=cat)
tab = Builder(action=gentab, source_scanner = CScan)
asm = Builder(action=
'$CC $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -S -o $TARGET $SOURCE',
source_scanner = CScan)
hlp = Builder(action=
'obj/fina help/glosgen.fs -e "newglos makeglos $SOURCE writeglos $TARGET bye"')
env.Append(BUILDERS = {
'Tab' : tab,
'Asm' : asm,
'Hlp' : hlp,
'Cat' : cat,
})
def myglob(self, pat):
curr = os.getcwd()
os.chdir(str(Dir('#')))
ret = glob.glob(pat)
os.chdir(curr)
return ret
def basename(self, path):
return os.path.basename(path)
def outputfrom(self, cmd):
return shelloutput(cmd)
def CppAsm(self, target, source):
cpp = self.Command(target + '.s', source,
'$CC $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -E -o $TARGET $SOURCE')
return self.Object(target, cpp)
prefix = ARGUMENTS.get('prefix', '#./inst')
if prefix[-1] != '/':
prefix += '/'
def Ins(self, where, what):
return self.Default(self.Install(prefix + where, what))
def Run(self, files):
env.Default(env.Command('dummyrun', files,
str(Dir(prefix)) + '/bin/fina $SOURCES'))
def TimedRun(self, file):
env.Default(env.Command('dummy' + file, file,
'time ' + str(Dir(prefix)) \
+ '/bin/fina $SOURCE -e "main bye"'))
Environment.Glob = classmethod(myglob)
Environment.Basename = classmethod(basename)
Environment.OutputFrom = classmethod(outputfrom)
env.AddMethod(CppAsm)
env.AddMethod(Ins)
env.AddMethod(Run)
env.AddMethod(TimedRun)
env.SConscript('SConscript.ffi',
variant_dir = 'obj',
exports=['env'],
duplicate = 0)
sc = 'SConscript'
if ring0:
sc += '.ring0'
env['files'] = ARGUMENTS.get('files', 1)
env['allocate'] = ARGUMENTS.get('allocate', 1)
env['fixed'] = ARGUMENTS.get('fixed', 1)
env['ffi'] = ARGUMENTS.get('ffi', 1)
env['moreprims'] = ARGUMENTS.get('moreprims', 1)
env['profile'] = ARGUMENTS.get('profile', 0)
env.SConscript(sc,
variant_dir = 'obj',
exports=['env'],
duplicate = 0)