Clean up set_toolchain_binary
This commit is contained in:
parent
4ab61d591a
commit
d4cf547683
1 changed files with 13 additions and 22 deletions
35
SConstruct
35
SConstruct
|
@ -38,6 +38,7 @@ BUILD_CMDS = False
|
|||
|
||||
import os
|
||||
import os.path
|
||||
import SCons.Errors
|
||||
|
||||
|
||||
def which(program):
|
||||
|
@ -69,30 +70,20 @@ def get_bool_argument(arg):
|
|||
return True
|
||||
|
||||
|
||||
def set_compiler(env, var, user_compiler, compilers, compiler_string=None):
|
||||
if not compiler_string:
|
||||
compiler_string = 'compiler'
|
||||
if user_compiler:
|
||||
if which(user_compiler):
|
||||
env[var] = user_compiler
|
||||
else:
|
||||
raise SCons.Errors.UserError('The given {} does not exist. '
|
||||
':-('.format(compiler_string))
|
||||
else:
|
||||
for c in compilers:
|
||||
if which(c):
|
||||
env[var] = c
|
||||
break
|
||||
else:
|
||||
raise SCons.Errors.UserError(("Couldn't find a viable {}. "
|
||||
"Have you installed one?").format(
|
||||
compiler_string))
|
||||
def set_toolchain_binary(env, var, user_binary, binaries=()):
|
||||
if user_binary and which(user_binary):
|
||||
env[var] = user_binary
|
||||
return
|
||||
for c in binaries:
|
||||
if which(c):
|
||||
env[var] = c
|
||||
break
|
||||
|
||||
common_env = Environment()
|
||||
set_compiler(common_env, 'CC', CC, ('clang', 'gcc'), 'C compiler')
|
||||
set_compiler(common_env, 'CXX', CXX, ('clang++', 'g++'), 'C++ compiler')
|
||||
set_compiler(common_env, 'AS', AS, ('gas'), 'assembler')
|
||||
set_compiler(common_env, 'LINK', LINK, ('ld'), 'linker')
|
||||
set_toolchain_binary(common_env, 'CC', CC, ('clang', 'gcc'))
|
||||
set_toolchain_binary(common_env, 'CXX', CXX, ('clang++', 'g++'))
|
||||
set_toolchain_binary(common_env, 'AS', AS)
|
||||
set_toolchain_binary(common_env, 'LINK', LINK)
|
||||
common_env.Append(CFLAGS='{} -std=c99'.format(CFLAGS))
|
||||
common_env.Append(CXXFLAGS='{} -std=c++11'.format(CFLAGS))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue