First split up of SConf.py
Bram Moolenaar <[email protected]>
| Newsgroups | gmane.comp.tools.aap.devel |
|---|---|
| Message-ID | <[email protected]> |
At the end you will find a diff for splitting up the SConf.py file into
a part that is SConf-specific and a generic part, called Conftest.py.
The generic part is also used by the configure feature of Aap.
I am currently checking in the changes into CVS (see the download page:
http://www.a-a-p.org/download.html). Note that SourceForge has a backup
CVS server, it may not have the new version 1.012 for a while. Make
sure you use the real-time server for downloading.
The goal was to put the parts of the configure checks that do not depend
on the build system in Conftest.py. To make this possible an object is
passed to the check functions that has to offer specific methods and
members. This is documented at the start of the Conftest.py file.
Together with the public functions of Conftest.py this forms the
interface to the generic configure checks.
The functionality of SCons is unchanged. I have run all the tests I
could find. The "test/Configure.py" test had to be adjusted, because
the stdout of the tests changed slightly.
For Aap the new ":conf" command has been implemented. Some of this code
is from Joerg Beyer. There is no documentation yet, sorry! Look in
DoConf.py if you want to see how it works.
A few remarks:
- Renamed "show_result" to "did_show_result" to make clear what the flag
actually stands for.
- The tests can define HAVE_ABC variables and append them to a file
(normally called confdefs.h). This is required for many tests to
work, but since SCons didn't do this before, it is not done now
either. Aap does use this feature.
- I added comments about why a test is done in the way it is done. This
functions as a knowledge base, so that people who change the tests in
the future understand the reasoning behind the test method.
- Tests displayed "failed" when the test successfully detected that a
feature is not present. I find this confusing, thus changed it into
"yes". "failed" should be used when the test could not determine if
the feature is present or not.
- The SConf.py function arguments are not consistent, I have added a few
comments to point this out.
Feel free to make comments.
*** src/engine/SCons/SConf.py.orig Fri Aug 8 15:29:20 2003
--- src/engine/SCons/SConf.py Tue Aug 12 18:21:36 2003
***************
*** 30,36 ****
import cPickle
import os
- import shutil
import sys
import traceback
from types import *
--- 30,35 ----
***************
*** 42,47 ****
--- 41,47 ----
import SCons.Taskmaster
import SCons.Util
import SCons.Warnings
+ import SCons.Conftest
# First i thought of using a different filesystem as the default_fs,
# but it showed up that there are too many side effects in doing that.
***************
*** 503,509 ****
"""Constructor. Pass the corresponding SConf instance."""
self.sconf = sconf
self.cached = 0
! self.show_result = 0
def Message(self, text):
"""Inform about what we are doing right now, e.g.
--- 503,514 ----
"""Constructor. Pass the corresponding SConf instance."""
self.sconf = sconf
self.cached = 0
! self.did_show_result = 0
!
! # for Conftest.py:
! self.vardict = {}
! self.havedict = {}
! self.headerfilename = None # XXX may cause trouble!
def Message(self, text):
"""Inform about what we are doing right now, e.g.
***************
*** 513,541 ****
if self.sconf.logstream != None:
self.sconf.logstream.write(text + '\n')
sys.stdout.write(text)
! self.show_result = 0
! def Result(self, res ):
"""Inform about the result of the test. res may be an integer or a
string. In case of an integer, the written text will be 'ok' or
'failed'.
"""
! if( type(res) == IntType ):
if res:
text = "ok"
else:
text = "failed"
! elif( type(res) == StringType ):
text = res
else:
raise TypeError, "Expected string or int"
! if( self.cached ):
! text = text + " (cached)"
! if self.show_result == 0:
if self.sconf.logstream != None:
self.sconf.logstream.write("Result: " + text + "\n\n")
sys.stdout.write(text + "\n")
! self.show_result = 1
def TryBuild(self, *args, **kw):
--- 518,550 ----
if self.sconf.logstream != None:
self.sconf.logstream.write(text + '\n')
sys.stdout.write(text)
! self.did_show_result = 0
! def Result(self, res):
"""Inform about the result of the test. res may be an integer or a
string. In case of an integer, the written text will be 'ok' or
'failed'.
+ The result is only displayed when self.did_show_result is not set.
"""
! if type(res) == IntType:
if res:
text = "ok"
else:
text = "failed"
! elif type(res) == StringType:
text = res
else:
raise TypeError, "Expected string or int"
!
! if self.did_show_result == 0:
! if self.cached:
! text = text + " (cached)"
!
! # Didn't show result yet, do it now.
if self.sconf.logstream != None:
self.sconf.logstream.write("Result: " + text + "\n\n")
sys.stdout.write(text + "\n")
! self.did_show_result = 1
def TryBuild(self, *args, **kw):
***************
*** 561,670 ****
else:
raise AttributeError, "CheckContext instance has no attribute '%s'" % attr
! def _header_prog( header, include_quotes ):
! return "#include %s%s%s\n\n" % (include_quotes[0],
! header,
! include_quotes[1])
! def CheckFunc(context, function_name):
! context.Message("Checking for %s... " % function_name)
! ret = context.TryBuild(context.env.Program, """
! #include <assert.h>
! #ifdef __cplusplus
! extern "C"
! #endif
! char %(name)s();
!
! int main() {
! #if defined (__stub_%(name)s) || defined (__stub___%(name)s)
! fail fail fail
! #else
! %(name)s();
! #endif
! return 0;
! }\n\n""" % { 'name': function_name }, ".cpp")
! context.Result(ret)
! return ret
- def CheckType(context, type_name, includes = ""):
- context.Message("Checking for %s..." % type_name)
! ret = context.TryBuild(context.env.Program, """
! %(includes)s
- int main() {
- if ((%(name)s *) 0)
- return 0;
- if (sizeof (%(name)s))
- return 0;
- }\n\n""" % { 'name': type_name, 'includes': includes }, ".cpp")
- context.Result(ret)
! return ret
! def CheckCHeader(test, header, include_quotes='""'):
"""
! A test for a c header file.
"""
# ToDo: Support also system header files (i.e. #include <header.h>)
! test.Message("Checking for C header %s ... " % header)
! ret = test.TryCompile(_header_prog(header, include_quotes), ".c")
! test.Result( ret )
! return ret
! def CheckCXXHeader(test, header, include_quotes='""'):
"""
! A test for a c++ header file.
"""
! # ToDo: Support also system header files (i.e. #include <header.h>)
! test.Message("Checking for C++ header %s ... " % header)
! ret = test.TryCompile(_header_prog(header, include_quotes), ".cpp")
! test.Result( ret )
! return ret
! def CheckLib(test, library=None, symbol="main", autoadd=1):
"""
A test for a library. See also CheckLibWithHeader.
Note that library may also be None to test whether the given symbol
compiles without flags.
"""
# ToDo: accept path for the library
! test.Message("Checking for %s in library %s ... " % (symbol, library))
! oldLIBS = test.env.get( 'LIBS', [] )
- # NOTE: we allow this at in the case that we don't know what the
- # library is called like when we get --libs from a configure script
- if library != None:
- test.env.Append(LIBS = [ library ])
-
- text = ""
- if symbol != "main":
- text = text + """
- #ifdef __cplusplus
- extern "C"
- #endif
- char %s();""" % symbol
- text = text + """
- int
- main() {
- %s();
- return 0;
- }
- \n\n""" % symbol
-
- ret = test.TryLink( text, ".c" )
- if not autoadd or not ret:
- test.env.Replace(LIBS=oldLIBS)
! test.Result(ret)
! return ret
! def CheckLibWithHeader(test, library, header, language, call="main();", autoadd=1):
# ToDo: accept path for library. Support system header files.
"""
Another (more sophisticated) test for a library.
--- 570,698 ----
else:
raise AttributeError, "CheckContext instance has no attribute '%s'" % attr
! #### Stuff used by Conftest.py (look there for explanations).
! def BuildProg(self, text, ext):
! # TODO: should use self.vardict for $CC, $CPPFLAGS, etc.
! res = self.TryBuild(self.env.Program, text, ext)
! if type(res) == IntType:
! if res:
! ret = ""
! else:
! ret = "failed to build test program"
! elif type(res) == StringType:
! ret = res
! else:
! raise TypeError, "Expected string or int"
! return ret
! def CompileProg(self, text, ext):
! # TODO: should use self.vardict for $CC, $CPPFLAGS, etc.
! res = self.TryBuild(self.env.Object, text, ext)
! if type(res) == IntType:
! if res:
! ret = ""
! else:
! ret = "failed to compile test program"
! elif type(res) == StringType:
! ret = res
! else:
! raise TypeError, "Expected string or int"
! return ret
! def AppendLIBS(self, lib_name_list):
! oldLIBS = self.env.get( 'LIBS', [] )
! self.env.Append(LIBS = lib_name_list)
! return oldLIBS
!
! def SetLIBS(self, val):
! oldLIBS = self.env.get( 'LIBS', [] )
! self.env.Replace(LIBS = val)
! return oldLIBS
!
! def Display(self, msg):
! sys.stdout.write(msg)
! self.Log(msg)
! def Log(self, msg):
! if self.sconf.logstream != None:
! self.sconf.logstream.write(msg)
! #### End of stuff used by Conftest.py.
! # Bram: CheckFunc() only works for C currently. To test for a C++ function the
! # "suffix" argument should be added.
!
! def CheckFunc(context, function_name):
! res = SCons.Conftest.CheckFunc(context, function_name, suffix = ".c")
! context.did_show_result = 1
! if not res:
! return 1 # Ok
! return 0 # Failed
!
!
! # Bram: Shouldn't this use ".c" instead of ".cpp"? Should add suffix argument.
!
! def CheckType(context, type_name, includes = ""):
! res = SCons.Conftest.CheckType(context, type_name,
! suffix = ".cpp", header = includes)
! context.did_show_result = 1
! if not res:
! return 1 # Ok
! return 0 # Failed
! # Bram: New function, generic version of the C and C++ ones below.
! def CheckHeader(context, header, include_quotes = '""', suffix = ".c"):
"""
! A test for a C or C++ header file.
"""
# ToDo: Support also system header files (i.e. #include <header.h>)
! res = SCons.Conftest.CheckHeader(context, header, suffix = suffix,
! include_quotes = include_quotes)
! context.did_show_result = 1
! if not res:
! return 1 # Ok
! return 0 # Failed
! def CheckCHeader(context, header, include_quotes = '""'):
"""
! A test for a C header file.
"""
! return CheckHeader(context, header, include_quotes, ".c")
!
! def CheckCXXHeader(context, header, include_quotes = '""'):
! """
! A test for a C++ header file.
! """
! return CheckHeader(context, header, include_quotes, ".cpp")
!
!
! def CheckLib(context, library = None, symbol = "main", autoadd = 1):
"""
A test for a library. See also CheckLibWithHeader.
Note that library may also be None to test whether the given symbol
compiles without flags.
"""
# ToDo: accept path for the library
! res = SCons.Conftest.CheckLib(context, library, symbol,
! suffix = ".c", autoadd = autoadd)
! context.did_show_result = 1
! if not res:
! return 1 # Ok
! return 0 # Failed
! # XXX
! # Bram: Using "language" is inconsistent with use of "suffix" in other checks.
! # Bram: Can only include one header and can't use #ifdef HAVE_HEADER_H.
! def CheckLibWithHeader(context, library, header, language,
! call = "main();", autoadd = 1):
# ToDo: accept path for library. Support system header files.
"""
Another (more sophisticated) test for a library.
***************
*** 673,705 ****
As in CheckLib, we support library=None, to test if the call compiles
without extra link flags.
"""
- test.Message("Checking for %s in library %s (header %s) ... " %
- (call, library, header))
- oldLIBS= test.env.get( 'LIBS', [] )
-
- # NOTE: we allow this at in the case that we don't know what the
- # library is called like when we get --libs from a configure script
- if library != None:
- test.env.Append(LIBS = [ library ])
-
- text = """\
- #include "%s"
- int main() {
- %s
- return 0;
- }
- """ % (header, call)
-
if language in ["C", "c"]:
! extension=".c"
elif language in ["CXX", "cxx", "C++", "c++"]:
! extension=".cpp"
else:
raise SCons.Errors.UserError, "Unknown language!"
! ret = test.TryLink( text, extension)
! if not autoadd or not ret:
! test.env.Replace( LIBS = oldLIBS )
- test.Result(ret)
- return ret
--- 701,718 ----
As in CheckLib, we support library=None, to test if the call compiles
without extra link flags.
"""
if language in ["C", "c"]:
! extension = ".c"
elif language in ["CXX", "cxx", "C++", "c++"]:
! extension = ".cpp"
else:
raise SCons.Errors.UserError, "Unknown language!"
! res = SCons.Conftest.CheckLib(context, library, "main",
! header = '#include "%s"' % header,
! call = call, suffix = extension, autoadd = autoadd)
! context.did_show_result = 1
! if not res:
! return 1 # Ok
! return 0 # Failed
*** src/engine/SCons/Conftest.py.orig Fri Aug 8 15:29:40 2003
--- src/engine/SCons/Conftest.py Tue Aug 12 18:16:15 2003
***************
*** 0 ****
--- 1,429 ----
+ """SCons.Conftest
+
+ Autoconf-like configuration support; low level implementation of tests.
+ """
+
+ #
+ # Copyright (c) 2003 Stichting NLnet Labs
+ # Copyright (c) 2001, 2002, 2003 Steven Knight
+ #
+ # Permission is hereby granted, free of charge, to any person obtaining
+ # a copy of this software and associated documentation files (the
+ # "Software"), to deal in the Software without restriction, including
+ # without limitation the rights to use, copy, modify, merge, publish,
+ # distribute, sublicense, and/or sell copies of the Software, and to
+ # permit persons to whom the Software is furnished to do so, subject to
+ # the following conditions:
+ #
+ # The above copyright notice and this permission notice shall be included
+ # in all copies or substantial portions of the Software.
+ #
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+ # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ #
+
+ #
+ # The purpose of this module is to define how a check is to be performed.
+ # Use one of the Check...() functions below.
+ #
+
+ #
+ # A context class is used that defines functions for carrying out the tests,
+ # logging and messages. The following methods and members must be present:
+ #
+ # context.Display(msg) Function called to print messages that are normally
+ # displayed for the user. Newlines are explicitly used.
+ # The text should also be written to the logfile!
+ #
+ # context.Log(msg) Function called to write to a log file.
+ #
+ # context.BuildProg(text, ext)
+ # Function called to build a program, using "ext" for the
+ # file extention. Must return an empty string for
+ # success, an error message for failure.
+ # For reliable test results building should be done just
+ # like an actual program would be build, using the same
+ # command and arguments (including configure results so
+ # far).
+ #
+ # context.CompileProg(text, ext)
+ # Function called to compile a program, using "ext" for
+ # the file extention. Must return an empty string for
+ # success, an error message for failure.
+ # For reliable test results compiling should be done just
+ # like an actual source file would be compiled, using the
+ # same command and arguments (including configure results
+ # so far).
+ #
+ # context.AppendLIBS(lib_name_list)
+ # Append "lib_name_list" to the value of LIBS.
+ # "lib_namelist" is a list of strings.
+ # Return the value of LIBS before changing it (any type
+ # can be used, it is passed to SetLIBS() later.
+ #
+ # context.SetLIBS(value)
+ # Set LIBS to "value". The type of "value" is what
+ # AppendLIBS() returned.
+ # Return the value of LIBS before changing it (any type
+ # can be used, it is passed to SetLIBS() later.
+ #
+ # context.headerfilename
+ # Name of file to append configure results to, usually
+ # "confdefs.h".
+ # The file must not exist or be empty when starting.
+ # Empty or None to skip this (some tests will not work!).
+ #
+ # context.vardict Dictionary holding variables used for the tests and
+ # stores results from the tests, used for the build
+ # commands.
+ # Normally contains "CC", "LIBS", "CPPFLAGS", etc.
+ #
+ # context.havedict Dictionary holding results from the tests that are to
+ # be used inside a program.
+ # Names often start with "HAVE_". These are zero
+ # (feature not present) or one (feature present). Other
+ # variables may have any value, e.g., "PERLVERSION" can
+ # be a number and "SYSTEMNAME" a string.
+ #
+
+ import string
+ from types import IntType
+
+ #
+ # PUBLIC FUNCTIONS
+ #
+
+ def CheckBuilder(context, text = None, suffix = None):
+ """
+ Configure check to see if the compiler works.
+ Note that this uses the current value of compiler and linker flags, make
+ sure $CFLAGS, $CPPFLAGS and $LIBS are set correctly.
+ "suffix" should be ".c" or ".cpp" and is used to select the compiler.
+ Default is ".c".
+ "text" may be used to specify the code to be build.
+ Returns an empty string for success, an error message for failure.
+ """
+ if not suffix:
+ suffix = ".c"
+
+ if not text:
+ text = """
+ int main() {
+ return 0;
+ }\n\n"""
+
+ context.Display("Checking building a %s file works... " % suffix)
+ ret = context.BuildProg(text, suffix)
+ _YesNoResult(context, ret, None, text)
+ return ret
+
+
+ def CheckFunc(context, function_name, header = None, suffix = None):
+ """
+ Configure check for a C function "function_name".
+ Optional "header" can be defined to define a function prototype, include a
+ header file or anything else that comes before main().
+ Sets HAVE_function_name in context.havedict according to the result.
+ Note that this uses the current value of compiler and linker flags, make
+ sure $CFLAGS, $CPPFLAGS and $LIBS are set correctly.
+ Returns an empty string for success, an error message for failure.
+ """
+
+ # Remarks from autoconf:
+ # - Don't include <ctype.h> because on OSF/1 3.0 it includes <sys/types.h>
+ # which includes <sys/select.h> which contains a prototype for select.
+ # Similarly for bzero.
+ # - assert.h is included to define __stub macros and hopefully few
+ # prototypes, which can conflict with char $1(); below.
+ # - Override any gcc2 internal prototype to avoid an error.
+ # - We use char for the function declaration because int might match the
+ # return type of a gcc2 builtin and then its argument prototype would
+ # still apply.
+ # - The GNU C library defines this for functions which it implements to
+ # always fail with ENOSYS. Some functions are actually named something
+ # starting with __ and the normal name is an alias.
+ if not header:
+ header = """
+ #ifdef __cplusplus
+ extern "C"
+ #endif
+ char %s();""" % function_name
+ if not suffix:
+ suffix = ".c"
+
+ text = """
+ #include <assert.h>
+ %(hdr)s
+
+ int main() {
+ #if defined (__stub_%(name)s) || defined (__stub___%(name)s)
+ fail fail fail
+ #else
+ %(name)s();
+ #endif
+
+ return 0;
+ }\n\n""" % { 'name': function_name, 'hdr': header }
+
+ context.Display("Checking for %s()... " % function_name)
+ ret = context.BuildProg(text, suffix)
+ _YesNoResult(context, ret, "HAVE_" + function_name, text)
+ return ret
+
+
+ def CheckHeader(context, header_name, header = None, suffix = None,
+ include_quotes = None):
+ """
+ Configure check for a C or C++ header file "header_name".
+ Optional "header" can be defined to do something before including the
+ header file (unusual, supported for consistency).
+ Use ".cpp" for "suffix" to test C++.
+ Sets HAVE_header_name in context.havedict according to the result.
+ Note that this uses the current value of compiler and linker flags, make
+ sure $CFLAGS and $CPPFLAGS are set correctly.
+ Returns an empty string for success, an error message for failure.
+ """
+ # Why compile the program instead of just running the preprocessor?
+ # It is possible that the header file exists, but actually using it may
+ # fail (e.g., because it depends on other header files). Thus this test is
+ # more strict. It may require using the "header" argument.
+ #
+ # Use <> by default, because the check is normally used for system header
+ # files. SCons passes '""' to overrule this.
+ if not header:
+ header = ""
+ if not suffix:
+ suffix = ".c"
+ if not include_quotes:
+ include_quotes = "<>"
+
+ text = "%s\n#include %s%s%s\n\n" % (header,
+ include_quotes[0], header_name, include_quotes[1])
+
+ lang = _suffix2lang(suffix)
+ context.Display("Checking for %sheader file %s... " % (lang, header_name))
+ ret = context.CompileProg(text, suffix)
+ _YesNoResult(context, ret, "HAVE_" + header_name, text)
+ return ret
+
+
+ def CheckType(context, type_name, header = None, suffix = None):
+ """
+ Configure check for a C or C++ type "type_name".
+ Optional "header" can be defined to include a header file.
+ Use ".cpp" for "suffix" to test C++.
+ Sets HAVE_type_name in context.havedict according to the result.
+ Note that this uses the current value of compiler and linker flags, make
+ sure $CFLAGS, $CPPFLAGS and $LIBS are set correctly.
+ Returns an empty string for success, an error message for failure.
+ """
+ # Include "confdefs.h" first, so that the header can use HAVE_HEADER_H.
+ if context.headerfilename:
+ includetext = '#include "%s"' % context.headerfilename
+ else:
+ includetext = ''
+ if not header:
+ header = ""
+ if not suffix:
+ suffix = ".c"
+
+ # Remarks from autoconf about this test:
+ # - Grepping for the type in include files is not reliable (grep isn't
+ # portable anyway).
+ # - Using "TYPE my_var;" doesn't work for const qualified types in C++.
+ # Adding an initializer is not valid for some C++ classes.
+ # - Using the type as parameter to a function either fails for K&$ C or for
+ # C++.
+ # - Using "TYPE *my_var;" is valid in C for some types that are not
+ # declared (struct something).
+ # - Using "sizeof(TYPE)" is valid when TYPE is actually a variable.
+ # - Using the previous two together works reliably.
+ text = """
+ %(include)s
+ %(header)s
+
+ int main() {
+ if ((%(name)s *) 0)
+ return 0;
+ if (sizeof (%(name)s))
+ return 0;
+ }\n\n""" % { 'include': includetext,
+ 'header': header,
+ 'name': type_name }
+
+ context.Display("Checking for %s type... " % type_name)
+ ret = context.BuildProg(text, suffix)
+ _YesNoResult(context, ret, "HAVE_" + type_name, text)
+ return ret
+
+
+ def CheckLib(context, lib_name, func_name, header = None,
+ extra_libs = None, call = None, suffix = None, autoadd = 1):
+ """
+ Configure check for a C or C++ library "lib_name".
+ Tests if "func_name" or "call" exists in the library. Note: if it exists
+ in another library the test succeeds anyway!
+ Optional "header" can be defined to include a header file. If not given a
+ default prototype for "func_name" is added.
+ Optional "extra_libs" is a list of library names to be added after
+ "lib_name" in the build command. To be used for libraries that "lib_name"
+ depends on.
+ Optional "call" replaces the call to "func_name" in the test code. It must
+ consist of complete C statements, including a trailing ";".
+ There must either be a "func_name" or a "call" argument (or both).
+ Use ".cpp" for "suffix" to test C++.
+ Note that this uses the current value of compiler and linker flags, make
+ sure $CFLAGS, $CPPFLAGS and $LIBS are set correctly.
+ Returns an empty string for success, an error message for failure.
+ """
+ # Include "confdefs.h" first, so that the header can use HAVE_HEADER_H.
+ if context.headerfilename:
+ includetext = '#include "%s"' % context.headerfilename
+ else:
+ includetext = ''
+ if not header:
+ header = ""
+ if not suffix:
+ suffix = ".c"
+
+ text = """
+ %s
+ %s """ % (includetext, header)
+
+ # Add a function declaration if needed.
+ if func_name and func_name != "main" and not header:
+ text = text + """
+ #ifdef __cplusplus
+ extern "C"
+ #endif
+ char %s();""" % func_name
+
+ # The actual test code.
+ if not call:
+ call = "%s();" % func_name
+ text = text + """
+ int
+ main() {
+ %s
+ return 0;
+ }
+ \n\n""" % call
+
+ i = string.find(call, "\n")
+ if i > 0:
+ calltext = call[:i] + ".."
+ elif call[-1] == ';':
+ calltext = call[:-1]
+ else:
+ calltext = call
+
+ context.Display("Checking for %s in %slibrary %s... "
+ % (calltext, _suffix2lang(suffix), lib_name))
+ if lib_name:
+ l = [ lib_name ]
+ if extra_libs:
+ l.extend(extra_libs)
+ oldLIBS = context.AppendLIBS(l)
+ sym = "HAVE_LIB" + lib_name
+ else:
+ oldLIBS = -1
+ sym = None
+
+ ret = context.BuildProg(text, suffix)
+
+ _YesNoResult(context, ret, sym, text)
+ if oldLIBS != -1 and (ret or not autoadd):
+ context.SetLIBS(oldLIBS)
+
+ return ret
+
+
+ #
+ # END OF PUBLIC FUNCTIONS
+ #
+
+ def _YesNoResult(context, ret, key, text):
+ """
+ Handle the result of a test with a "yes" or "no" result.
+ "ret" is the return value: empty if OK, error message when not.
+ "key" is the name of the symbol to be defined (HAVE_foo).
+ "text" is the source code of the program used for testing.
+ """
+ if key:
+ _Have(context, key, not ret)
+ if ret:
+ context.Display("no\n")
+ _LogFailed(context, text, ret)
+ else:
+ context.Display("yes\n")
+
+
+ def _Have(context, key, have):
+ """
+ Store result of a test in context.havedict and context.headerfilename.
+ "key" is a "HAVE_abc" name. It is turned into all CAPITALS and ":./" are
+ replaced by an underscore.
+ The value of "have" can be:
+ 1 - Feature is defined, add "#define key".
+ 0 - Feature is not defined, add "/* #undef key */".
+ Adding "undef" is what autoconf does. Not useful for the
+ compiler, but it shows that the test was done.
+ number - Feature is defined to this number "#define key have".
+ Doesn't work for 0 or 1, use a string then.
+ string - Feature is defined to this string "#define key have".
+ Give "have" as is should appear in the header file, include quotes
+ when desired and escape special characters!
+ """
+ key_up = string.upper(key)
+ key_up = string.replace(key_up, ':', '_')
+ key_up = string.replace(key_up, '.', '_')
+ key_up = string.replace(key_up, '/', '_')
+ key_up = string.replace(key_up, ' ', '_')
+ context.havedict[key_up] = have
+ if context.headerfilename:
+ f = open(context.headerfilename, "a")
+ if have == 1:
+ f.write("#define %s\n" % key_up)
+ elif have == 0:
+ f.write("/* #undef %s */\n" % key_up)
+ elif type(have) == IntType:
+ f.write("#define %s %d\n" % (key_up, have))
+ else:
+ f.write("#define %s %s\n" % (key_up, str(have)))
+ f.close()
+
+
+ def _LogFailed(context, text, msg):
+ """
+ Write to the log about a failed program.
+ Add line numbers, so that error messages can be understood.
+ """
+ context.Log("Failed program was:\n")
+ lines = string.split(text, '\n')
+ if len(lines) and lines[-1] == '':
+ lines = lines[:-1] # remove trailing empty line
+ n = 1
+ for line in lines:
+ context.Log("%d: %s\n" % (n, line))
+ n = n + 1
+ context.Log("Error message: %s\n" % msg)
+
+
+ def _suffix2lang(suffix):
+ """
+ Convert a file suffix to a language name.
+ Returns an empty string for a suffix that isn't recognized.
+ """
+ if suffix == ".c":
+ return "C "
+ if suffix == ".cpp":
+ return "C++ "
+ return ""
+
+
+ # vim: set sw=4 et sts=4 tw=79 fo+=l:
*** test/Configure.py.orig Wed Jun 25 22:34:15 2003
--- test/Configure.py Tue Aug 12 16:26:00 2003
***************
*** 93,106 ****
required_stdout = test.wrap_stdout(build_str="scons: `.' is up to date.\n",
read_str=
! """Checking for main(); in library %s (header math.h) ... ok
! Checking for main(); in library None (header math.h) ... ok
! Checking for main in library %s ... ok
! Checking for main in library None ... ok
! Checking for C header math.h ... ok
! Checking for C++ header vector ... ok
""" % (lib, lib))
test.run(stdout = required_stdout)
checkLog(test,'config.log', 0, 0 )
--- 93,107 ----
required_stdout = test.wrap_stdout(build_str="scons: `.' is up to date.\n",
read_str=
! """Checking for main() in C library %s... yes
! Checking for main() in C library None... yes
! Checking for main() in C library %s... yes
! Checking for main() in C library None... yes
! Checking for C header file math.h... yes
! Checking for C++ header file vector... yes
""" % (lib, lib))
+
test.run(stdout = required_stdout)
checkLog(test,'config.log', 0, 0 )
***************
*** 109,116 ****
# 1.2 if checks are not ok, the cache mechanism should work as well
# (via explicit cache)
! reset()
!
test.write( 'SConstruct', """
env = Environment()
--- 110,116 ----
# 1.2 if checks are not ok, the cache mechanism should work as well
# (via explicit cache)
! reset(dot = 0) # match exactly, "()" is a regexp thing
test.write( 'SConstruct', """
env = Environment()
***************
*** 127,136 ****
required_stdout = test.wrap_stdout(build_str="scons: `.' is up to date.\n",
read_str=
! """Checking for C header no_std_c_header.h ... failed
! Checking for main in library no_c_library_SAFFDG ... failed
""")
test.run(stdout = required_stdout)
checkLog(test, 'config.log', 0, 0 )
--- 127,137 ----
required_stdout = test.wrap_stdout(build_str="scons: `.' is up to date.\n",
read_str=
! """Checking for C header file no_std_c_header.h... no
! Checking for main() in C library no_c_library_SAFFDG... no
""")
+
test.run(stdout = required_stdout)
checkLog(test, 'config.log', 0, 0 )
***************
*** 164,174 ****
printf( "Hello\\n" );
}
""")
- test.match_func = TestCmd.match_re_dotall
required_stdout = test.wrap_stdout(build_str='.*',
read_str=
! """Checking for C header math.h ... ok
! Checking for C header no_std_c_header.h ... failed
""")
test.run( stdout = required_stdout )
checkLog( test, 'config.log', 0, 0 )
--- 165,174 ----
printf( "Hello\\n" );
}
""")
required_stdout = test.wrap_stdout(build_str='.*',
read_str=
! """Checking for C header file math.h... yes
! Checking for C header file no_std_c_header.h... no
""")
test.run( stdout = required_stdout )
checkLog( test, 'config.log', 0, 0 )
***************
*** 207,214 ****
""")
required_stdout = test.wrap_stdout(build_str='.*',
read_str=
! """Checking for C header math.h ... ok
! Checking for C header no_std_c_header.h ... failed
""")
test.run( stdout = required_stdout )
checkLog( test, 'build/config.log', 0, 0 )
--- 207,214 ----
""")
required_stdout = test.wrap_stdout(build_str='.*',
read_str=
! """Checking for C header file math.h... yes
! Checking for C header file no_std_c_header.h... no
""")
test.run( stdout = required_stdout )
checkLog( test, 'build/config.log', 0, 0 )
***************
*** 270,277 ****
""")
required_stdout = test.wrap_stdout(build_str='.*',
read_str=
! """Checking for C header math.h ... ok
! Checking for C header no_std_c_header.h ... failed
Executing Custom Test ... ok
""")
# first with SConscriptChdir(0)
--- 270,277 ----
""")
required_stdout = test.wrap_stdout(build_str='.*',
read_str=
! """Checking for C header file math.h... yes
! Checking for C header file no_std_c_header.h... no
Executing Custom Test ... ok
""")
# first with SConscriptChdir(0)
--
hundred-and-one symptoms of being an internet addict:
94. Now admit it... How many of you have made "modem noises" into
the phone just to see if it was possible? :-)
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
\\\ Project leader for A-A-P -- http://www.A-A-P.org ///
\\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01