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

numpy-svn@scip... numpy-svn@scip...
Sat Oct 20 11:32:58 CDT 2007


Author: cdavid
Date: 2007-10-20 11:32:52 -0500 (Sat, 20 Oct 2007)
New Revision: 4263

Modified:
   branches/numpy.scons/numpy/core/SConstruct
   branches/numpy.scons/numpy/core/scons_support.py
Log:
Add proper check for broken mathlib

Modified: branches/numpy.scons/numpy/core/SConstruct
===================================================================
--- branches/numpy.scons/numpy/core/SConstruct	2007-10-20 12:49:15 UTC (rev 4262)
+++ branches/numpy.scons/numpy/core/SConstruct	2007-10-20 16:32:52 UTC (rev 4263)
@@ -9,7 +9,8 @@
 from numpy.distutils.scons import GetNumpyEnvironment
 
 from scons_support import CheckBrokenMathlib, define_no_smp, \
-    generate_config_header, generate_config_header_emitter
+    generate_config_header, generate_config_header_emitter, \
+    CheckMathlib
 
 env = GetNumpyEnvironment(ARGUMENTS)
 env.Append(CPPPATH = [get_python_inc()])
@@ -17,7 +18,9 @@
 #=======================
 # Starting Configuration
 #=======================
-config = env.NumpyConfigure(custom_tests = {'CheckBrokenMathlib' : CheckBrokenMathlib})
+# XXX: separate env for configuration
+config = env.NumpyConfigure(custom_tests = {'CheckBrokenMathlib' : CheckBrokenMathlib,
+    'CheckMathlib' : CheckMathlib})
 
 # Convention: list of tuples (definition, value). value:
 # - 0: #undef definition
@@ -73,12 +76,21 @@
 
 # TODO: getting the math lib automatically ? Having a list ?
 # TODO: checklib vs checkfunc ?
+mlibs = [[], ['cpml']]
 mathlib = os.environ.get('MATHLIB')
 if mathlib: 
-    # XXX: prepend it ?
-    mlib = mathlib
-else:
-    mlib = 'm'
+    # XXX: prepend it
+    mlibs.insert(0, mathlib)
+for mlib in mlibs:
+    st = config.CheckBrokenMathlib(mlib)
+    if st:
+        break
+
+if not st:
+    import SCons
+    raise SCons.Errors.UserError("No usable mathlib was found: chose another "\
+                                 "one using the MATHLIB env variable, eg "\
+                                 "MATHLIB=m")
 config_sym.append(('MATHLIB', str(mlib)))
 
 def check_lib(f, autoadd = 0):
@@ -95,11 +107,6 @@
 for f in mfuncs[1:]:
     check_lib(f)
 
-if not config.CheckBrokenMathlib(mlib):
-    raise SCons.Errors.UserError("Your mathlib looks broken: chose another "\
-                                 "one using the MATHLIB env variable, eg "\
-                                 "MATHLIB=m")
-
 #-------------------------------------------------------
 # Define the function PyOS_ascii_strod if not available
 #-------------------------------------------------------

Modified: branches/numpy.scons/numpy/core/scons_support.py
===================================================================
--- branches/numpy.scons/numpy/core/scons_support.py	2007-10-20 12:49:15 UTC (rev 4262)
+++ branches/numpy.scons/numpy/core/scons_support.py	2007-10-20 16:32:52 UTC (rev 4263)
@@ -125,6 +125,33 @@
 #-----------------------------------------
 # Other functions related to configuration
 #-----------------------------------------
+def CheckMathlib(context, mathlib):
+    src = """
+/* check whether exp can be found with current link/compile options */
+#include <math.h>
+int main(int argc, char *argv[])
+{
+    double a = exp(0);
+}
+"""
+    try:
+        oldLIBS = deepcopy(context.env['LIBS'])
+    except:
+        oldLIBS = []
+
+    try:
+        context.Message("Checking if math lib %s defines exp ... " % mathlib)
+        context.env.AppendUnique(LIBS = mathlib)
+        st = context.TryLink(src, '.c')
+    finally:
+        context.env['LIBS'] = oldLIBS
+
+    if st:
+        context.Result(' Yes')
+    else:
+        context.Result(' No ')
+    return st
+
 def CheckBrokenMathlib(context, mathlib):
     src = """
 /* check whether libm is broken */
@@ -141,16 +168,16 @@
         oldLIBS = []
 
     try:
-        context.Message("Checking if math lib %s is broken ... " % mathlib)
+        context.Message("Checking if math lib %s is usable for numpy ... " % mathlib)
         context.env.AppendUnique(LIBS = mathlib)
         st = context.TryRun(src, '.c')
     finally:
         context.env['LIBS'] = oldLIBS
 
     if st[0]:
-        context.Result(' not broken !')
+        context.Result(' Yes !')
     else:
-        context.Result(' broken !')
+        context.Result(' No !')
     return st[0]
 
 def define_no_smp():



More information about the Numpy-svn mailing list