-import SCons.Environment
-import SCons.Util, SCons.Script
+import SCons.Environment, SCons.Util, SCons.Script, SCons.Conftest
+import re, os.path
# Fix for SCons 0.97 compatibility
import SCons.SConf
from CustomTests import ConfTest
MY_TESTS = {}
-
+
@ConfTest(MY_TESTS)
def CheckMyFoo(context):
pass
env = Environment()
env.Tool('CustomTests')
-
+
@env.ConfTest()
def CheckMyFoo(context):
pass
env['CUSTOM_TESTS'] and is thus automatically available to all
configuration contexts created from the environment.
"""
-
+
def __init__(self, registry=None):
if registry is None:
self.tests = {}
self.tests[func.__name__] = func
return func
-DefaultTest = ConfTest()
-
def Configure(self, *args, **kw):
try: kw['custom_tests'].update(self['CUSTOM_TESTS'])
except KeyError: kw['custom_tests'] = dict(self['CUSTOM_TESTS'])
return self._CustomTests_orig_Configure(*args, **kw)
+def Fail(context, message, condition=True):
+ if condition:
+ SCons.Util.display("scons: *** %s" % message)
+ SCons.Script.Exit(1)
+
+DefaultTest = ConfTest()
+
+@DefaultTest
+def CheckSymbolWithExpression(context, symbol, expression, header="", language="C"):
+ lang, suffix, msg = SCons.Conftest._lang2suffix(language)
+ if msg:
+ context.Message("Cannot check for %s: " % symbol)
+ context.Result(msg)
+ return False
+
+ text = ("#include <assert.h>\n"
+ "%s\n"
+ "int main() {\n"
+ "%s;\n"
+ "return 0;\n"
+ "}\n") % (header, expression)
+
+ context.Message("Checking for %s... " % symbol)
+ ret = context.TryLink(text, suffix)
+ context.Result(ret)
+ if ret:
+ key = symbol.upper()
+ key = re.sub('[^A-Z0-9_]', '_', key)
+ context.sconf.Define("HAVE_%s" % key, 1,
+ "Define to 1 if you have `%s'" % symbol)
+
+ return ret
+
+@DefaultTest
+def CheckByteorder(context):
+ context.Message("Checking byteorder... ")
+ if context.env.has_key("BYTEORDER"):
+ ret = context.env["BYTEORDER"]
+ else:
+ ret = context.TryRun('#include <stdio.h>\n'
+ 'union byteorder_test { int i; char b; };\n'
+ 'int main() {\n'
+ ' union byteorder_test t; t.i=1;\n'
+ ' printf(t.b ? "little\\n" : "big\\n");\n'
+ ' return 0;\n'
+ '}\n',
+ ".c")[-1].strip()
+ if not ret:
+ context.Result("failed")
+ return False
+ else:
+ context.Result(ret+"-endian")
+ context.sconf.Define("BYTEORDER_%s_ENDIAN" % ret.upper(), 1,
+ "Define BYTEORDER_LITTLE_ENDIAN or BYTEORDER_BIG_ENDIAN")
+ return ret
+
@DefaultTest
-def Fail(context, msg):
- SCons.Util.display("scons: *** %s" % msg)
- SCons.Script.Exit(1)
+def FindCHeader(context, name, dirs):
+ defn = name.upper()
+ defn = re.sub('[^A-Z0-9_]', '_', defn)
+ defn += "_PATH"
+
+ context.Message("Checking for %s... " % name)
+ for dir in dirs:
+ path = os.path.join(dir, name);
+ ret = context.TryCompile("#include <%s>" % path, ".c");
+ if ret:
+ context.Result(path)
+ context.sconf.Define(defn, "<%s>" % path,
+ "Define %s as <path/to/%s>" % (defn, name))
+ return ret
+ return False
def generate(env):
env.Append( CUSTOM_TESTS = DefaultTest.tests )