X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=site_scons%2Fsite_tools%2FCustomTests.py;h=e482f800fd033fb639ec5b49506fa31c4b01d1d2;hb=14f43d9587103f6a78e51628785f93f1c14f99a0;hp=81a8eba4c7d5aa4badf6165888c20cad406d5905;hpb=41ac85f6c8a96bdefebdbee4e88193d7f23f50cf;p=senf.git diff --git a/site_scons/site_tools/CustomTests.py b/site_scons/site_tools/CustomTests.py index 81a8eba..e482f80 100644 --- a/site_scons/site_tools/CustomTests.py +++ b/site_scons/site_tools/CustomTests.py @@ -1,5 +1,5 @@ -import SCons.Environment -import SCons.Util, SCons.Script +import SCons.Environment, SCons.Util, SCons.Script, SCons.Conftest +import re # Fix for SCons 0.97 compatibility import SCons.SConf @@ -35,7 +35,7 @@ the decorator. This usage is primarily interesting for tool writers: from CustomTests import ConfTest MY_TESTS = {} - + @ConfTest(MY_TESTS) def CheckMyFoo(context): pass @@ -73,7 +73,7 @@ This usage is interesting for SConstruct and SConscript writers: env = Environment() env.Tool('CustomTests') - + @env.ConfTest() def CheckMyFoo(context): pass @@ -86,7 +86,7 @@ The new configuration test is automatically added to 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 = {} @@ -99,17 +99,63 @@ configuration contexts created from the environment. 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 \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 Fail(context, msg): - SCons.Util.display("scons: *** %s" % msg) - SCons.Script.Exit(1) +def CheckByteorder(context): + context.Message("Checking byteorder... ") + ret = context.TryRun('#include \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 def generate(env): env.Append( CUSTOM_TESTS = DefaultTest.tests )