[Numpy-svn] r4232 - branches/numpy.scons/numpy/core

numpy-svn@scip... numpy-svn@scip...
Thu Oct 18 04:40:16 CDT 2007


Author: cdavid
Date: 2007-10-18 04:40:11 -0500 (Thu, 18 Oct 2007)
New Revision: 4232

Modified:
   branches/numpy.scons/numpy/core/SConstruct
   branches/numpy.scons/numpy/core/scons_support.py
Log:
Put some configuration code in scons_support

Modified: branches/numpy.scons/numpy/core/SConstruct
===================================================================
--- branches/numpy.scons/numpy/core/SConstruct	2007-10-18 09:38:38 UTC (rev 4231)
+++ branches/numpy.scons/numpy/core/SConstruct	2007-10-18 09:40:11 UTC (rev 4232)
@@ -1,8 +1,8 @@
-# Last Change: Thu Oct 18 05:00 PM 2007 J
+# Last Change: Thu Oct 18 06:00 PM 2007 J
 # vim:syntax=python
 import os
-from os.path import join as pjoin, basename as pbasename, dirname as pdirname
 import sys
+from os.path import join as pjoin, basename as pbasename, dirname as pdirname
 from copy import deepcopy
 
 from numpy.distutils.scons import get_python_inc
@@ -10,92 +10,9 @@
 
 import SCons.Node
 
-def generate_config_header(target, source, env):
-    t = open(str(target[0]), 'w')
-    if not env.has_key('CONFIG_H_GEN'):
-        # XXX
-        assert 0 == 1
-    sym = env['CONFIG_H_GEN']
-    def write_symbol(define, value):
-        if value == 1:
-            return "#define %s\n\n" % define
-        elif value == 0:
-            return "/* #undef %s */\n\n" % define
-        else:
-            return "#define %s %s\n\n" % (define, value)
-    t.writelines([write_symbol(i[0], i[1]) for i in sym])
-    t.write('\n')
-    t.close()
+from scons_support import CheckBrokenMathlib, define_no_smp, \
+    generate_config_header, generate_config_header_emitter
 
-    print 'File: %s' % target[0]
-    target_f = open(str(target[0]))
-    print target_f.read()
-    target_f.close()
-    print 'EOF'
-    return 0
-
-def generate_config_header_emitter(target, source, env):
-    """Add dependency from config list  CONFIG_H_GEN to target.  Returns
-    original target, source tuple unchanged.  """
-    d = deepcopy(env['CONFIG_H_GEN']) # copy it
-    Depends(target, SCons.Node.Python.Value(d))
-    return target, source
-
-def define_no_smp():
-    """Returns True if we should define NPY_NOSMP, False otherwise."""
-    #--------------------------------
-    # Checking SMP and thread options
-    #--------------------------------
-    # Python 2.3 causes a segfault when
-    #  trying to re-acquire the thread-state
-    #  which is done in error-handling
-    #  ufunc code.  NPY_ALLOW_C_API and friends
-    #  cause the segfault. So, we disable threading
-    #  for now.
-    if sys.version[:5] < '2.4.2':
-        nosmp = 1
-    else:
-        # Perhaps a fancier check is in order here.
-        #  so that threads are only enabled if there
-        #  are actually multiple CPUS? -- but
-        #  threaded code can be nice even on a single
-        #  CPU so that long-calculating code doesn't
-        #  block.
-        try:
-            nosmp = os.environ['NPY_NOSMP']
-            nosmp = 1
-        except KeyError:
-            nosmp = 0
-    return nosmp == 1
-
-def CheckBrokenMathlib(context, mathlib):
-    src = """
-/* check whether libm is broken */
-#include <math.h>
-int main(int argc, char *argv[])
-{
-  return exp(-720.) > 1.0;  /* typically an IEEE denormal */
-}
-"""
-
-    try:
-        oldLIBS = deepcopy(context.env['LIBS'])
-    except:
-        oldLIBS = []
-
-    try:
-        context.Message("Checking if math lib %s is broken ... " % mathlib)
-        context.env.AppendUnique(LIBS = mathlib)
-        st = context.TryRun(src, '.c')
-    finally:
-        env['LIBS'] = oldLIBS
-
-    if st[0]:
-        context.Result(' not broken !')
-    else:
-        context.Result(' broken !')
-    return st[0]
-
 env = GetNumpyEnvironment(ARGUMENTS)
 env.Append(CPPPATH = [get_python_inc()])
 
