-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSConstruct
190 lines (135 loc) · 4.59 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
################################################################################
#
# SConstruct
#
################################################################################
# avoid creation of *.pyc files in the source tree
import sys
sys.dont_write_bytecode = True
import copy
from SCons.Script.SConscript import SConsEnvironment
from scons.buildconfig import BuildConfig
from scons.messages import SetupMessages
from scons.projectmanager import ProjectManager
################################################################################
#
# Variable settings
#
################################################################################
# read variables from command line or SConfig file
vars = Variables('SConfig')
vars.Add(BoolVariable('verbose', 'print full gcc comands', 0))
vars.Add(BoolVariable('memusage', 'print memory usage for every project', 1))
vars.Add('gcc', 'path to gcc', 'avr-gcc')
vars.Add('ar', 'path to ar', 'avr-gcc-ar')
vars.Add('ranlib', 'path to ranlib', 'avr-gcc-ranlib')
vars.Add('frequency', 'the target cpu frequency', 8000000)
################################################################################
#
# Projects
#
################################################################################
projects = []
projects += ['yalla']
projects += ['yalla/test/avr/bitset']
projects += ['yalla/test/avr/iomm']
projects += ['yalla/test/avr/register']
################################################################################
#
# Devices
#
################################################################################
devices = []
devices += ['atmega8']
################################################################################
#
# Global build configuration
#
################################################################################
globalConfig = BuildConfig()
# These flags are AVR specific
globalConfig.ccflags += ['-funsigned-char']
globalConfig.ccflags += ['-funsigned-bitfields']
globalConfig.ccflags += ['-fpack-struct']
globalConfig.ccflags += ['-fshort-enums']
# Warnings
globalConfig.ccflags += ['-Wall']
globalConfig.ccflags += ['-Wextra']
# Use C++ 11 standard
globalConfig.cxxflags += ['-std=c++11']
################################################################################
#
# Variants
#
################################################################################
variants = dict()
###################
# Optimized Build #
###################
optConfig = BuildConfig()
# optimization
optConfig.ccflags += ['-Os', '-g1']
# enable link time optimization
optConfig.ccflags += ['-flto']
# strip unused functions
optConfig.ccflags += ['-ffunction-sections', '-fdata-sections']
optConfig.linkflags += ['-Wl,--gc-sections']
# link relaxiation
optConfig.linkflags += ['-Wl,--relax']
variants['opt'] = optConfig
###############
# Debug Build #
###############
dbgConfig = BuildConfig()
# optimization
dbgConfig.ccflags += ['-O1', '-g3']
# define DEBUG macro
dbgConfig.cppdefines += ['DEBUG']
variants['dbg'] = dbgConfig
###############
# Simavr Build #
###############
# extend debug configuration
simConfig = copy.deepcopy(dbgConfig)
# define SIMAVR macro
simConfig.cppdefines += ['SIMAVR']
# add simavr to include path
simConfig.parse += ['pkg-config --cflags simavr']
simConfig.linkflags += ['-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000']
variants['sim'] = simConfig
################################################################################
#
# Create the environment
#
################################################################################
env = Environment(variables = vars)
# Generate help text for variables
Help(vars.GenerateHelpText(env))
# put all .sconsign files in one place
env.SConsignFile()
# override the default build tools
env['CC'] = env['gcc']
env['CXX'] = env['gcc']
env['AR'] = env['ar']
env['RANLIB'] = env['ranlib']
# set messages
if env['verbose'] == 0:
SetupMessages(env)
# set the CPU frequency
globalConfig.cppdefines += ['F_CPU=' + str(env['frequency'])]
# set global build configuration
globalConfig.AppendToEnvironment(env)
# construct the project manager and add it to the environment
SConsEnvironment.pm = ProjectManager(env, projects, devices, variants)
# export the environment so SConscripts can access it
Export('env')
# set default target
Default('build.opt')
################################################################################
#
# Build it!
#
################################################################################
# tell the project manager about every project in the list
# the rest is handled by the SConscripts
env.pm.BuildAll()