-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSconstruct
200 lines (168 loc) · 7.49 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
#
# Copyright (C) 2012-2013 Designture
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Release information
version = {
'PULSAR_VER_RELEASE': 1,
'PULSAR_VER_UPDATE': 0,
'PULSAR_VER_REVISION': 0,
}
# C/C++ warning flags.
cc_warning_flags = [
'-Wall', '-Wextra', '-Wno-variadic-macros', '-Wno-unused-parameter',
'-Wwrite-strings', '-Wmissing-declarations', '-Wredundant-decls',
'-Wno-format', '-Werror', '-Wno-error=unused',
]
# C++ warning flags.
cxx_warning_flags = [
'-Wold-style-cast', '-Wsign-promo',
]
# Variables to set in target environments.
target_flags = {
'CCFLAGS': cc_warning_flags + ['-gdwarf-2', '-pipe', '-fno-omit-frame-pointer'],
'CFLAGS': ['-std=gnu11'],
'CXXFLAGS': cxx_warning_flags + ['-std=c++11'],
'ASFLAGS': ['-D__ASM__'],
}
# Variables to set in host environments. Don't build C code with our normal
# warning flags, Kconfig and Flex/Bison code won't compile with them. Also
# older host G++ versions don't support some flags.
host_flags = {
'CCFLAGS': ['-pipe'],
'CFLAGS': ['-std=gnu99'],
'CXXFLAGS': filter(lambda f: f not in [
'-Wmissing-declarations', '-Wno-variadic-macros',
'-Wno-unused-but-set-variable'], cc_warning_flags),
'YACCFLAGS': ['-d'],
}
#########################
# Internal build setup. #
#########################
import os, sys, SCons.Errors
# Add the path to our build utilities to the path
sys.path = [os.path.abspath(os.path.join('utilities', 'build'))] + sys.path
from manager import BuildManager
from kconfig import ConfigParser
from toolchain import ToolchainManager
from util import RequireTarget
import vcs
# Set the version string.
version['PULSAR_VER_STRING'] = '%d.%d' % (
version['PULSAR_VER_RELEASE'],
version['PULSAR_VER_UPDATE'])
if version['PULSAR_VER_REVISION']:
version['PULSAR_VER_STRING'] += '.%d' % (version['PULSAR_VER_REVISION'])
revision = vcs.revision_id()
if revision:
version['PULSAR_VER_STRING'] += '-%s' % (revision)
# Change the Decider to MD5-timestamp to speed up the build a bit.
Decider('MD5-timestamp')
host_env = Environment(ENV = os.environ)
target_env = Environment(platform = 'posix', ENV = os.environ)
manager = BuildManager(host_env, target_env)
#Load the build configuration (if it exists yet)
config = ConfigParser('.config')
manager.AddVariable('_CONFIG', config)
# Make Config, Manager and Version available outside this script
Export('config', 'manager', 'version')
# Set up the host environment template
for (k, v) in host_flags.items():
host_env[k] = v
# darwin hosts probably have needed libraries in /opt
if os.uname()[0] == 'Darwin':
host_env['CPPPATH'] = ['/opt/local/include']
host_env['LIBPATH'] = ['/opt/local/lib']
# Cretae yhe host environment and build host utilities.
env = manager.CreateHost(name = 'host')
SConscript('utilities/SConscript', variant_dir = os.path.join('build', 'host'), exports = ['env'])
# Add targets to run the configuration interface
env['ENV']['KERNELVERSION'] = version['PULSAR_VER_STRING']
Alias('config', env.ConfigMenu('__config', ['Kconfig']))
# If the configuration does not exist, all we can do is configure. Raise an
# error to notify the user that they need to configure if they are not trying
# to do so, and don't run the rest of the build.
if not config.configured() or 'config' in COMMAND_LINE_TARGETS:
RequireTarget('config',
"Configuration missing or out of date. Please update using 'config' target.")
Return()
# Initialise the toolchain manager and add the toolchain build target.
toolchain = ToolchainManager(config)
Alias('toolchain', Command('__toolchain', [], Action(toolchain.update, None)))
# If the toolchain is out of date, only allow it to be built.
if toolchain.check() or 'toolchain' in COMMAND_LINE_TARGETS:
RequireTarget('toolchain',
"Toolchain out of date. Update using the 'toolchain' target.")
Return()
# Now set up the target template environment.
for (k, v) in target_flags.items():
target_env[k] = v
# Clang,s integrated assembler doesn't suport 16-bit code.
target_env['ASFLAGS'] = ['-D__ASM__', '-no-integrated-as']
# Set correct shared library link flags.
target_env['SHCCFLAGS'] = '$CCFLAGS -fPIC -DSHARED'
target_env['SHLINKFLAGS'] = '$LINKFLAGS -shared -Wl,-soname,${TARGET.name}'
# Override default assembler - it uses as directly, we want to go through the
# compiler.
target_env['ASCOM'] = '$CC $_CCCOMCOM $ASFLAGS -c -o $TARGET $SOURCES'
# Add an action for ASM files in a shared library.
from SCons.Tool import createObjBuilders
static_obj, shared_obj = createObjBuilders(target_env)
shared_obj.add_action('.S', Action('$CC $_CCCOMCOM $ASFLAGS -DSHARED -c -o $TARGET $SOURCES', '$ASCOMSTR'))
# Add in extra compilation flags from the configuration.
if config.has_key('ARCH_ASFLAGS'):
target_env['ASFLAGS'] += config['ARCH_ASFLAGS'].split()
if config.has_key('ARCH_CCFLAGS'):
target_env['CCFLAGS'] += config['ARCH_CCFLAGS'].split()
if config.has_key('PLATFORM_ASFLAGS'):
target_env['CCFLAGS'] += config['PLATFORM_ASFLAGS'].split()
if config.has_key('PLATFORM_CCFLAGS'):
target_env['CCFLAGS'] += config['PLATFORM_CCFLAGS'].split()
target_env['CCFLAGS'] += config['EXTRA_CCFLAGS'].split()
target_env['CFLAGS'] += config['EXTRA_CFLAGS'].split()
target_env['CXXFLAGS'] += config['EXTRA_CXXFLAGS'].split()
# Set paths to toolchain components.
if os.environ.has_key('CC') and os.path.basename(os.environ['CC']) == 'ccc-analyzer':
target_env['CC'] = os.environ['CC']
target_env['ENV']['CCC_CC'] = toolchain.tool_path('clang')
# Force a rebuild when doing static analysis.
def decide_if_changed(dependency, target, prev_ni):
return True
target_env.Decider(decide_if_changed)
else:
target_env['CC'] = toolchain.tool_path('clang')
if os.environ.has_key('CXX') and os.path.basename(os.environ['CXX']) == 'c++-analyzer':
target_env['CXX'] = os.environ['CXX']
target_env['ENV']['CCC_CXX'] = toolchain.tool_path('clang++')
else:
target_env['CXX'] = toolchain.tool_path('clang++')
target_env['AS'] = toolchain.tool_path('as')
target_env['OBJDUMP'] = toolchain.tool_path('objdump')
target_env['READELF'] = toolchain.tool_path('readelf')
target_env['NM'] = toolchain.tool_path('nm')
target_env['STRIP'] = toolchain.tool_path('strip')
target_env['AR'] = toolchain.tool_path('ar')
target_env['RANLIB'] = toolchain.tool_path('ranlib')
target_env['OBJCOPY'] = toolchain.tool_path('objcopy')
target_env['LD'] = toolchain.tool_path('ld')
# Build the target system.
SConscript('source/SConscript', variant_dir = os.path.join('build',
'%s-%s' % (config['ARCH'], config['PLATFORM'])))
# Now that we have information of all libraries, update the toolchain sysroot.
toolchain.update_sysroot(manager)
# EOF