-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
237 lines (198 loc) · 8.99 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
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import os
opts = Variables( 'build/scons/SConfig', ARGUMENTS )
opts.AddVariables(
BoolVariable( 'debug', 'Debug build', 0 ),
BoolVariable( 'profile', 'Profile build', 0 ),
BoolVariable( 'deploy', 'Deploy build', 0 ),
EnumVariable( 'arch', 'Architecture to compile for', '', allowed_values=( '', 'x86', 'x86_64', 'arm' ) ),
EnumVariable( 'sse', 'SSE instruction set to use', '2', allowed_values=( '2', '3', '4' ) ),
EnumVariable( 'platform', 'Platform to compile for', '', allowed_values=( '', 'linux', 'win32', 'win64', 'macosx', 'raspberrypi' ) ),
( 'libsuffix', 'Extra library name suffix', '' ),
EnumVariable( 'tools', 'Tools to use to build', 'gnu', allowed_values=( 'intel', 'gnu', 'msvc' ) ),
( 'foundationpath', 'Path to foundation library', '' ),
( 'networkpath', 'Path to network library', '' ),
( 'taskpath', 'Path to task library', '' ),
)
baseenv = Environment( variables=opts )
#for item in sorted(baseenv.Dictionary().items()):
# print "construction variable = '%s', value = '%s'" % item
#print "HOST_ARCH: %s" % baseenv['HOST_ARCH']
#print "TARGET_ARCH: %s" % baseenv['TARGET_ARCH']
#print "PLATFORM: %s" % baseenv['PLATFORM']
if ( "%s" % baseenv['HOST_ARCH'] ) == 'None':
if baseenv['PLATFORM'] == 'win32':
baseenv['HOST_ARCH'] = 'x86'
else:
baseenv['HOST_ARCH'] = os.popen("arch").read().rstrip()
if baseenv['PLATFORM'] == 'win32':
if baseenv['tools'] == 'gnu':
baseenv['tools'] = 'mingw'
if baseenv['PLATFORM'] == 'posix':
if baseenv['tools'] == 'gnu':
baseenv['tools'] = 'default'
if baseenv['arch'] == 'arm':
baseenv['TARGET_ARCH'] = 'arm'
elif baseenv['arch'] == 'x86_64':
baseenv['TARGET_ARCH'] = 'x86_64'
elif baseenv['arch'] == 'x86':
baseenv['TARGET_ARCH'] = 'x86'
else:
baseenv['TARGET_ARCH'] = baseenv['HOST_ARCH']
if baseenv['platform'] == 'win64':
baseenv['TARGET_ARCH'] = 'x86_64'
env = Environment(
variables=opts,
CPPPATH=['#'],
TARGET_ARCH=baseenv['TARGET_ARCH'],
HOST_ARCH=baseenv['HOST_ARCH'],
tool=[ baseenv['tools'] ]
)
#for item in sorted(baseenv.Dictionary().items()):
# print "construction variable = '%s', value = '%s'" % item
env['platformsuffix'] = ''
if env['PLATFORM'] == 'posix':
if env['platform'] == '':
env['platform'] = 'linux'
env['arch'] = env['TARGET_ARCH']
env['ENV']['TERM'] = os.environ['TERM']
#if env['platform'] == 'raspberrypi':
# env['CC'] = 'clang'
# env['CXX'] = 'clang++'
# env['LD'] = 'llvm-ld'
if env['TARGET_ARCH'] == 'x86' and env['arch'] != 'x86_64':
env['arch'] = 'x86'
if env['TARGET_ARCH'] == 'i686' and env['arch'] != 'x86_64':
env['arch'] = 'x86'
if env['TARGET_ARCH'] == 'x86_64':
env['arch'] = 'x86_64'
if env['TARGET_OS'] == 'win32':
if env['arch'] == 'x86_64':
env['platform'] = 'win64'
elif env['arch'] == 'x86':
env['platform'] = 'win32'
else:
if env['HOST_ARCH'] == 'x86_64':
env['platform'] = 'win64'
env['arch'] = 'x86_64'
else:
env['platform'] = 'win32'
env['arch'] = 'x86'
if env['platform'] == 'linux':
if env['arch'] == 'x86':
env['platformsuffix'] = '32'
elif env['arch'] == 'x86_64':
env['platformsuffix'] = '64'
else:
env['platformsuffix'] = env['arch']
#print "HOST_ARCH: %s" % baseenv['HOST_ARCH']
#print "TARGET_ARCH: %s" % baseenv['TARGET_ARCH']
#print "PLATFORM: %s" % baseenv['PLATFORM']
print "Building on " + env['PLATFORM'] + " (" + env['HOST_ARCH'] + ") for " + env['platform'] + " (" + env['arch'] + ")"
Help( opts.GenerateHelpText( env ) )
if env['platform'] == 'raspberrypi':
env.Append( CFLAGS=['-march=armv6j','-mfloat-abi=hard','-mfpu=vfp','-mtune=arm1176jzf-s'] )
env.Append( CXXFLAGS=['-march=armv6j','-mfloat-abi=hard','-mfpu=vfp','-mtune=arm1176jzf-s'] )
env.Append( CPPPATH=['/opt/vc/include','/opt/vc/include/interface/vcos/pthreads'] )
env.Append( LIBPATH=['/opt/vc/lib'] )
#echo 'SUBSYSTEM=="vchiq",GROUP="video",MODE="0660"' > /etc/udev/rules.d/10-vchiq-permissions.rules
#usermod -a -G video [your_username]
if env['CC'] == 'gcc' or env['CC'] == 'clang':
env.Append( CFLAGS=['-std=gnu99','-W','-Wall','-Wcast-align','-Wcast-qual','-Wchar-subscripts','-Winline','-Wpointer-arith','-Wredundant-decls','-Wshadow','-Wwrite-strings','-Wno-variadic-macros','-Wno-long-long','-Wno-format','-Wno-unused','-Wundef','-Wstrict-aliasing','-Wno-missing-field-initializers','-Wno-missing-braces','-Wno-unused-parameter','-ftabstop=4','-fstrict-aliasing'] )
if env['platform'] != 'raspberrypi':
env.Append( CFLAGS=['-pedantic','-Werror'] )
if env['arch'] == 'x86':
env.Append( CCFLAGS=['-m32'] )
env.Append( LINKFLAGS=['-m32'] )
env.Append( CCFLAGS=['-msse' + env['sse']] )
if env['arch'] == 'x86_64':
env.Append( CCFLAGS=['-m64'] )
env.Append( LINKFLAGS=['-m64'] )
env.Append( CCFLAGS=['-msse' + env['sse']] )
env.Append( LINKFLAGS=['-pthread'] )
if env['CC'] == 'cl':
env.Append( LINKFLAGS=[ '/MACHINE:X86' ] )
# SETUP DEFAULT ENVIRONMENT
if env['PLATFORM'] == 'win32':
# AVOID CMDLINE LENGTH OVERFLOW
import win32file
import win32event
import win32process
import win32security
import string
import shutil
def my_spawn(sh, escape, cmd, args, spawnenv):
for var in spawnenv:
spawnenv[var] = spawnenv[var].encode('ascii', 'replace')
sAttrs = win32security.SECURITY_ATTRIBUTES()
StartupInfo = win32process.STARTUPINFO()
newargs = string.join( args[1:], ' ' ) #map(escape, args[1:]), ' ')
cmdline = cmd + " " + newargs
exit_code = 0
# check for any special operating system commands
if cmd == 'del':
for arg in args[1:]:
win32file.DeleteFile(arg)
elif cmd == 'copy':
shutil.copyfile(args[1].strip('"'),args[2].strip('"'))
else:
# otherwise execute the command.
hProcess, hThread, dwPid, dwTid = win32process.CreateProcess(None, cmdline, None, None, 1, 0, spawnenv, None, StartupInfo)
win32event.WaitForSingleObject(hProcess, win32event.INFINITE)
exit_code = win32process.GetExitCodeProcess(hProcess)
win32file.CloseHandle(hProcess);
win32file.CloseHandle(hThread);
return exit_code
env['SPAWN'] = my_spawn
if env['CC'] == 'gcc':
env['BUILDERS']['PCH'] = Builder( action = '$CXX -x c++-header $CXXFLAGS $_CPPINCFLAGS $_CPPDEFFLAGS -o $TARGET $SOURCE', suffix = '.h.gch', src_suffix = '.h' )
# SETUP DEBUG ENVRIONMENT
if env['debug']:
env.Append( CPPDEFINES=['BUILD_DEBUG=1'] )
env['buildpath'] = 'debug'
if env['CC'] == 'gcc' or env['CC'] == 'clang':
env.Append( CFLAGS=['-g','-fno-math-errno','-ffinite-math-only'] )
if env['CC'] == 'gcc':
env.Append( CFLAGS=['-funsafe-math-optimizations','-fno-trapping-math'] )
env['buildprofile'] = 'debug'
# SETUP RELEASE ENVIRONMENT
elif not env['deploy'] and not env['profile']:
env.Append( CPPDEFINES=['BUILD_RELEASE=1'] )
env['buildpath'] = 'release';
if env['CC'] == 'gcc' or env['CC'] == 'clang':
env.Append( CFLAGS=['-g','-O3','-ffast-math','-funit-at-a-time','-fno-math-errno','-funsafe-math-optimizations','-ffinite-math-only','-fno-trapping-math','-funroll-loops'] )
env['buildprofile'] = 'release'
# SETUP PROFILE ENVIRONMENT
elif env['profile']:
env.Append( CPPDEFINES=['BUILD_PROFILE=1'] )
env['buildpath'] = 'profile';
if env['CC'] == 'gcc' or env['CC'] == 'clang':
env.Append( CFLAGS=['-g','-O6','-ffast-math','-funit-at-a-time','-fno-math-errno','-funsafe-math-optimizations','-ffinite-math-only','-fno-trapping-math','-funroll-loops'] )
env['buildprofile'] = 'profile'
# SETUP RTM ENVIRONMENT
else:
env.Append( CPPDEFINES=['BUILD_DEPLOY=1'] )
env['buildpath'] = 'deploy';
if env['CC'] == 'gcc' or env['CC'] == 'clang':
env.Append( CFLAGS=['-O6','-ffast-math','-funit-at-a-time','-fno-math-errno','-funsafe-math-optimizations','-ffinite-math-only','-fno-trapping-math','-funroll-loops'] )
env['buildprofile'] = 'deploy'
# SETUP COMMON ENVIRONMENT
if env['platform'] == 'raspberrypi':
env.Append( CPPDEFINES=['__raspberrypi__=1'] )
if not env['foundationpath'] == '':
env.Append( CPPPATH=[env['foundationpath']] )
env.Append( LIBPATH=[env['foundationpath'] + '/lib/${platform}${platformsuffix}/${buildprofile}'] )
if not env['networkpath'] == '':
env.Append( CPPPATH=[env['networkpath']] )
env.Append( LIBPATH=[env['networkpath'] + '/lib/${platform}${platformsuffix}/${buildprofile}', env['networkpath'] + '/lib/${platform}${platformsuffix}'] )
if not env['taskpath'] == '':
env.Append( CPPPATH=[env['taskpath']] )
env.Append( LIBPATH=[env['taskpath'] + '/lib/${platform}${platformsuffix}/${buildprofile}', env['taskpath'] + '/lib/${platform}${platformsuffix}'] )
env['buildpath'] = env['buildpath'] + '-' + env['platform'] + env['platformsuffix']
Export("env")
VariantDir( 'build/scons/%s/http' % env['buildpath'] , 'http', duplicate=0 )
SConscript( 'build/scons/%s/http/SConscript' % env['buildpath'] )
VariantDir( 'build/scons/%s/test' % env['buildpath'] , 'test', duplicate=0 )
SConscript( 'build/scons/%s/test/SConscript' % env['buildpath'] )
if not env['profile'] and not env['deploy']:
VariantDir( 'build/scons/%s/tools' % env['buildpath'] , 'tools', duplicate=0 )
SConscript( 'build/scons/%s/tools/SConscript' % env['buildpath'] )