Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Commit

Permalink
[scons] Allow setting compiler optimization level.
Browse files Browse the repository at this point in the history
The optimization level can be set in `project.cfg` as
`build.optimization=level` and overwritten using the command line 
argument `optimization=level`.
  • Loading branch information
rleh authored and salkinium committed Oct 15, 2016
1 parent 6c338ff commit c12a69b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scons/site_tools/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def generate(env, **kw):
"$FPU",
"$THUMB", # use THUMB='-mthumb' to compile as thumb code (default for AT91SAM)
"-mthumb-interwork",
"-Os",
"$OPTIMIZATION",
"-gdwarf-2",
"-funsigned-char",
"-funsigned-bitfields",
Expand Down
2 changes: 1 addition & 1 deletion scons/site_tools/avr.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def generate(env, **kw):
# flags for C and C++
env['CCFLAGS'] = [
"-mmcu=$AVR_DEVICE",
"-Os",
"$OPTIMIZATION",
"-gdwarf-2",
"-funsigned-char",
"-funsigned-bitfields",
Expand Down
1 change: 1 addition & 0 deletions scons/site_tools/hosted.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def generate(env, **kw):
"-Wundef",
"-ggdb",
"-DBASENAME=${SOURCE.file}",
"$OPTIMIZATION",
]

#if c_compiler == 'clang':
Expand Down
14 changes: 14 additions & 0 deletions scons/site_tools/xpcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ def generate(env, **kw):
if buildpath is None:
buildpath = parser.get('build', 'buildpath', os.path.join(os.curdir, 'build/'))

# optimization level can be declared in project.cfg
optimization = parser.get('build', 'optimization', 's')
# but can be overwritten by command line
optimization = ARGUMENTS.get('optimization', optimization)

# load parameters if available
if parser.has_section('parameters'):
env['XPCC_USER_PARAMETERS'] = parser.items('parameters')
Expand Down Expand Up @@ -388,6 +393,15 @@ def generate(env, **kw):
env['XPCC_SYSTEM_BUILDER'] = os.path.join(rootpath, 'tools', 'system_design', 'builder')
env['XPCC_DEVICE'] = device # needed by the platform tools

# compiler optimization
optimization_levels = ['0', '1', '2', '3', 's']
if optimization in optimization_levels:
env['OPTIMIZATION'] = "-O{}".format(optimization)
else:
env.Error("scons: Unknown compiler optimization level '{}'!".format(optimization))
env.Error("Available optimization levels are [{}]".format(', '.join(optimization_levels)))
Exit(1)

# tools which are used independently of the architecture
env.Tool('template') # needs to be added before platform_tools
env.Tool('unittest')
Expand Down

0 comments on commit c12a69b

Please sign in to comment.