[tools] Change the generate cconfig.h code position for fix the 'scons --target=cc' problem.

This commit is contained in:
armink 2018-06-23 10:07:48 +08:00
parent b7f7d6e6b2
commit dbe8e60fcc
1 changed files with 128 additions and 148 deletions

View File

@ -112,37 +112,33 @@ class Win32Spawn:
return proc.wait() return proc.wait()
# auto fix the 'RTT_CC' and 'RTT_EXEC_PATH' # generate cconfig.h file
# when using 'scons --target=cc' the 'RTT_CC' will set to 'cc' def GenCconfigFile(env, BuildOptions):
# it will fix the the 'rtconfig.EXEC_PATH' when get it failed.
# NOTE: this function will changed your env. Please backup the env before used it.
def AutoFixRttCCAndExecPath():
import rtconfig import rtconfig
target_option = None
# get --target=cc option if rtconfig.PLATFORM == 'gcc':
if len(sys.argv) > 1: contents = ''
option = sys.argv[1].split('=') if not os.path.isfile('cconfig.h'):
if len(option) > 1 and option[0] == '--target': import gcc
target_option = option[1] gcc.GenerateGCCConfig(rtconfig)
# force change the 'RTT_CC' when using 'scons --target=cc' # try again
if target_option: if os.path.isfile('cconfig.h'):
if target_option == 'mdk' or target_option == 'mdk4' or target_option == 'mdk5': f = file('cconfig.h', 'r')
os.environ['RTT_CC'] = 'keil' if f:
elif target_option == 'iar': contents = f.read()
os.environ['RTT_CC'] = 'iar' f.close();
# auto change the 'RTT_EXEC_PATH' when 'rtconfig.EXEC_PATH' get failed prep = PatchedPreProcessor()
reload(rtconfig) prep.process_contents(contents)
if not os.path.exists(rtconfig.EXEC_PATH): options = prep.cpp_namespace
if os.environ['RTT_EXEC_PATH']:
# del the 'RTT_EXEC_PATH' and using the 'EXEC_PATH' setting on rtconfig.py BuildOptions.update(options)
del os.environ['RTT_EXEC_PATH']
reload(rtconfig) # add HAVE_CCONFIG_H definition
env.AppendUnique(CPPDEFINES = ['HAVE_CCONFIG_H'])
def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = []): def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = []):
import SCons.cpp
import rtconfig import rtconfig
global BuildOptions global BuildOptions
@ -150,6 +146,64 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
global Env global Env
global Rtt_Root global Rtt_Root
# ===== Add option to SCons =====
AddOption('--copy',
dest = 'copy',
action = 'store_true',
default = False,
help = 'copy rt-thread directory to local.')
AddOption('--copy-header',
dest = 'copy-header',
action = 'store_true',
default = False,
help = 'copy header of rt-thread directory to local.')
AddOption('--dist',
dest = 'make-dist',
action = 'store_true',
default = False,
help = 'make distribution')
AddOption('--cscope',
dest = 'cscope',
action = 'store_true',
default = False,
help = 'Build Cscope cross reference database. Requires cscope installed.')
AddOption('--clang-analyzer',
dest = 'clang-analyzer',
action = 'store_true',
default = False,
help = 'Perform static analyze with Clang-analyzer. ' + \
'Requires Clang installed.\n' + \
'It is recommended to use with scan-build like this:\n' + \
'`scan-build scons --clang-analyzer`\n' + \
'If things goes well, scan-build will instruct you to invoke scan-view.')
AddOption('--buildlib',
dest = 'buildlib',
type = 'string',
help = 'building library of a component')
AddOption('--cleanlib',
dest = 'cleanlib',
action = 'store_true',
default = False,
help = 'clean up the library by --buildlib')
AddOption('--target',
dest = 'target',
type = 'string',
help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk')
AddOption('--genconfig',
dest = 'genconfig',
action = 'store_true',
default = False,
help = 'Generate .config from rtconfig.h')
AddOption('--useconfig',
dest = 'useconfig',
type = 'string',
help = 'make rtconfig.h from config file.')
AddOption('--verbose',
dest = 'verbose',
action = 'store_true',
default = False,
help = 'print verbose information during build')
Env = env Env = env
Rtt_Root = os.path.abspath(root_directory) Rtt_Root = os.path.abspath(root_directory)
# set RTT_ROOT in ENV # set RTT_ROOT in ENV
@ -159,15 +213,53 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
sys.path = sys.path + [os.path.join(Rtt_Root, 'tools')] sys.path = sys.path + [os.path.join(Rtt_Root, 'tools')]
# auto fix the 'RTT_CC' and 'RTT_EXEC_PATH' # {target_name:(CROSS_TOOL, PLATFORM)}
AutoFixRttCCAndExecPath() tgt_dict = {'mdk':('keil', 'armcc'),
'mdk4':('keil', 'armcc'),
'mdk5':('keil', 'armcc'),
'iar':('iar', 'iar'),
'vs':('msvc', 'cl'),
'vs2012':('msvc', 'cl'),
'vsc' : ('gcc', 'gcc'),
'cb':('keil', 'armcc'),
'ua':('gcc', 'gcc'),
'cdk':('gcc', 'gcc')}
tgt_name = GetOption('target')
if tgt_name:
# --target will change the toolchain settings which clang-analyzer is
# depend on
if GetOption('clang-analyzer'):
print '--clang-analyzer cannot be used with --target'
sys.exit(1)
SetOption('no_exec', 1)
try:
rtconfig.CROSS_TOOL, rtconfig.PLATFORM = tgt_dict[tgt_name]
# replace the 'RTT_CC' to 'CROSS_TOOL'
os.environ['RTT_CC'] = rtconfig.CROSS_TOOL
reload(rtconfig)
except KeyError:
print 'Unknow target: %s. Avaible targets: %s' % \
(tgt_name, ', '.join(tgt_dict.keys()))
sys.exit(1)
elif (GetDepend('RT_USING_NEWLIB') == False and GetDepend('RT_USING_NOLIBC') == False) \
and rtconfig.PLATFORM == 'gcc':
AddDepend('RT_USING_MINILIBC')
# auto change the 'RTT_EXEC_PATH' when 'rtconfig.EXEC_PATH' get failed
if not os.path.exists(rtconfig.EXEC_PATH):
if os.environ['RTT_EXEC_PATH']:
# del the 'RTT_EXEC_PATH' and using the 'EXEC_PATH' setting on rtconfig.py
del os.environ['RTT_EXEC_PATH']
reload(rtconfig)
# add compability with Keil MDK 4.6 which changes the directory of armcc.exe # add compability with Keil MDK 4.6 which changes the directory of armcc.exe
if rtconfig.PLATFORM == 'armcc': if rtconfig.PLATFORM == 'armcc':
if not os.path.isfile(os.path.join(rtconfig.EXEC_PATH, 'armcc.exe')): if not os.path.isfile(os.path.join(rtconfig.EXEC_PATH, 'armcc.exe')):
if rtconfig.EXEC_PATH.find('bin40') > 0: if rtconfig.EXEC_PATH.find('bin40') > 0:
rtconfig.EXEC_PATH = rtconfig.EXEC_PATH.replace('bin40', 'armcc/bin') rtconfig.EXEC_PATH = rtconfig.EXEC_PATH.replace('bin40', 'armcc/bin')
Env['LINKFLAGS']=Env['LINKFLAGS'].replace('RV31', 'armcc') Env['LINKFLAGS'] = Env['LINKFLAGS'].replace('RV31', 'armcc')
# reset AR command flags # reset AR command flags
env['ARCOM'] = '$AR --create $TARGET $SOURCES' env['ARCOM'] = '$AR --create $TARGET $SOURCES'
@ -206,62 +298,6 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
PreProcessor.process_contents(contents) PreProcessor.process_contents(contents)
BuildOptions = PreProcessor.cpp_namespace BuildOptions = PreProcessor.cpp_namespace
if rtconfig.PLATFORM == 'gcc':
contents = ''
if not os.path.isfile('cconfig.h'):
import gcc
gcc.GenerateGCCConfig(rtconfig)
# try again
if os.path.isfile('cconfig.h'):
f = file('cconfig.h', 'r')
if f:
contents = f.read()
f.close();
prep = PatchedPreProcessor()
prep.process_contents(contents)
options = prep.cpp_namespace
BuildOptions.update(options)
# add HAVE_CCONFIG_H definition
env.AppendUnique(CPPDEFINES = ['HAVE_CCONFIG_H'])
if str(env['LINKFLAGS']).find('nano.specs') != -1:
env.AppendUnique(CPPDEFINES = ['_REENT_SMALL'])
# add copy option
AddOption('--copy',
dest='copy',
action='store_true',
default=False,
help='copy rt-thread directory to local.')
AddOption('--copy-header',
dest='copy-header',
action='store_true',
default=False,
help='copy header of rt-thread directory to local.')
AddOption('--dist',
dest = 'make-dist',
action = 'store_true',
default=False,
help = 'make distribution')
AddOption('--cscope',
dest='cscope',
action='store_true',
default=False,
help='Build Cscope cross reference database. Requires cscope installed.')
AddOption('--clang-analyzer',
dest='clang-analyzer',
action='store_true',
default=False,
help='Perform static analyze with Clang-analyzer. '+\
'Requires Clang installed.\n'+\
'It is recommended to use with scan-build like this:\n'+\
'`scan-build scons --clang-analyzer`\n'+\
'If things goes well, scan-build will instruct you to invoke scan-view.')
if GetOption('clang-analyzer'): if GetOption('clang-analyzer'):
# perform what scan-build does # perform what scan-build does
env.Replace( env.Replace(
@ -281,59 +317,13 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
# found or something like that). # found or something like that).
rtconfig.POST_ACTION = '' rtconfig.POST_ACTION = ''
# add build library option # generate cconfig.h file
AddOption('--buildlib', GenCconfigFile(env, BuildOptions)
dest='buildlib',
type='string',
help='building library of a component')
AddOption('--cleanlib',
dest='cleanlib',
action='store_true',
default=False,
help='clean up the library by --buildlib')
# add target option # auto append '_REENT_SMALL' when using newlib 'nano.specs' option
AddOption('--target', if rtconfig.PLATFORM == 'gcc' and str(env['LINKFLAGS']).find('nano.specs') != -1:
dest='target', env.AppendUnique(CPPDEFINES = ['_REENT_SMALL'])
type='string',
help='set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk')
#{target_name:(CROSS_TOOL, PLATFORM)}
tgt_dict = {'mdk':('keil', 'armcc'),
'mdk4':('keil', 'armcc'),
'mdk5':('keil', 'armcc'),
'iar':('iar', 'iar'),
'vs':('msvc', 'cl'),
'vs2012':('msvc', 'cl'),
'vsc' : ('gcc', 'gcc'),
'cb':('keil', 'armcc'),
'ua':('gcc', 'gcc'),
'cdk':('gcc', 'gcc')}
tgt_name = GetOption('target')
if tgt_name:
# --target will change the toolchain settings which clang-analyzer is
# depend on
if GetOption('clang-analyzer'):
print '--clang-analyzer cannot be used with --target'
sys.exit(1)
SetOption('no_exec', 1)
try:
rtconfig.CROSS_TOOL, rtconfig.PLATFORM = tgt_dict[tgt_name]
except KeyError:
print 'Unknow target: %s. Avaible targets: %s' % \
(tgt_name, ', '.join(tgt_dict.keys()))
sys.exit(1)
elif (GetDepend('RT_USING_NEWLIB') == False and GetDepend('RT_USING_NOLIBC') == False) \
and rtconfig.PLATFORM == 'gcc':
AddDepend('RT_USING_MINILIBC')
AddOption('--genconfig',
dest = 'genconfig',
action = 'store_true',
default = False,
help = 'Generate .config from rtconfig.h')
if GetOption('genconfig'): if GetOption('genconfig'):
from genconf import genconfig from genconf import genconfig
genconfig() genconfig()
@ -350,22 +340,12 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
menuconfig(Rtt_Root) menuconfig(Rtt_Root)
exit(0) exit(0)
AddOption('--useconfig',
dest = 'useconfig',
type='string',
help = 'make rtconfig.h from config file.')
configfn = GetOption('useconfig') configfn = GetOption('useconfig')
if configfn: if configfn:
from menuconfig import mk_rtconfig from menuconfig import mk_rtconfig
mk_rtconfig(configfn) mk_rtconfig(configfn)
exit(0) exit(0)
# add comstr option
AddOption('--verbose',
dest='verbose',
action='store_true',
default=False,
help='print verbose information during build')
if not GetOption('verbose'): if not GetOption('verbose'):
# override the default verbose command string # override the default verbose command string