提交 819fd97f 编写于 作者: G goprife@gmail.com

add source remove method

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1816 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 b38a9757
import os import os
import sys import sys
import string import string
import xml.etree.ElementTree as etree import xml.etree.ElementTree as etree
from xml.etree.ElementTree import SubElement from xml.etree.ElementTree import SubElement
from SCons.Script import * from SCons.Script import *
BuildOptions = {} BuildOptions = {}
Projects = [] Projects = []
Rtt_Root = '' Rtt_Root = ''
Env = None Env = None
fs_encoding = sys.getfilesystemencoding() fs_encoding = sys.getfilesystemencoding()
def _get_filetype(fn): def _get_filetype(fn):
if fn.rfind('.c') != -1 or fn.rfind('.C') != -1 or fn.rfind('.cpp') != -1: if fn.rfind('.c') != -1 or fn.rfind('.C') != -1 or fn.rfind('.cpp') != -1:
return 1 return 1
# assimble file type # assimble file type
if fn.rfind('.s') != -1 or fn.rfind('.S') != -1: if fn.rfind('.s') != -1 or fn.rfind('.S') != -1:
return 2 return 2
# header type # header type
if fn.rfind('.h') != -1: if fn.rfind('.h') != -1:
return 5 return 5
# other filetype # other filetype
return 5 return 5
def splitall(loc): def splitall(loc):
""" """
Return a list of the path components in loc. (Used by relpath_). Return a list of the path components in loc. (Used by relpath_).
The first item in the list will be either ``os.curdir``, ``os.pardir``, empty, The first item in the list will be either ``os.curdir``, ``os.pardir``, empty,
or the root directory of loc (for example, ``/`` or ``C:\\). or the root directory of loc (for example, ``/`` or ``C:\\).
The other items in the list will be strings. The other items in the list will be strings.
Adapted from *path.py* by Jason Orendorff. Adapted from *path.py* by Jason Orendorff.
""" """
parts = [] parts = []
while loc != os.curdir and loc != os.pardir: while loc != os.curdir and loc != os.pardir:
prev = loc prev = loc
loc, child = os.path.split(prev) loc, child = os.path.split(prev)
if loc == prev: if loc == prev:
break break
parts.append(child) parts.append(child)
parts.append(loc) parts.append(loc)
parts.reverse() parts.reverse()
return parts return parts
def _make_path_relative(origin, dest): def _make_path_relative(origin, dest):
""" """
Return the relative path between origin and dest. Return the relative path between origin and dest.
If it's not possible return dest. If it's not possible return dest.
If they are identical return ``os.curdir`` If they are identical return ``os.curdir``
Adapted from `path.py <http://www.jorendorff.com/articles/python/path/>`_ by Jason Orendorff. Adapted from `path.py <http://www.jorendorff.com/articles/python/path/>`_ by Jason Orendorff.
""" """
origin = os.path.abspath(origin).replace('\\', '/') origin = os.path.abspath(origin).replace('\\', '/')
dest = os.path.abspath(dest).replace('\\', '/') dest = os.path.abspath(dest).replace('\\', '/')
# #
orig_list = splitall(os.path.normcase(origin)) orig_list = splitall(os.path.normcase(origin))
# Don't normcase dest! We want to preserve the case. # Don't normcase dest! We want to preserve the case.
dest_list = splitall(dest) dest_list = splitall(dest)
# #
if orig_list[0] != os.path.normcase(dest_list[0]): if orig_list[0] != os.path.normcase(dest_list[0]):
# Can't get here from there. # Can't get here from there.
return dest return dest
# #
# Find the location where the two paths start to differ. # Find the location where the two paths start to differ.
i = 0 i = 0
for start_seg, dest_seg in zip(orig_list, dest_list): for start_seg, dest_seg in zip(orig_list, dest_list):
if start_seg != os.path.normcase(dest_seg): if start_seg != os.path.normcase(dest_seg):
break break
i += 1 i += 1
# #
# Now i is the point where the two paths diverge. # Now i is the point where the two paths diverge.
# Need a certain number of "os.pardir"s to work up # Need a certain number of "os.pardir"s to work up
# from the origin to the point of divergence. # from the origin to the point of divergence.
segments = [os.pardir] * (len(orig_list) - i) segments = [os.pardir] * (len(orig_list) - i)
# Need to add the diverging part of dest_list. # Need to add the diverging part of dest_list.
segments += dest_list[i:] segments += dest_list[i:]
if len(segments) == 0: if len(segments) == 0:
# If they happen to be identical, use os.curdir. # If they happen to be identical, use os.curdir.
return os.curdir return os.curdir
else: else:
# return os.path.join(*segments).replace('\\', '/') # return os.path.join(*segments).replace('\\', '/')
return os.path.join(*segments) return os.path.join(*segments)
def xml_indent(elem, level=0): def xml_indent(elem, level=0):
i = "\n" + level*" " i = "\n" + level*" "
if len(elem): if len(elem):
if not elem.text or not elem.text.strip(): if not elem.text or not elem.text.strip():
elem.text = i + " " elem.text = i + " "
if not elem.tail or not elem.tail.strip(): if not elem.tail or not elem.tail.strip():
elem.tail = i elem.tail = i
for elem in elem: for elem in elem:
xml_indent(elem, level+1) xml_indent(elem, level+1)
if not elem.tail or not elem.tail.strip(): if not elem.tail or not elem.tail.strip():
elem.tail = i elem.tail = i
else: else:
if level and (not elem.tail or not elem.tail.strip()): if level and (not elem.tail or not elem.tail.strip()):
elem.tail = i elem.tail = i
def IARAddGroup(parent, name, files, project_path): def IARAddGroup(parent, name, files, project_path):
group = SubElement(parent, 'group') group = SubElement(parent, 'group')
group_name = SubElement(group, 'name') group_name = SubElement(group, 'name')
group_name.text = name group_name.text = name
for f in files: for f in files:
fn = f.rfile() fn = f.rfile()
name = fn.name name = fn.name
path = os.path.dirname(fn.abspath) path = os.path.dirname(fn.abspath)
basename = os.path.basename(path) basename = os.path.basename(path)
path = _make_path_relative(project_path, path) path = _make_path_relative(project_path, path)
path = os.path.join(path, name) path = os.path.join(path, name)
file = SubElement(group, 'file') file = SubElement(group, 'file')
file_name = SubElement(file, 'name') file_name = SubElement(file, 'name')
file_name.text = ('$PROJ_DIR$\\' + path).decode(fs_encoding) file_name.text = ('$PROJ_DIR$\\' + path).decode(fs_encoding)
iar_workspace = '''<?xml version="1.0" encoding="iso-8859-1"?> iar_workspace = '''<?xml version="1.0" encoding="iso-8859-1"?>
<workspace> <workspace>
<project> <project>
<path>$WS_DIR$\%s</path> <path>$WS_DIR$\%s</path>
</project> </project>
<batchBuild/> <batchBuild/>
</workspace> </workspace>
''' '''
def IARWorkspace(target): def IARWorkspace(target):
# make an workspace # make an workspace
workspace = target.replace('.ewp', '.eww') workspace = target.replace('.ewp', '.eww')
out = file(workspace, 'wb') out = file(workspace, 'wb')
xml = iar_workspace % target xml = iar_workspace % target
out.write(xml) out.write(xml)
out.close() out.close()
def IARProject(target, script): def IARProject(target, script):
project_path = os.path.dirname(os.path.abspath(target)) project_path = os.path.dirname(os.path.abspath(target))
tree = etree.parse('template.ewp') tree = etree.parse('template.ewp')
root = tree.getroot() root = tree.getroot()
out = file(target, 'wb') out = file(target, 'wb')
CPPPATH = [] CPPPATH = []
CPPDEFINES = [] CPPDEFINES = []
LINKFLAGS = '' LINKFLAGS = ''
CCFLAGS = '' CCFLAGS = ''
# add group # add group
for group in script: for group in script:
IARAddGroup(root, group['name'], group['src'], project_path) IARAddGroup(root, group['name'], group['src'], project_path)
# get each include path # get each include path
if group.has_key('CPPPATH') and group['CPPPATH']: if group.has_key('CPPPATH') and group['CPPPATH']:
CPPPATH += group['CPPPATH'] CPPPATH += group['CPPPATH']
# get each group's definitions # get each group's definitions
if group.has_key('CPPDEFINES') and group['CPPDEFINES']: if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
CPPDEFINES += group['CPPDEFINES'] CPPDEFINES += group['CPPDEFINES']
# get each group's link flags # get each group's link flags
if group.has_key('LINKFLAGS') and group['LINKFLAGS']: if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
LINKFLAGS += group['LINKFLAGS'] LINKFLAGS += group['LINKFLAGS']
# make relative path # make relative path
paths = set() paths = set()
for path in CPPPATH: for path in CPPPATH:
inc = _make_path_relative(project_path, os.path.normpath(path)) inc = _make_path_relative(project_path, os.path.normpath(path))
paths.add(inc) #.replace('\\', '/') paths.add(inc) #.replace('\\', '/')
# setting options # setting options
options = tree.findall('configuration/settings/data/option') options = tree.findall('configuration/settings/data/option')
for option in options: for option in options:
# print option.text # print option.text
name = option.find('name') name = option.find('name')
if name.text == 'CCIncludePath2': if name.text == 'CCIncludePath2':
for path in paths: for path in paths:
state = SubElement(option, 'state') state = SubElement(option, 'state')
state.text = '$PROJ_DIR$\\' + path state.text = '$PROJ_DIR$\\' + path
if name.text == 'CCDefines': if name.text == 'CCDefines':
for define in CPPDEFINES: for define in CPPDEFINES:
state = SubElement(option, 'state') state = SubElement(option, 'state')
state.text = define state.text = define
xml_indent(root) xml_indent(root)
out.write(etree.tostring(root, encoding='utf-8')) out.write(etree.tostring(root, encoding='utf-8'))
out.close() out.close()
IARWorkspace(target) IARWorkspace(target)
def MDK4AddGroup(ProjectFiles, parent, name, files, project_path): def MDK4AddGroup(ProjectFiles, parent, name, files, project_path):
group = SubElement(parent, 'Group') group = SubElement(parent, 'Group')
group_name = SubElement(group, 'GroupName') group_name = SubElement(group, 'GroupName')
group_name.text = name group_name.text = name
for f in files: for f in files:
fn = f.rfile() fn = f.rfile()
name = fn.name name = fn.name
path = os.path.dirname(fn.abspath) path = os.path.dirname(fn.abspath)
basename = os.path.basename(path) basename = os.path.basename(path)
path = _make_path_relative(project_path, path) path = _make_path_relative(project_path, path)
path = os.path.join(path, name) path = os.path.join(path, name)
files = SubElement(group, 'Files') files = SubElement(group, 'Files')
file = SubElement(files, 'File') file = SubElement(files, 'File')
file_name = SubElement(file, 'FileName') file_name = SubElement(file, 'FileName')
name = os.path.basename(path) name = os.path.basename(path)
if ProjectFiles.count(name): if ProjectFiles.count(name):
name = basename + '_' + name name = basename + '_' + name
ProjectFiles.append(name) ProjectFiles.append(name)
file_name.text = name.decode(fs_encoding) file_name.text = name.decode(fs_encoding)
file_type = SubElement(file, 'FileType') file_type = SubElement(file, 'FileType')
file_type.text = '%d' % _get_filetype(name) file_type.text = '%d' % _get_filetype(name)
file_path = SubElement(file, 'FilePath') file_path = SubElement(file, 'FilePath')
file_path.text = path.decode(fs_encoding) file_path.text = path.decode(fs_encoding)
def MDK4Project(target, script): def MDK4Project(target, script):
project_path = os.path.dirname(os.path.abspath(target)) project_path = os.path.dirname(os.path.abspath(target))
tree = etree.parse('template.uvproj') tree = etree.parse('template.uvproj')
root = tree.getroot() root = tree.getroot()
out = file(target, 'wb') out = file(target, 'wb')
out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n') out.write('<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n')
CPPPATH = [] CPPPATH = []
CPPDEFINES = [] CPPDEFINES = []
LINKFLAGS = '' LINKFLAGS = ''
CCFLAGS = '' CCFLAGS = ''
ProjectFiles = [] ProjectFiles = []
# add group # add group
groups = tree.find('Targets/Target/Groups') groups = tree.find('Targets/Target/Groups')
if not groups: if not groups:
groups = SubElement(tree.find('Targets/Target'), 'Groups') groups = SubElement(tree.find('Targets/Target'), 'Groups')
for group in script: for group in script:
group_xml = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path) group_xml = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path)
# get each include path # get each include path
if group.has_key('CPPPATH') and group['CPPPATH']: if group.has_key('CPPPATH') and group['CPPPATH']:
if CPPPATH: if CPPPATH:
CPPPATH += group['CPPPATH'] CPPPATH += group['CPPPATH']
else: else:
CPPPATH += group['CPPPATH'] CPPPATH += group['CPPPATH']
# get each group's definitions # get each group's definitions
if group.has_key('CPPDEFINES') and group['CPPDEFINES']: if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
if CPPDEFINES: if CPPDEFINES:
CPPDEFINES += ';' + group['CPPDEFINES'] CPPDEFINES += ';' + group['CPPDEFINES']
else: else:
CPPDEFINES += group['CPPDEFINES'] CPPDEFINES += group['CPPDEFINES']
# get each group's link flags # get each group's link flags
if group.has_key('LINKFLAGS') and group['LINKFLAGS']: if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
if LINKFLAGS: if LINKFLAGS:
LINKFLAGS += ' ' + group['LINKFLAGS'] LINKFLAGS += ' ' + group['LINKFLAGS']
else: else:
LINKFLAGS += group['LINKFLAGS'] LINKFLAGS += group['LINKFLAGS']
# remove repeat path # remove repeat path
paths = set() paths = set()
for path in CPPPATH: for path in CPPPATH:
inc = _make_path_relative(project_path, os.path.normpath(path)) inc = _make_path_relative(project_path, os.path.normpath(path))
paths.add(inc) #.replace('\\', '/') paths.add(inc) #.replace('\\', '/')
paths = [i for i in paths] paths = [i for i in paths]
CPPPATH = string.join(paths, ';') CPPPATH = string.join(paths, ';')
definitions = [i for i in set(CPPDEFINES)] definitions = [i for i in set(CPPDEFINES)]
CPPDEFINES = string.join(definitions, ', ') CPPDEFINES = string.join(definitions, ', ')
# write include path, definitions and link flags # write include path, definitions and link flags
IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath') IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath')
IncludePath.text = CPPPATH IncludePath.text = CPPPATH
Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define') Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define')
Define.text = CPPDEFINES Define.text = CPPDEFINES
Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc') Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc')
Misc.text = LINKFLAGS Misc.text = LINKFLAGS
xml_indent(root) xml_indent(root)
out.write(etree.tostring(root, encoding='utf-8')) out.write(etree.tostring(root, encoding='utf-8'))
out.close() out.close()
def MDKProject(target, script): def MDKProject(target, script):
template = file('template.Uv2', "rb") template = file('template.Uv2', "rb")
lines = template.readlines() lines = template.readlines()
project = file(target, "wb") project = file(target, "wb")
project_path = os.path.dirname(os.path.abspath(target)) project_path = os.path.dirname(os.path.abspath(target))
line_index = 5 line_index = 5
# write group # write group
for group in script: for group in script:
lines.insert(line_index, 'Group (%s)\r\n' % group['name']) lines.insert(line_index, 'Group (%s)\r\n' % group['name'])
line_index += 1 line_index += 1
lines.insert(line_index, '\r\n') lines.insert(line_index, '\r\n')
line_index += 1 line_index += 1
# write file # write file
ProjectFiles = [] ProjectFiles = []
CPPPATH = [] CPPPATH = []
CPPDEFINES = [] CPPDEFINES = []
LINKFLAGS = '' LINKFLAGS = ''
CCFLAGS = '' CCFLAGS = ''
# number of groups # number of groups
group_index = 1 group_index = 1
for group in script: for group in script:
# print group['name'] # print group['name']
# get each include path # get each include path
if group.has_key('CPPPATH') and group['CPPPATH']: if group.has_key('CPPPATH') and group['CPPPATH']:
if CPPPATH: if CPPPATH:
CPPPATH += group['CPPPATH'] CPPPATH += group['CPPPATH']
else: else:
CPPPATH += group['CPPPATH'] CPPPATH += group['CPPPATH']
# get each group's definitions # get each group's definitions
if group.has_key('CPPDEFINES') and group['CPPDEFINES']: if group.has_key('CPPDEFINES') and group['CPPDEFINES']:
if CPPDEFINES: if CPPDEFINES:
CPPDEFINES += ';' + group['CPPDEFINES'] CPPDEFINES += ';' + group['CPPDEFINES']
else: else:
CPPDEFINES += group['CPPDEFINES'] CPPDEFINES += group['CPPDEFINES']
# get each group's link flags # get each group's link flags
if group.has_key('LINKFLAGS') and group['LINKFLAGS']: if group.has_key('LINKFLAGS') and group['LINKFLAGS']:
if LINKFLAGS: if LINKFLAGS:
LINKFLAGS += ' ' + group['LINKFLAGS'] LINKFLAGS += ' ' + group['LINKFLAGS']
else: else:
LINKFLAGS += group['LINKFLAGS'] LINKFLAGS += group['LINKFLAGS']
# generate file items # generate file items
for node in group['src']: for node in group['src']:
fn = node.rfile() fn = node.rfile()
name = fn.name name = fn.name
path = os.path.dirname(fn.abspath) path = os.path.dirname(fn.abspath)
basename = os.path.basename(path) basename = os.path.basename(path)
path = _make_path_relative(project_path, path) path = _make_path_relative(project_path, path)
path = os.path.join(path, name) path = os.path.join(path, name)
if ProjectFiles.count(name): if ProjectFiles.count(name):
name = basename + '_' + name name = basename + '_' + name
ProjectFiles.append(name) ProjectFiles.append(name)
lines.insert(line_index, 'File %d,%d,<%s><%s>\r\n' lines.insert(line_index, 'File %d,%d,<%s><%s>\r\n'
% (group_index, _get_filetype(name), path, name)) % (group_index, _get_filetype(name), path, name))
line_index += 1 line_index += 1
group_index = group_index + 1 group_index = group_index + 1
lines.insert(line_index, '\r\n') lines.insert(line_index, '\r\n')
line_index += 1 line_index += 1
# remove repeat path # remove repeat path
paths = set() paths = set()
for path in CPPPATH: for path in CPPPATH:
inc = _make_path_relative(project_path, os.path.normpath(path)) inc = _make_path_relative(project_path, os.path.normpath(path))
paths.add(inc) #.replace('\\', '/') paths.add(inc) #.replace('\\', '/')
paths = [i for i in paths] paths = [i for i in paths]
CPPPATH = string.join(paths, ';') CPPPATH = string.join(paths, ';')
definitions = [i for i in set(CPPDEFINES)] definitions = [i for i in set(CPPDEFINES)]
CPPDEFINES = string.join(definitions, ', ') CPPDEFINES = string.join(definitions, ', ')
while line_index < len(lines): while line_index < len(lines):
if lines[line_index].startswith(' ADSCINCD '): if lines[line_index].startswith(' ADSCINCD '):
lines[line_index] = ' ADSCINCD (' + CPPPATH + ')\r\n' lines[line_index] = ' ADSCINCD (' + CPPPATH + ')\r\n'
if lines[line_index].startswith(' ADSLDMC ('): if lines[line_index].startswith(' ADSLDMC ('):
lines[line_index] = ' ADSLDMC (' + LINKFLAGS + ')\r\n' lines[line_index] = ' ADSLDMC (' + LINKFLAGS + ')\r\n'
if lines[line_index].startswith(' ADSCDEFN ('): if lines[line_index].startswith(' ADSCDEFN ('):
lines[line_index] = ' ADSCDEFN (' + CPPDEFINES + ')\r\n' lines[line_index] = ' ADSCDEFN (' + CPPDEFINES + ')\r\n'
line_index += 1 line_index += 1
# write project # write project
for line in lines: for line in lines:
project.write(line) project.write(line)
project.close() project.close()
def BuilderProject(target, script): def BuilderProject(target, script):
project = file(target, "wb") project = file(target, "wb")
project_path = os.path.dirname(os.path.abspath(target)) project_path = os.path.dirname(os.path.abspath(target))
# write file # write file
CPPPATH = [] CPPPATH = []
CPPDEFINES = [] CPPDEFINES = []
LINKFLAGS = '' LINKFLAGS = ''
CCFLAGS = '' CCFLAGS = ''
# number of groups # number of groups
group_index = 1 group_index = 1
for group in script: for group in script:
# print group['name'] # print group['name']
# generate file items # generate file items
for node in group['src']: for node in group['src']:
fn = node.rfile() fn = node.rfile()
name = fn.name name = fn.name
path = os.path.dirname(fn.abspath) path = os.path.dirname(fn.abspath)
path = _make_path_relative(project_path, path) path = _make_path_relative(project_path, path)
path = os.path.join(path, name) path = os.path.join(path, name)
project.write('%s\r\n' % path) project.write('%s\r\n' % path)
group_index = group_index + 1 group_index = group_index + 1
project.close() project.close()
class Win32Spawn: class Win32Spawn:
def spawn(self, sh, escape, cmd, args, env): def spawn(self, sh, escape, cmd, args, env):
import subprocess import subprocess
newargs = string.join(args[1:], ' ') newargs = string.join(args[1:], ' ')
cmdline = cmd + " " + newargs cmdline = cmd + " " + newargs
startupinfo = subprocess.STARTUPINFO() startupinfo = subprocess.STARTUPINFO()
# startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW # startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE, proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False) stderr=subprocess.PIPE, startupinfo=startupinfo, shell = False)
data, err = proc.communicate() data, err = proc.communicate()
rv = proc.wait() rv = proc.wait()
if rv: if rv:
print err print err
return rv return rv
if data: if data:
print data print data
return 0 return 0
def PrepareBuilding(env, root_directory, has_libcpu=False): def PrepareBuilding(env, root_directory, has_libcpu=False):
import SCons.cpp import SCons.cpp
import rtconfig import rtconfig
global BuildOptions global BuildOptions
global Projects global Projects
global Env global Env
global Rtt_Root global Rtt_Root
Env = env Env = env
Rtt_Root = root_directory Rtt_Root = root_directory
# patch for win32 spawn # patch for win32 spawn
if env['PLATFORM'] == 'win32' and rtconfig.PLATFORM == 'gcc': if env['PLATFORM'] == 'win32' and rtconfig.PLATFORM == 'gcc':
win32_spawn = Win32Spawn() win32_spawn = Win32Spawn()
win32_spawn.env = env win32_spawn.env = env
env['SPAWN'] = win32_spawn.spawn env['SPAWN'] = win32_spawn.spawn
# add program path # add program path
env.PrependENVPath('PATH', rtconfig.EXEC_PATH) env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
# parse rtconfig.h to get used component # parse rtconfig.h to get used component
PreProcessor = SCons.cpp.PreProcessor() PreProcessor = SCons.cpp.PreProcessor()
f = file('rtconfig.h', 'r') f = file('rtconfig.h', 'r')
contents = f.read() contents = f.read()
f.close() f.close()
PreProcessor.process_contents(contents) PreProcessor.process_contents(contents)
BuildOptions = PreProcessor.cpp_namespace BuildOptions = PreProcessor.cpp_namespace
# add target option # add target option
AddOption('--target', AddOption('--target',
dest='target', dest='target',
type='string', type='string',
help='set target project: mdk') help='set target project: mdk')
#{target_name:(CROSS_TOOL, PLATFORM)} #{target_name:(CROSS_TOOL, PLATFORM)}
tgt_dict = {'mdk':('keil', 'armcc'), tgt_dict = {'mdk':('keil', 'armcc'),
'mdk4':('keil', 'armcc'), 'mdk4':('keil', 'armcc'),
'iar':('iar', 'iar')} 'iar':('iar', 'iar')}
tgt_name = GetOption('target') tgt_name = GetOption('target')
if tgt_name: if tgt_name:
SetOption('no_exec', 1) SetOption('no_exec', 1)
try: try:
rtconfig.CROSS_TOOL, rtconfig.PLATFORM = tgt_dict[tgt_name] rtconfig.CROSS_TOOL, rtconfig.PLATFORM = tgt_dict[tgt_name]
except KeyError: except KeyError:
print 'Unknow target: %s. Avaible targets: %s' % \ print 'Unknow target: %s. Avaible targets: %s' % \
(tgt_name, ', '.join(tgt_dict.keys())) (tgt_name, ', '.join(tgt_dict.keys()))
sys.exit(1) sys.exit(1)
elif (GetDepend('RT_USING_NEWLIB') == False and GetDepend('RT_USING_NOLIBC') == False) \ elif (GetDepend('RT_USING_NEWLIB') == False and GetDepend('RT_USING_NOLIBC') == False) \
and rtconfig.PLATFORM == 'gcc': and rtconfig.PLATFORM == 'gcc':
AddDepend('RT_USING_MINILIBC') AddDepend('RT_USING_MINILIBC')
#env['CCCOMSTR'] = "CC $TARGET" #env['CCCOMSTR'] = "CC $TARGET"
#env['ASCOMSTR'] = "AS $TARGET" #env['ASCOMSTR'] = "AS $TARGET"
#env['LINKCOMSTR'] = "Link $TARGET" #env['LINKCOMSTR'] = "Link $TARGET"
# board build script # board build script
objs = SConscript('SConscript', variant_dir='build/bsp', duplicate=0) objs = SConscript('SConscript', variant_dir='build/bsp', duplicate=0)
Repository(Rtt_Root) Repository(Rtt_Root)
# include kernel # include kernel
objs.append(SConscript('src/SConscript', variant_dir='build/src', duplicate=0)) objs.append(SConscript('src/SConscript', variant_dir='build/src', duplicate=0))
# include libcpu # include libcpu
if not has_libcpu: if not has_libcpu:
objs.append(SConscript('libcpu/SConscript', variant_dir='build/libcpu', duplicate=0)) objs.append(SConscript('libcpu/SConscript', variant_dir='build/libcpu', duplicate=0))
# include components # include components
objs.append(SConscript('components/SConscript', variant_dir='build/components', duplicate=0)) objs.append(SConscript('components/SConscript', variant_dir='build/components', duplicate=0))
return objs return objs
def PrepareModuleBuilding(env, root_directory): def PrepareModuleBuilding(env, root_directory):
import SCons.cpp import SCons.cpp
import rtconfig import rtconfig
global BuildOptions global BuildOptions
global Projects global Projects
global Env global Env
global Rtt_Root global Rtt_Root
Env = env Env = env
Rtt_Root = root_directory Rtt_Root = root_directory
# add program path # add program path
env.PrependENVPath('PATH', rtconfig.EXEC_PATH) env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
def GetDepend(depend): def GetDepend(depend):
building = True building = True
if type(depend) == type('str'): if type(depend) == type('str'):
if not BuildOptions.has_key(depend) or BuildOptions[depend] == 0: if not BuildOptions.has_key(depend) or BuildOptions[depend] == 0:
building = False building = False
elif BuildOptions[depend] != '': elif BuildOptions[depend] != '':
return BuildOptions[depend] return BuildOptions[depend]
return building return building
# for list type depend # for list type depend
for item in depend: for item in depend:
if item != '': if item != '':
if not BuildOptions.has_key(item) or BuildOptions[item] == 0: if not BuildOptions.has_key(item) or BuildOptions[item] == 0:
building = False building = False
return building return building
def AddDepend(option): def AddDepend(option):
BuildOptions[option] = 1 BuildOptions[option] = 1
def DefineGroup(name, src, depend, **parameters): def DefineGroup(name, src, depend, **parameters):
global Env global Env
if not GetDepend(depend): if not GetDepend(depend):
return [] return []
group = parameters group = parameters
group['name'] = name group['name'] = name
if type(src) == type(['src1', 'str2']): if type(src) == type(['src1', 'str2']):
group['src'] = File(src) group['src'] = File(src)
else: else:
group['src'] = src group['src'] = src
Projects.append(group) Projects.append(group)
if group.has_key('CCFLAGS'): if group.has_key('CCFLAGS'):
Env.Append(CCFLAGS = group['CCFLAGS']) Env.Append(CCFLAGS = group['CCFLAGS'])
if group.has_key('CPPPATH'): if group.has_key('CPPPATH'):
Env.Append(CPPPATH = group['CPPPATH']) Env.Append(CPPPATH = group['CPPPATH'])
if group.has_key('CPPDEFINES'): if group.has_key('CPPDEFINES'):
Env.Append(CPPDEFINES = group['CPPDEFINES']) Env.Append(CPPDEFINES = group['CPPDEFINES'])
if group.has_key('LINKFLAGS'): if group.has_key('LINKFLAGS'):
Env.Append(LINKFLAGS = group['LINKFLAGS']) Env.Append(LINKFLAGS = group['LINKFLAGS'])
objs = Env.Object(group['src']) objs = Env.Object(group['src'])
if group.has_key('LIBRARY'): if group.has_key('LIBRARY'):
objs = Env.Library(name, objs) objs = Env.Library(name, objs)
return objs return objs
def GetCurrentDir(): def GetCurrentDir():
conscript = File('SConscript') conscript = File('SConscript')
fn = conscript.rfile() fn = conscript.rfile()
name = fn.name name = fn.name
path = os.path.dirname(fn.abspath) path = os.path.dirname(fn.abspath)
return path return path
def EndBuilding(target): def EndBuilding(target):
import rtconfig import rtconfig
Env.AddPostAction(target, rtconfig.POST_ACTION) Env.AddPostAction(target, rtconfig.POST_ACTION)
if GetOption('target') == 'mdk': if GetOption('target') == 'mdk':
template = os.path.isfile('template.Uv2') template = os.path.isfile('template.Uv2')
if template: if template:
MDKProject('project.Uv2', Projects) MDKProject('project.Uv2', Projects)
else: else:
template = os.path.isfile('template.uvproj') template = os.path.isfile('template.uvproj')
if template: if template:
MDK4Project('project.uvproj', Projects) MDK4Project('project.uvproj', Projects)
else: else:
print 'No template project file found.' print 'No template project file found.'
if GetOption('target') == 'mdk4': if GetOption('target') == 'mdk4':
MDK4Project('project.uvproj', Projects) MDK4Project('project.uvproj', Projects)
if GetOption('target') == 'iar': if GetOption('target') == 'iar':
IARProject('project.ewp', Projects) IARProject('project.ewp', Projects)
import copy
def SrcRemove(src, remove):
src_tmp = copy.copy(src)
count = 0
for i in range(0, len(src_tmp)):
s = os.path.basename(str(src_tmp[i]))
if s in remove:
src.pop(i-count)
count = count + 1
return src
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册