SConstruct
7.03 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import os
import platform
opts = Variables('DefaultOptions.py')
opts.Add(BoolVariable('DEBUG', 'Set to 1 to build with debug symbols', 0))
opts.Add(BoolVariable('STATIC', 'Set to 1 to build with static libraries', 0))
debug = ARGUMENTS.get('DEBUG', 0)
static = ARGUMENTS.get('STATIC', 0)
print "Platform: ", platform.system()
if platform.system() == 'Windows':
#os.environ['HOME'] = os.path.join(os.getcwd(), '..', '..') # for windows users
env = Environment(variables = opts, ENV = os.environ, tools = ['mingw'])
# print env['ENV']['PATH']
import SCons
SCons.Tool.Tool('lex').generate(env)
SCons.Tool.Tool('yacc').generate(env)
print env.WhereIs('bison')
else:
env = Environment(variables = opts, ENV = os.environ)
if debug:
env.Append(CPPDEFINES = {'DEBUG': None})
env.Append(CPPDEFINES = {'_DEBUG': None})
else:
env.Append(CPPDEFINES = {'NDEBUG': None})
compiler_output_name = 'anubis'
if platform.system() == 'Windows':
env.Append(CPPDEFINES = {'WIN32': None, '_WIN32_IE': '0x0400'})
# env.Append(CCFLAGS = ' /MD /GX /O2')
#env.Append(CPPDEFINES = {'__STDC__': None})
#env.Append(CPPDEFINES = {'_MSC_VER': '600'})
#additionalLibs.append('ws2_32.lib')
#additionalLibs.append('shell32.lib')
env.Append(LIBS=['ws2_32', 'shell32'])
# env.Append(LINKFLAGS = ' /subsystem:console /incremental:no /machine:I386 ')
else:
if platform.system() == 'Linux':
env.Append(CPPDEFINES = {'_LINUX_': None})
elif platform.system() == 'Darwin':
env.Append(CPPDEFINES = {'_LINUX_': None})
# for full path on log
#env['CXXCOM'] = '$CXX -o $TARGET -c $CXXFLAGS $CCFLAGS $_CCCOMCOM ${SOURCES.abspath}'
env['CXXCOM'] = env['CXXCOM'].replace('$SOURCES', '${SOURCES.abspath}')
env['CCCOM'] = env['CCCOM'].replace('$SOURCES', '${SOURCES.abspath}')
compiler_output_name = 'anubis_with_symbol'
env.Append(CCFLAGS = ' -c -Wall -m32')
env.Append(CFLAGS = ' -Wstrict-prototypes') #Flags only use for C compiler not C++
env.Append(LINKFLAGS = ' -m32')
if debug:
env.Append(CCFLAGS = ' -g3 -O0')
else:
env.Append(CCFLAGS = ' -O2')
if static:
env.Append(LINKFLAGS = '-static')
env['DEVDIR'] = os.path.normpath(os.path.join('..'))
env['BASEDIR'] = os.path.normpath(os.path.join(env['DEVDIR'], '..'))
env.Append(CPPPATH = [os.path.join(env['DEVDIR'], 'include'), '.'])
if platform.system() == 'Windows':
env.Append(CPPPATH = [os.path.join('src', 'win32')])
#SConscript('src/SConscript', exports='env', build_dir='build', duplicate=0)
env.VariantDir('build', 'src', duplicate=0)
env.VariantDir(os.path.join('build', 'win32'), os.path.join('src', 'win32'), duplicate=0)
env.VariantDir(os.path.join('build', 'share'), os.path.join(env['DEVDIR'], 'share'), duplicate=0)
env.VariantDir(os.path.join('build', 'cipher'), os.path.join(env['DEVDIR'], 'cipher'), duplicate=0)
main_src = [os.path.join('build', x) for x in Split("""
new_var.c interp.c globals.c mallocz.c opdef.c
unify.c show.c msgtexts.c typedef.c rectype.c typewidth.c implem.c
determin.c unknowns.c eqcode.c typecmp.c dumpct.c typetools.c destruct.cpp
compile.c delcode.c symcode.c vminstr.c rwcode.c index.c
checkexpr.c polish.c grammar_tools.c nat.cpp optimize.c
describe.c module_type.c
""")]
share_src = [os.path.join('build', 'share', x) for x in Split("""
FileIO.cpp
IniFile.cpp
String.cpp
DebugLog.cpp
MultiPath.cpp
StringList.cpp
List.cpp
""")]
special_src = [os.path.join('build', x) for x in Split("""
expr.cpp output.cpp main.cpp predef.c
""")]
cipher_src = [os.path.join('build', 'cipher', x) for x in Split("""
blowfish.c sha1.c
""")]
if platform.system() == 'Windows':
main_rc = [os.path.join('build', 'win32', x) for x in Split("""
compiler.rc
""")]
share_src.extend([os.path.join('build', 'share', x) for x in Split("""
win32stuff.cpp
""")])
else:
main_rc = []
share_src.extend([os.path.join('build', 'share', x) for x in Split("""
linuxstuff.cpp
""")])
#
# scanner
#
grammar = env.CFile('src/grammar.tab.c', 'src/grammar.y', YACCFLAGS = '-l -v -d')
env.Depends(grammar, 'src/compil.h')
lexer = env.CFile('src/lex.yy.c', 'src/lexer.l')
env.Depends(lexer, grammar)
env.Depends(lexer, 'src/compil.h')
#
# shared objects
#
specialDefs = env['CPPDEFINES'].copy()
specialDefs['__STDC__'] = None
gammar_obj = env.StaticObject([ grammar[0] ] + lexer, CPPDEFINES= specialDefs)
main_obj = env.Object(main_src) + gammar_obj
share_obj = env.Object(share_src)
cipher_obj = env.Object(cipher_src)
#
# The 'private' Anubis compiler (used only by the developers)
# It is used for compiling 'predefined.anubis'
#
myenv = env.Clone()
specialDefs = env['CPPDEFINES'].copy()
specialDefs['myanubis'] = None
special_obj = myenv.Object(special_src, CPPDEFINES = specialDefs, OBJPREFIX = 'my_')
myenv.Ignore(special_obj, 'src/predef_npd.aux')
myanubis = myenv.Program('myanubis', main_obj + share_obj + special_obj + cipher_obj)
#
# Making the anubis predefine
#
#def predefEmitter(target, source, env):
# return (['predef_npd.aux', 'predef.aux'],
# ['predef.anubis', os.path.join(env['DEVDIR'], 'library', 'predefined.anubis'), myanubis)
#predefBuilder = Builder(emitter = predefEmitter,
# action = 'build/myanubis -predef -Isrc')
#env.Append(BUILDERS = {'Predef' : predefBuilder})
predef = env.Command('src/predef_npd.aux', #['predef_npd.aux', 'predef.aux'],
['src/predef.anubis', os.path.join(env['DEVDIR'], 'library', 'predefined.anubis'), myanubis],
[Delete(os.path.join('src', 'predef.aux')),
Delete("$TARGET"),
'cd src && ' + os.path.join('..', 'myanubis -predef')])
#cd src
#myanubis -predef
#in: src/predef.anubis library/predefined.anubis
#out: predef.aux predef.
#
# The Anubis compiler without predef.dat nor ankh/djed
#
npdenv = env.Clone()
specialDefs = env['CPPDEFINES'].copy()
specialDefs['_no_predef_dat_'] = None
special_obj = npdenv.Object(special_src, CPPDEFINES = specialDefs, OBJPREFIX = 'npd_')
npdenv.Depends(special_obj, predef)
if platform.system() == 'Windows':
rsc = npdenv.RES(main_rc)
else:
rsc = []
anubis = npdenv.Program(compiler_output_name, main_obj + share_obj + special_obj + cipher_obj + rsc)
if platform.system() != 'Windows':
if not debug:
anubis = npdenv.Command('anubis', compiler_output_name, 'strip -o $TARGET $SOURCE')
else:
anubis = npdenv.Command('anubis', compiler_output_name, 'cp $SOURCE $TARGET')
if platform.system() != 'Windows':
installPath = os.path.join(env['BASEDIR'], 'anubis_distrib', 'linux_install', 'bin')
binDir = os.path.join(env['ENV']['HOME'], 'bin')
else:
installPath = os.path.join(env['BASEDIR'], 'anubis_distrib', 'win32_install', 'bin')
binDir = os.path.normpath(os.path.join(env['BASEDIR'], 'bin', 'anubis'))
env.Install(installPath, anubis)
env.Install(binDir, anubis)
env.Alias('install', [installPath, binDir])
env.Alias('all', [anubis, 'install'])
print 'BINDIR=', binDir
Default('all')
Help("""
Type: 'scons compiler' to build the production program,
'scons debug' to build the debug version.
"""
+ opts.GenerateHelpText(env))
print 'BUILD_TARGETS is', map(str, BUILD_TARGETS)