From c12a69b88f738642e3db56075887da12bd5bf658 Mon Sep 17 00:00:00 2001 From: Raphael Lehmann Date: Fri, 14 Oct 2016 17:41:07 +0200 Subject: [PATCH] [scons] Allow setting compiler optimization level. The optimization level can be set in `project.cfg` as `build.optimization=level` and overwritten using the command line argument `optimization=level`. --- scons/site_tools/arm.py | 2 +- scons/site_tools/avr.py | 2 +- scons/site_tools/hosted.py | 1 + scons/site_tools/xpcc.py | 14 ++++++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/scons/site_tools/arm.py b/scons/site_tools/arm.py index 7b4a1f2e8..7fc61a8d8 100644 --- a/scons/site_tools/arm.py +++ b/scons/site_tools/arm.py @@ -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", diff --git a/scons/site_tools/avr.py b/scons/site_tools/avr.py index a8b9d660a..0e2eb6194 100644 --- a/scons/site_tools/avr.py +++ b/scons/site_tools/avr.py @@ -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", diff --git a/scons/site_tools/hosted.py b/scons/site_tools/hosted.py index f5f60704e..acc2a2f51 100644 --- a/scons/site_tools/hosted.py +++ b/scons/site_tools/hosted.py @@ -89,6 +89,7 @@ def generate(env, **kw): "-Wundef", "-ggdb", "-DBASENAME=${SOURCE.file}", + "$OPTIMIZATION", ] #if c_compiler == 'clang': diff --git a/scons/site_tools/xpcc.py b/scons/site_tools/xpcc.py index 6262fa3c3..3fd2e9202 100644 --- a/scons/site_tools/xpcc.py +++ b/scons/site_tools/xpcc.py @@ -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') @@ -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')