mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-11-16 12:34:33 +00:00
[Tools] merge v2.1.0 LOCAL_CPPPATH feature to v2.0.x branch
This commit is contained in:
@@ -20,6 +20,8 @@
|
|||||||
# Change Logs:
|
# Change Logs:
|
||||||
# Date Author Notes
|
# Date Author Notes
|
||||||
# 2015-01-20 Bernard Add copyright information
|
# 2015-01-20 Bernard Add copyright information
|
||||||
|
# 2015-07-25 Bernard Add LOCAL_CCFLAGS/LOCAL_CPPPATH/LOCAL_CPPDEFINES for
|
||||||
|
# group definition.
|
||||||
#
|
#
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@@ -112,6 +114,8 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
|||||||
|
|
||||||
# add program path
|
# add program path
|
||||||
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
|
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
|
||||||
|
# add rtconfig.h path
|
||||||
|
env.Append(CPPPATH = [str(Dir('#').abspath)])
|
||||||
|
|
||||||
# add library build action
|
# add library build action
|
||||||
act = SCons.Action.Action(BuildLibInstallAction, 'Install compiled library... $TARGET')
|
act = SCons.Action.Action(BuildLibInstallAction, 'Install compiled library... $TARGET')
|
||||||
@@ -186,7 +190,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
|||||||
AddOption('--target',
|
AddOption('--target',
|
||||||
dest='target',
|
dest='target',
|
||||||
type='string',
|
type='string',
|
||||||
help='set target project: mdk/iar/vs/ua')
|
help='set target project: mdk/mdk4/iar/vs/ua')
|
||||||
|
|
||||||
#{target_name:(CROSS_TOOL, PLATFORM)}
|
#{target_name:(CROSS_TOOL, PLATFORM)}
|
||||||
tgt_dict = {'mdk':('keil', 'armcc'),
|
tgt_dict = {'mdk':('keil', 'armcc'),
|
||||||
@@ -196,7 +200,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
|||||||
'vs':('msvc', 'cl'),
|
'vs':('msvc', 'cl'),
|
||||||
'vs2012':('msvc', 'cl'),
|
'vs2012':('msvc', 'cl'),
|
||||||
'cb':('keil', 'armcc'),
|
'cb':('keil', 'armcc'),
|
||||||
'ua':('keil', 'armcc')}
|
'ua':('gcc', 'gcc')}
|
||||||
tgt_name = GetOption('target')
|
tgt_name = GetOption('target')
|
||||||
if tgt_name:
|
if tgt_name:
|
||||||
# --target will change the toolchain settings which clang-analyzer is
|
# --target will change the toolchain settings which clang-analyzer is
|
||||||
@@ -256,15 +260,24 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
|
|||||||
|
|
||||||
return objs
|
return objs
|
||||||
|
|
||||||
def PrepareModuleBuilding(env, root_directory):
|
def PrepareModuleBuilding(env, root_directory, bsp_directory):
|
||||||
import rtconfig
|
import rtconfig
|
||||||
|
|
||||||
|
global BuildOptions
|
||||||
global Env
|
global Env
|
||||||
global Rtt_Root
|
global Rtt_Root
|
||||||
|
|
||||||
Env = env
|
Env = env
|
||||||
Rtt_Root = root_directory
|
Rtt_Root = root_directory
|
||||||
|
|
||||||
|
# parse bsp rtconfig.h to get used component
|
||||||
|
PreProcessor = SCons.cpp.PreProcessor()
|
||||||
|
f = file(bsp_directory + '/rtconfig.h', 'r')
|
||||||
|
contents = f.read()
|
||||||
|
f.close()
|
||||||
|
PreProcessor.process_contents(contents)
|
||||||
|
BuildOptions = PreProcessor.cpp_namespace
|
||||||
|
|
||||||
# add build/clean library option for library checking
|
# add build/clean library option for library checking
|
||||||
AddOption('--buildlib',
|
AddOption('--buildlib',
|
||||||
dest='buildlib',
|
dest='buildlib',
|
||||||
@@ -324,6 +337,24 @@ def MergeGroup(src_group, group):
|
|||||||
src_group['CPPDEFINES'] = src_group['CPPDEFINES'] + group['CPPDEFINES']
|
src_group['CPPDEFINES'] = src_group['CPPDEFINES'] + group['CPPDEFINES']
|
||||||
else:
|
else:
|
||||||
src_group['CPPDEFINES'] = group['CPPDEFINES']
|
src_group['CPPDEFINES'] = group['CPPDEFINES']
|
||||||
|
|
||||||
|
# for local CCFLAGS/CPPPATH/CPPDEFINES
|
||||||
|
if group.has_key('LOCAL_CCFLAGS'):
|
||||||
|
if src_group.has_key('LOCAL_CCFLAGS'):
|
||||||
|
src_group['LOCAL_CCFLAGS'] = src_group['LOCAL_CCFLAGS'] + group['LOCAL_CCFLAGS']
|
||||||
|
else:
|
||||||
|
src_group['LOCAL_CCFLAGS'] = group['LOCAL_CCFLAGS']
|
||||||
|
if group.has_key('LOCAL_CPPPATH'):
|
||||||
|
if src_group.has_key('LOCAL_CPPPATH'):
|
||||||
|
src_group['LOCAL_CPPPATH'] = src_group['LOCAL_CPPPATH'] + group['LOCAL_CPPPATH']
|
||||||
|
else:
|
||||||
|
src_group['LOCAL_CPPPATH'] = group['LOCAL_CPPPATH']
|
||||||
|
if group.has_key('LOCAL_CPPDEFINES'):
|
||||||
|
if src_group.has_key('LOCAL_CPPDEFINES'):
|
||||||
|
src_group['LOCAL_CPPDEFINES'] = src_group['LOCAL_CPPDEFINES'] + group['LOCAL_CPPDEFINES']
|
||||||
|
else:
|
||||||
|
src_group['LOCAL_CPPDEFINES'] = group['LOCAL_CPPDEFINES']
|
||||||
|
|
||||||
if group.has_key('LINKFLAGS'):
|
if group.has_key('LINKFLAGS'):
|
||||||
if src_group.has_key('LINKFLAGS'):
|
if src_group.has_key('LINKFLAGS'):
|
||||||
src_group['LINKFLAGS'] = src_group['LINKFLAGS'] + group['LINKFLAGS']
|
src_group['LINKFLAGS'] = src_group['LINKFLAGS'] + group['LINKFLAGS']
|
||||||
@@ -362,13 +393,13 @@ def DefineGroup(name, src, depend, **parameters):
|
|||||||
group['src'] = src
|
group['src'] = src
|
||||||
|
|
||||||
if group.has_key('CCFLAGS'):
|
if group.has_key('CCFLAGS'):
|
||||||
Env.Append(CCFLAGS = group['CCFLAGS'])
|
Env.AppendUnique(CCFLAGS = group['CCFLAGS'])
|
||||||
if group.has_key('CPPPATH'):
|
if group.has_key('CPPPATH'):
|
||||||
Env.Append(CPPPATH = group['CPPPATH'])
|
Env.AppendUnique(CPPPATH = group['CPPPATH'])
|
||||||
if group.has_key('CPPDEFINES'):
|
if group.has_key('CPPDEFINES'):
|
||||||
Env.Append(CPPDEFINES = group['CPPDEFINES'])
|
Env.AppendUnique(CPPDEFINES = group['CPPDEFINES'])
|
||||||
if group.has_key('LINKFLAGS'):
|
if group.has_key('LINKFLAGS'):
|
||||||
Env.Append(LINKFLAGS = group['LINKFLAGS'])
|
Env.AppendUnique(LINKFLAGS = group['LINKFLAGS'])
|
||||||
|
|
||||||
# check whether to clean up library
|
# check whether to clean up library
|
||||||
if GetOption('cleanlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
|
if GetOption('cleanlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
|
||||||
@@ -385,13 +416,15 @@ def DefineGroup(name, src, depend, **parameters):
|
|||||||
else : group['LIBPATH'] = [GetCurrentDir()]
|
else : group['LIBPATH'] = [GetCurrentDir()]
|
||||||
|
|
||||||
if group.has_key('LIBS'):
|
if group.has_key('LIBS'):
|
||||||
Env.Append(LIBS = group['LIBS'])
|
Env.AppendUnique(LIBS = group['LIBS'])
|
||||||
if group.has_key('LIBPATH'):
|
if group.has_key('LIBPATH'):
|
||||||
Env.Append(LIBPATH = group['LIBPATH'])
|
Env.AppendUnique(LIBPATH = group['LIBPATH'])
|
||||||
|
|
||||||
|
# check whether to build group library
|
||||||
if group.has_key('LIBRARY'):
|
if group.has_key('LIBRARY'):
|
||||||
objs = Env.Library(name, group['src'])
|
objs = Env.Library(name, group['src'])
|
||||||
else:
|
else:
|
||||||
|
# only add source
|
||||||
objs = group['src']
|
objs = group['src']
|
||||||
|
|
||||||
# merge group
|
# merge group
|
||||||
@@ -447,6 +480,39 @@ def BuildLibInstallAction(target, source, env):
|
|||||||
break
|
break
|
||||||
|
|
||||||
def DoBuilding(target, objects):
|
def DoBuilding(target, objects):
|
||||||
|
|
||||||
|
# merge all objects into one list
|
||||||
|
def one_list(l):
|
||||||
|
lst = []
|
||||||
|
for item in l:
|
||||||
|
if type(item) == type([]):
|
||||||
|
lst += one_list(item)
|
||||||
|
else:
|
||||||
|
lst.append(item)
|
||||||
|
return lst
|
||||||
|
|
||||||
|
objects = one_list(objects)
|
||||||
|
|
||||||
|
# remove source files with local flags setting
|
||||||
|
for group in Projects:
|
||||||
|
if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'):
|
||||||
|
for source in group['src']:
|
||||||
|
for obj in objects:
|
||||||
|
if source.abspath == obj.abspath or (len(obj.sources) > 0 and source.abspath == obj.sources[0].abspath):
|
||||||
|
objects.remove(obj)
|
||||||
|
|
||||||
|
# re-add the source files to the objects
|
||||||
|
for group in Projects:
|
||||||
|
if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'):
|
||||||
|
CCFLAGS = Env.get('CCFLAGS', '') + group.get('LOCAL_CCFLAGS', '')
|
||||||
|
CPPPATH = Env.get('CPPPATH', ['']) + group.get('LOCAL_CPPPATH', [''])
|
||||||
|
CPPDEFINES = Env.get('CPPDEFINES', ['']) + group.get('LOCAL_CPPDEFINES', [''])
|
||||||
|
|
||||||
|
for source in group['src']:
|
||||||
|
objects += Env.Object(source, CCFLAGS = CCFLAGS,
|
||||||
|
CPPPATH = CPPPATH,
|
||||||
|
CPPDEFINES = CPPDEFINES)
|
||||||
|
|
||||||
program = None
|
program = None
|
||||||
# check whether special buildlib option
|
# check whether special buildlib option
|
||||||
lib_name = GetOption('buildlib')
|
lib_name = GetOption('buildlib')
|
||||||
@@ -586,6 +652,11 @@ def GlobSubDir(sub_dir, ext_name):
|
|||||||
dst.append(os.path.relpath(item, sub_dir))
|
dst.append(os.path.relpath(item, sub_dir))
|
||||||
return dst
|
return dst
|
||||||
|
|
||||||
|
def PackageSConscript(package):
|
||||||
|
from package import BuildPackage
|
||||||
|
|
||||||
|
return BuildPackage(package)
|
||||||
|
|
||||||
def file_path_exist(path, *args):
|
def file_path_exist(path, *args):
|
||||||
return os.path.exists(os.path.join(path, *args))
|
return os.path.exists(os.path.join(path, *args))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user