[Xorp-cvs] SF.net SVN: xorp:[11595] trunk/xorp/SConstruct
bms_fbsd at users.sourceforge.net
bms_fbsd at users.sourceforge.net
Thu Nov 26 17:53:26 PST 2009
Revision: 11595
http://xorp.svn.sourceforge.net/xorp/?rev=11595&view=rev
Author: bms_fbsd
Date: 2009-11-27 01:53:26 +0000 (Fri, 27 Nov 2009)
Log Message:
-----------
Add an 'optimize' command line variable which can be used to set
the optimization level in a portable way, should we e.g. support icc
or llvm more fully later on. CFLAGS/CXXFLAGS will be sanitized to
enforce this option, unless 'optimize' is set to 'override'.
Enable GCC -O1 optimization level by default.
This trims most of the template fat from the compiled code, but
should not interfere with debugging.
The following command reports a 30% reduction in code size:
find obj -name '*.so' | xargs size -t
Modified Paths:
--------------
trunk/xorp/SConstruct
Modified: trunk/xorp/SConstruct
===================================================================
--- trunk/xorp/SConstruct 2009-11-27 00:37:09 UTC (rev 11594)
+++ trunk/xorp/SConstruct 2009-11-27 01:53:26 UTC (rev 11595)
@@ -69,6 +69,9 @@
BoolVariable('debug_msg', 'Build with debug messages', False),
BoolVariable('debug_fn', 'Build with function names in debug_msg output', False),
BoolVariable('debug_cb', 'Build with callback debugging', False),
+ EnumVariable('optimize', 'Build with optimization', 'yes',
+ allowed_values=('no', 'yes', 'full', 'size', 'override'),
+ map={}, ignorecase=2),
)
def tgt_guess():
@@ -145,6 +148,10 @@
if gnustrip:
env['_STRIP_UNNEEDED'] = "--strip-unneeded"
+# User can override this. Defaults to gcc's -O1, as this trims
+# most of the template fat.
+print 'Optimize code: ', env['optimize']
+
# Most of our shared library tweaks are specific to GNU ld.
# Check if the GNU linker is available, and print a warning if not.
if env['shared']:
@@ -346,6 +353,19 @@
env.AppendUnique( CXXFLAGS = Split(ARGUMENTS.get('CXXFLAGS', "-g")) )
env.AppendUnique( LINKFLAGS = Split(ARGUMENTS.get('LINKFLAGS', "")) )
+# If the user didn't override our default optimization, then
+# sanitize user's CFLAGS/CXXFLAGS to not contain optimization options,
+# and map to an appropriate GCC flag.
+if not env['optimize'] == 'override':
+ env.Replace( CFLAGS = filter(lambda s: not s.startswith('-O'),
+ Split(env['CFLAGS'])))
+ env.Replace( CXXFLAGS = filter(lambda s: not s.startswith('-O'),
+ Split(env['CXXFLAGS'])))
+ bigodict = { 'no': '-O0', 'yes': '-O1', 'full': '-O2', 'size': '-Os' }
+ bigoflag = bigodict[env['optimize']]
+ env.AppendUnique(CFLAGS = [ bigoflag ])
+ env.AppendUnique(CXXFLAGS = [ bigoflag ])
+
env.AppendUnique(CPPDEFINES = [
( '_FORTIFY_SOURCE', 0 ),
])
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Xorp-cvs
mailing list