[Numpy-svn] r4373 - branches/numpy.scons/numpy/distutils/scons

numpy-svn@scip... numpy-svn@scip...
Fri Nov 2 02:56:12 CDT 2007


Author: cdavid
Date: 2007-11-02 02:56:03 -0500 (Fri, 02 Nov 2007)
New Revision: 4373

Modified:
   branches/numpy.scons/numpy/distutils/scons/default.py
   branches/numpy.scons/numpy/distutils/scons/numpyenv.py
Log:
Start working on compiler flags customization

Modified: branches/numpy.scons/numpy/distutils/scons/default.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/default.py	2007-11-01 10:45:17 UTC (rev 4372)
+++ branches/numpy.scons/numpy/distutils/scons/default.py	2007-11-02 07:56:03 UTC (rev 4373)
@@ -1,5 +1,5 @@
 #! /usr/bin/env python
-# Last Change: Thu Oct 18 05:00 PM 2007 J
+# Last Change: Fri Nov 02 04:00 PM 2007 J
 
 # This is a copy of scons/Tools/__init__.py, because scons does not offer any
 # public api for this
@@ -81,3 +81,39 @@
             'tar', 'tex', 'yacc', 'zip']
     return linkers, c_compilers, cxx_compilers, assemblers, fortran_compilers, \
            ars, other_tools
+
+# Handling compiler configuration: only flags which change how to build object
+# files. Nothing related to linking, search path, etc... should be given here.
+# Basically, limit yourself to optimization/debug/warning flags.
+class CompilerConfig:
+    def __init__(self, optim = None, warn = None, debug = None, debug_symbol = None):
+        # XXX: several level of optimizations ?
+        self.optim = optim
+        # XXX: several level of warnings ?
+        self.warn = warn
+        # To enable putting debugging info in binaries
+        self.debug_symbol = debug_symbol
+        # To enable friendly debugging
+        self.debug = debug
+
+    def get_optims(self, level):
+        pass
+
+    def get_warn(self, level):
+        pass
+
+    def get_flags_dict(self):
+        return {'NUMPY_OPTIM_CFLAGS' : self.optim,
+                'NUMPY_WARN_CFLAGS' : self.warn,
+                'NUMPY_DEBUG_CFLAGS' : self.debug,
+                'NUMPY_DEBUG_SYMBOL_CFLAGS' : self.debug_symbol}
+
+def get_cc_config(name):
+    if name == 'gcc':
+        cfg = CompilerConfig(optim = ['-O2', '-fno-strict-aliasing', '-DNDEBUG'],
+                             warn = ['-Wall', '-Wstrict-prototypes'],
+                             debug_symbol = ['-g'])
+    else:
+        cfg = CompilerConfig()
+
+    return cfg

Modified: branches/numpy.scons/numpy/distutils/scons/numpyenv.py
===================================================================
--- branches/numpy.scons/numpy/distutils/scons/numpyenv.py	2007-11-01 10:45:17 UTC (rev 4372)
+++ branches/numpy.scons/numpy/distutils/scons/numpyenv.py	2007-11-02 07:56:03 UTC (rev 4373)
@@ -8,7 +8,7 @@
 from numpy.distutils.misc_util import get_scons_build_dir, get_scons_configres_dir,\
     get_scons_configres_filename
 
-from default import tool_list
+from default import tool_list, get_cc_config
 from custom_builders import NumpySharedLibrary, NumpyCtypes, NumpyPythonExtension
 from libinfo import get_config
 from extension_scons import PythonExtension
@@ -72,7 +72,18 @@
 
     return opts
 
+def customize_cc(name, env):
+    """Customize env options related to the given tool."""
+    cfg = get_cc_config(name)
+    env.AppendUnique(**cfg.get_flags_dict())
+
 def GetNumpyEnvironment(args):
+    env = _GetNumpyEnvironment(args)
+    env.AppendUnique(CFLAGS  = env['NUMPY_WARN_CFLAGS'] + env['NUMPY_OPTIM_CFLAGS'] +\
+                               env['NUMPY_DEBUG_SYMBOL_CFLAGS'])
+    return env
+
+def _GetNumpyEnvironment(args):
     """Call this with args = ARGUMENTS."""
     from SCons.Environment import Environment
     from SCons.Tool import Tool, FindTool, FindAllTools
@@ -116,6 +127,7 @@
                     t = Tool(env['cc_opt'], 
                              topdir = os.path.split(env['cc_opt_path'])[0])
                     t(env) 
+                    customize_cc(t.name, env)
                 else:
                     if is_cc_suncc(pjoin(env['cc_opt_path'], env['cc_opt'])):
                         env['cc_opt'] = 'suncc'
@@ -123,6 +135,7 @@
                     # PATH ? (may not work on windows).
                     t = Tool(env['cc_opt'])
                     t(env) 
+                    customize_cc(t.name, env)
                     if sys.platform == 'win32':
                         env['ENV']['PATH'] += ';%s' % env['cc_opt_path']
                     else:
@@ -134,6 +147,7 @@
     else:
         t = Tool(FindTool(DEF_C_COMPILERS))
         t(env)
+        customize_cc(t.name, env)
 
     # F77 compiler
     if len(env['f77_opt']) > 0:
@@ -197,10 +211,6 @@
     except KeyError:
         pass
 
-    # XXX: think about how to handle optimizations per compiler
-    if env['CC'] == 'gcc':
-        env.Append(CCFLAGS = "-Wall -Wstrict-prototypes -fno-strict-aliasing -O3 -g")
-
     # Adding custom builder
     env['BUILDERS']['NumpySharedLibrary'] = NumpySharedLibrary
     env['BUILDERS']['NumpyCtypes'] = NumpyCtypes



More information about the Numpy-svn mailing list