From 743049957142e69086c7dd517a27684a7c37ef30 Mon Sep 17 00:00:00 2001 From: kichik Date: Tue, 14 Mar 2006 17:52:38 +0000 Subject: [PATCH] added FlagsConfigure for compiler and linker flags configuration git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4586 212acab6-be3b-0410-9dea-997c60f758d6 --- SCons/utils.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/SCons/utils.py b/SCons/utils.py index 926d3fe4..302f9594 100644 --- a/SCons/utils.py +++ b/SCons/utils.py @@ -10,4 +10,58 @@ def AddAvailableLibs(env, libs): conf.Finish() -Export('AddAvailableLibs') +""" +Checks if a compiler flag is valid. +""" +def check_compile_flag(ctx, flag): + ctx.Message('Checking for compiler flag %s... ' % flag) + + old_flags = ctx.env['CCFLAGS'] + ctx.env.Append(CCFLAGS = flag) + + test = """ + int __main() { + return 0; + } + """ + + result = not ctx.TryCompile(test, '.c') + ctx.Result(result) + + if not result: + ctx.env.Replace(CCFLAGS = old_flags) + + return result + +""" +Checks if a linker flag is valid. +""" +def check_link_flag(ctx, flag): + ctx.Message('Checking for linker flag %s... ' % flag) + + old_flags = ctx.env['LINKFLAGS'] + ctx.env.Append(LINKFLAGS = flag) + + test = """ + int __main() { + return 0; + } + """ + + result = not ctx.TryLink(test, '.c') + ctx.Result(result) + + if not result: + ctx.env.Replace(LINKFLAGS = old_flags) + + return result + +""" +Wrapper for env.Configure which adds two new tests: + CheckCompileFlag - checks for a compiler flag + CheckLinkFlag - checks for a linker flag +""" +def FlagsConfigure(env): + return env.Configure(custom_tests = { 'CheckCompileFlag' : check_compile_flag, 'CheckLinkFlag': check_link_flag }) + +Export('AddAvailableLibs FlagsConfigure')