[Tools] Add LOCAL_* options for group definition

This commit is contained in:
Bernard Xiong 2015-07-27 10:34:53 +08:00
parent e3c93b3068
commit 0af2be6b5d
1 changed files with 51 additions and 8 deletions

View File

@ -20,6 +20,8 @@
# Change Logs:
# Date Author Notes
# 2015-01-20 Bernard Add copyright information
# 2015-07-25 Bernard Add LOCAL_CCFLAGS/LOCAL_CPPPATH/LOCAL_CPPDEFINES for
# group definition.
#
import os
@ -112,6 +114,8 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
# add program path
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
# add rtconfig.h path
env.Append(CPPPATH = [str(Dir('#').abspath)])
# add library build action
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',
dest='target',
type='string',
help='set target project: mdk/iar/vs/ua')
help='set target project: mdk/mdk4/iar/vs/ua')
#{target_name:(CROSS_TOOL, PLATFORM)}
tgt_dict = {'mdk':('keil', 'armcc'),
@ -333,6 +337,24 @@ def MergeGroup(src_group, group):
src_group['CPPDEFINES'] = src_group['CPPDEFINES'] + group['CPPDEFINES']
else:
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 src_group.has_key('LINKFLAGS'):
src_group['LINKFLAGS'] = src_group['LINKFLAGS'] + group['LINKFLAGS']
@ -371,13 +393,13 @@ def DefineGroup(name, src, depend, **parameters):
group['src'] = src
if group.has_key('CCFLAGS'):
Env.Append(CCFLAGS = group['CCFLAGS'])
Env.AppendUnique(CCFLAGS = group['CCFLAGS'])
if group.has_key('CPPPATH'):
Env.Append(CPPPATH = group['CPPPATH'])
Env.AppendUnique(CPPPATH = group['CPPPATH'])
if group.has_key('CPPDEFINES'):
Env.Append(CPPDEFINES = group['CPPDEFINES'])
Env.AppendUnique(CPPDEFINES = group['CPPDEFINES'])
if group.has_key('LINKFLAGS'):
Env.Append(LINKFLAGS = group['LINKFLAGS'])
Env.AppendUnique(LINKFLAGS = group['LINKFLAGS'])
# check whether to clean up library
if GetOption('cleanlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
@ -394,13 +416,15 @@ def DefineGroup(name, src, depend, **parameters):
else : group['LIBPATH'] = [GetCurrentDir()]
if group.has_key('LIBS'):
Env.Append(LIBS = group['LIBS'])
Env.AppendUnique(LIBS = group['LIBS'])
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'):
objs = Env.Library(name, group['src'])
else:
# only add source
objs = group['src']
# merge group
@ -456,6 +480,26 @@ def BuildLibInstallAction(target, source, env):
break
def DoBuilding(target, 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
# check whether special buildlib option
lib_name = GetOption('buildlib')
@ -500,7 +544,6 @@ def EndBuilding(target, program = None):
else:
print 'No template project file found.'
if GetOption('target') == 'mdk4':
from keil import MDK4Project
MDK4Project('project.uvproj', Projects)