@@ -296,9 +213,6 @@
                     pjoin(env['build_dir'], 'ufunc_api'), 
                     pjoin(env['src_dir'], 'code_generators', 'ufunc_api_order.txt'))
 
-# XXX
-env.Append(CCFLAGS = "-Wall -fno-strict-aliasing")
-
 env.Append(CPPPATH = [pjoin(env['src_dir'], 'include'), env['build_dir']])
 
 #-----------------

Modified: branches/numpy.scons/numpy/core/scons_support.py
===================================================================
--- branches/numpy.scons/numpy/core/scons_support.py	2007-10-18 09:38:38 UTC (rev 4231)
+++ branches/numpy.scons/numpy/core/scons_support.py	2007-10-18 09:40:11 UTC (rev 4232)
@@ -1,4 +1,8 @@
+import sys
+import os
+
 from os.path import join as pjoin, dirname as pdirname, basename as pbasename
+from copy import deepcopy
 
 from code_generators.generate_array_api import \
      do_generate_api as nowrap_do_generate_array_api
@@ -7,6 +11,8 @@
 
 from numpy.distutils.conv_template import process_str
 
+import SCons.Node
+
 def split_ext(string):
     sp = string.rsplit('.', 1)
     if len(sp) == 1:
@@ -80,3 +86,96 @@
     t = str(target[0]) + '.c'
     return ([t], source)
     
+#-------------------
+# Generate config.h 
+#-------------------
+def generate_config_header(target, source, env):
+    t = open(str(target[0]), 'w')
+    if not env.has_key('CONFIG_H_GEN'):
+        # XXX
+        assert 0 == 1
+    sym = env['CONFIG_H_GEN']
+    def write_symbol(define, value):
+        if value == 1:
+            return "#define %s\n\n" % define
+        elif value == 0:
+            return "/* #undef %s */\n\n" % define
+        else:
+            return "#define %s %s\n\n" % (define, value)
+    t.writelines([write_symbol(i[0], i[1]) for i in sym])
+    t.write('\n')
+    t.close()
+
+    print 'File: %s' % target[0]
+    target_f = open(str(target[0]))
+    print target_f.read()
+    target_f.close()
+    print 'EOF'
+    return 0
+
+def generate_config_header_emitter(target, source, env):
+    """Add dependency from config list  CONFIG_H_GEN to target.  Returns
+    original target, source tuple unchanged.  """
+    from SCons.Script import *
+    d = deepcopy(env['CONFIG_H_GEN']) # copy it
+    Depends(target, SCons.Node.Python.Value(d))
+    return target, source
+
+#-----------------------------------------
+# Other functions related to configuration
+#-----------------------------------------
+def CheckBrokenMathlib(context, mathlib):
+    src = """
+/* check whether libm is broken */
+#include <math.h>
+int main(int argc, char *argv[])
+{
+  return exp(-720.) > 1.0;  /* typically an IEEE denormal */
+}
+"""
+
+    try:
+        oldLIBS = deepcopy(context.env['LIBS'])
+    except:
+        oldLIBS = []
+
+    try:
+        context.Message("Checking if math lib %s is broken ... " % mathlib)
+        context.env.AppendUnique(LIBS = mathlib)
+        st = context.TryRun(src, '.c')
+    finally:
+        context.env['LIBS'] = oldLIBS
+
+    if st[0]:
+        context.Result(' not broken !')
+    else:
+        context.Result(' broken !')
+    return st[0]
+
+def define_no_smp():
+    """Returns True if we should define NPY_NOSMP, False otherwise."""
+    #--------------------------------
+    # Checking SMP and thread options
+    #--------------------------------
+    # Python 2.3 causes a segfault when
+    #  trying to re-acquire the thread-state
+    #  which is done in error-handling
+    #  ufunc code.  NPY_ALLOW_C_API and friends
+    #  cause the segfault. So, we disable threading
+    #  for now.
+    if sys.version[:5] < '2.4.2':
+        nosmp = 1
+    else:
+        # Perhaps a fancier check is in order here.
+        #  so that threads are only enabled if there
+        #  are actually multiple CPUS? -- but
+        #  threaded code can be nice even on a single
+        #  CPU so that long-calculating code doesn't
+        #  block.
+        try:
+            nosmp = os.environ['NPY_NOSMP']
+            nosmp = 1
+        except KeyError:
+            nosmp = 0
+    return nosmp == 1
+



More information about the Numpy-svn mailing list