Author: brane
Date: Wed Jun 25 01:34:51 2025
New Revision: 1926709
URL: http://svn.apache.org/viewvc?rev=1926709&view=rev
Log:
SERF-133: Don't override the user's optimization, debugging or C-standard
flags that the user provided on the command line.
* build/scons_extras.py: Add required imports.
(__env_munge_if): New. Invokes an environment method if the given
filtering constraints are met.
(AddEnvironmentMethods): New. Add methods SerfAppendIf and SerfPrependIf
to the SCons environment class. Both use __env_munge_if.
* SConstruct: Call build.scons_extras.AddEnvironmentMethods(), then
add the -std=c89, -g and -O2 compiler flags only if equivalents
were not already set by some other mechanism.
Modified:
serf/trunk/SConstruct
serf/trunk/build/scons_extras.py
Modified: serf/trunk/SConstruct
URL:
http://svn.apache.org/viewvc/serf/trunk/SConstruct?rev=1926709&r1=1926708&r2=1926709&view=diff
==============================================================================
--- serf/trunk/SConstruct (original)
+++ serf/trunk/SConstruct Wed Jun 25 01:34:51 2025
@@ -42,6 +42,7 @@ sys.path.insert(0, src_dir)
import build.scons_extras
import build.exports
+build.scons_extras.AddEnvironmentMethods()
custom_tests = {'CheckGnuCC': build.scons_extras.CheckGnuCC}
# SCons 4.7 introduced the function argument list parameter to CheckFunc.
@@ -326,16 +327,19 @@ if sys.platform != 'win32':
env = conf.Finish()
if have_gcc:
- env.Append(CFLAGS=['-std=c89'])
+ # env.Append(CFLAGS=['-std=c89'])
+ env.SerfAppendIf(['CFLAGS'], r'-(ansi|std=c\d+)', CFLAGS=['-std=c89'])
env.Append(CCFLAGS=['-Wdeclaration-after-statement',
'-Wmissing-prototypes',
'-Wall'])
if debug:
- env.Append(CCFLAGS=['-g'])
+ # env.Append(CCFLAGS=['-g'])
+ env.SerfAppendIf(['CFLAGS', 'CCFLAGS'], r'-g\S*', CCFLAGS=['-g'])
env.Append(CPPDEFINES=['DEBUG', '_DEBUG'])
else:
- env.Append(CCFLAGS=['-O2'])
+ # env.Append(CCFLAGS=['-O2'])
+ env.SerfAppendIf(['CFLAGS', 'CCFLAGS'], r'-O\S*', CCFLAGS=['-O2'])
env.Append(CPPDEFINES=['NDEBUG'])
### works for Mac OS. probably needs to change
Modified: serf/trunk/build/scons_extras.py
URL:
http://svn.apache.org/viewvc/serf/trunk/build/scons_extras.py?rev=1926709&r1=1926708&r2=1926709&view=diff
==============================================================================
--- serf/trunk/build/scons_extras.py (original)
+++ serf/trunk/build/scons_extras.py Wed Jun 25 01:34:51 2025
@@ -19,6 +19,11 @@
# under the License.
# ===================================================================
+import re
+
+import SCons.Environment
+import SCons.Util
+
def CheckGnuCC(context):
'''Check if the compiler is compatible with gcc.'''
@@ -35,6 +40,33 @@ oh noes!
return result
+def __env_munge_if(env, method, variables, pattern, **kwargs):
+ '''Invoke `env`.`method`(**`kwargs`), unless `pattern` matches the
+ values in `variables` that are also in `env`.
+ '''
+
+ rx = re.compile(pattern)
+ for var in variables:
+ values = env.get(var, [])
+ for value in values:
+ if rx.search(value):
+ return
+ getattr(env, method)(**kwargs)
+
+
+def AddEnvironmentMethods():
+ SCons.Util.AddMethod(
+ SCons.Environment.Environment,
+ lambda env, variables, pattern, **kwargs:
+ __env_munge_if(env, 'Append', variables, pattern, **kwargs),
+ 'SerfAppendIf')
+ SCons.Util.AddMethod(
+ SCons.Environment.Environment,
+ lambda env, variables, pattern, **kwargs:
+ __env_munge_if(env, 'Prepend', variables, pattern, **kwargs),
+ 'SerfPrependIf')
+
+
#
# The following code is derived from SCons, version 4.7.0.
#