2005-09-24 15:48:59 +00:00
|
|
|
def AddAvailableLibs(env, libs):
|
2009-01-10 22:53:35 +00:00
|
|
|
"""
|
|
|
|
Scans through a list list of libraries and adds
|
|
|
|
available libraries to the environment.
|
|
|
|
"""
|
2005-09-24 15:48:59 +00:00
|
|
|
conf = env.Configure()
|
|
|
|
|
|
|
|
for lib in libs:
|
|
|
|
conf.CheckLib(lib)
|
|
|
|
|
|
|
|
conf.Finish()
|
|
|
|
|
2009-01-10 22:51:43 +00:00
|
|
|
def GetAvailableLibs(env, libs):
|
2009-01-10 22:53:35 +00:00
|
|
|
"""
|
|
|
|
Scans through a list list of libraries and adds
|
|
|
|
available libraries to the environment.
|
|
|
|
"""
|
2009-01-10 22:51:43 +00:00
|
|
|
conf = env.Configure()
|
|
|
|
avail_libs = []
|
|
|
|
|
|
|
|
for lib in libs:
|
|
|
|
if conf.CheckLib(lib):
|
|
|
|
avail_libs.append(lib)
|
|
|
|
|
|
|
|
conf.Finish()
|
|
|
|
|
|
|
|
return avail_libs
|
|
|
|
|
2006-03-14 17:52:38 +00:00
|
|
|
def check_compile_flag(ctx, flag):
|
2009-01-10 22:53:35 +00:00
|
|
|
"""
|
|
|
|
Checks if a compiler flag is valid.
|
|
|
|
"""
|
2006-03-14 17:52:38 +00:00
|
|
|
ctx.Message('Checking for compiler flag %s... ' % flag)
|
|
|
|
|
|
|
|
old_flags = ctx.env['CCFLAGS']
|
2008-11-15 21:54:24 +00:00
|
|
|
ctx.env.Append(CCFLAGS = [flag])
|
2006-03-14 17:52:38 +00:00
|
|
|
|
|
|
|
test = """
|
2006-03-14 18:21:12 +00:00
|
|
|
int main() {
|
2006-03-14 17:52:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2006-03-14 18:03:43 +00:00
|
|
|
result = ctx.TryCompile(test, '.c')
|
2006-03-14 17:52:38 +00:00
|
|
|
ctx.Result(result)
|
|
|
|
|
|
|
|
if not result:
|
2008-11-15 21:54:24 +00:00
|
|
|
ctx.env.Replace(CCFLAGS = [old_flags])
|
2006-03-14 17:52:38 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
|
2006-04-28 15:54:42 +00:00
|
|
|
def check_link_flag(ctx, flag, run = 0, extension = '.c', code = None):
|
2009-01-10 22:53:35 +00:00
|
|
|
"""
|
|
|
|
Checks if a linker flag is valid.
|
|
|
|
"""
|
2006-03-14 17:52:38 +00:00
|
|
|
ctx.Message('Checking for linker flag %s... ' % flag)
|
|
|
|
|
|
|
|
old_flags = ctx.env['LINKFLAGS']
|
2008-11-15 21:54:24 +00:00
|
|
|
ctx.env.Append(LINKFLAGS = [flag])
|
2006-03-14 17:52:38 +00:00
|
|
|
|
2006-04-28 15:54:42 +00:00
|
|
|
if code:
|
|
|
|
test = code
|
|
|
|
else:
|
|
|
|
test = """
|
|
|
|
int main() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
result = ctx.TryLink(test, extension)
|
|
|
|
|
|
|
|
if run:
|
|
|
|
result = result and ctx.TryRun(test, extension)[0]
|
2006-03-14 17:52:38 +00:00
|
|
|
|
|
|
|
ctx.Result(result)
|
|
|
|
|
|
|
|
if not result:
|
2008-11-15 21:54:24 +00:00
|
|
|
ctx.env.Replace(LINKFLAGS = [old_flags])
|
2006-03-14 17:52:38 +00:00
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
def FlagsConfigure(env):
|
2009-01-10 22:53:35 +00:00
|
|
|
"""
|
|
|
|
Wrapper for env.Configure which adds two new tests:
|
|
|
|
CheckCompileFlag - checks for a compiler flag
|
|
|
|
CheckLinkFlag - checks for a linker flag
|
|
|
|
"""
|
2006-03-14 17:52:38 +00:00
|
|
|
return env.Configure(custom_tests = { 'CheckCompileFlag' : check_compile_flag, 'CheckLinkFlag': check_link_flag })
|
|
|
|
|
2009-01-10 22:51:43 +00:00
|
|
|
Export('AddAvailableLibs FlagsConfigure GetAvailableLibs')
|