2011-11-29 11:49:14 +08:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import string
|
|
|
|
|
|
|
|
from SCons.Script import *
|
2012-02-19 17:11:35 +08:00
|
|
|
from utils import _make_path_relative
|
2011-11-29 11:49:14 +08:00
|
|
|
|
|
|
|
BuildOptions = {}
|
|
|
|
Projects = []
|
|
|
|
Rtt_Root = ''
|
|
|
|
Env = None
|
|
|
|
|
|
|
|
class Win32Spawn:
|
|
|
|
def spawn(self, sh, escape, cmd, args, env):
|
2014-05-24 13:04:49 +08:00
|
|
|
# deal with the cmd build-in commands which cannot be used in
|
|
|
|
# subprocess.Popen
|
|
|
|
if cmd == 'del':
|
|
|
|
for f in args[1:]:
|
|
|
|
try:
|
|
|
|
os.remove(f)
|
|
|
|
except Exception as e:
|
|
|
|
print 'Error removing file: %s' % e
|
|
|
|
return -1
|
|
|
|
return 0
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
newargs = string.join(args[1:], ' ')
|
|
|
|
cmdline = cmd + " " + newargs
|
2014-05-24 13:04:49 +08:00
|
|
|
|
|
|
|
# Make sure the env is constructed by strings
|
2014-09-06 14:33:46 +08:00
|
|
|
_e = dict([(k, str(v)) for k, v in env.items()])
|
2014-05-24 13:04:49 +08:00
|
|
|
|
|
|
|
# Windows(tm) CreateProcess does not use the env passed to it to find
|
|
|
|
# the executables. So we have to modify our own PATH to make Popen
|
|
|
|
# work.
|
|
|
|
old_path = os.environ['PATH']
|
|
|
|
os.environ['PATH'] = _e['PATH']
|
2012-02-17 17:20:33 +08:00
|
|
|
|
2014-05-24 13:04:49 +08:00
|
|
|
try:
|
2014-08-28 12:27:47 +08:00
|
|
|
proc = subprocess.Popen(cmdline, env=_e, shell=False)
|
2014-05-24 13:04:49 +08:00
|
|
|
except Exception as e:
|
2014-06-07 16:46:00 +08:00
|
|
|
print 'Error in calling:\n%s' % cmdline
|
|
|
|
print 'Exception: %s: %s' % (e, os.strerror(e.errno))
|
|
|
|
return e.errno
|
2014-05-24 13:04:49 +08:00
|
|
|
finally:
|
|
|
|
os.environ['PATH'] = old_path
|
2012-02-17 17:20:33 +08:00
|
|
|
|
2014-05-24 13:04:49 +08:00
|
|
|
return proc.wait()
|
2011-11-29 11:49:14 +08:00
|
|
|
|
2012-07-22 19:17:04 +08:00
|
|
|
def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = []):
|
2011-11-29 11:49:14 +08:00
|
|
|
import SCons.cpp
|
|
|
|
import rtconfig
|
|
|
|
|
|
|
|
global BuildOptions
|
|
|
|
global Projects
|
|
|
|
global Env
|
|
|
|
global Rtt_Root
|
|
|
|
|
|
|
|
Env = env
|
|
|
|
Rtt_Root = root_directory
|
|
|
|
|
2012-12-13 13:24:41 +08:00
|
|
|
# add compability with Keil MDK 4.6 which changes the directory of armcc.exe
|
|
|
|
if rtconfig.PLATFORM == 'armcc':
|
|
|
|
if not os.path.isfile(os.path.join(rtconfig.EXEC_PATH, 'armcc.exe')):
|
|
|
|
if rtconfig.EXEC_PATH.find('bin40') > 0:
|
|
|
|
rtconfig.EXEC_PATH = rtconfig.EXEC_PATH.replace('bin40', 'armcc/bin')
|
2013-03-01 02:27:32 +08:00
|
|
|
Env['LINKFLAGS']=Env['LINKFLAGS'].replace('RV31', 'armcc')
|
2012-12-13 13:24:41 +08:00
|
|
|
|
2013-08-09 22:26:22 +08:00
|
|
|
# reset AR command flags
|
|
|
|
env['ARCOM'] = '$AR --create $TARGET $SOURCES'
|
|
|
|
env['LIBPREFIX'] = ''
|
2014-02-15 10:29:35 +08:00
|
|
|
env['LIBSUFFIX'] = '.lib'
|
2014-02-07 23:23:44 +08:00
|
|
|
env['LIBLINKPREFIX'] = ''
|
2014-02-15 10:29:35 +08:00
|
|
|
env['LIBLINKSUFFIX'] = '.lib'
|
2014-02-07 23:23:44 +08:00
|
|
|
env['LIBDIRPREFIX'] = '--userlibpath '
|
2013-08-09 22:26:22 +08:00
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
# patch for win32 spawn
|
2014-05-24 13:04:49 +08:00
|
|
|
if env['PLATFORM'] == 'win32':
|
2011-11-29 11:49:14 +08:00
|
|
|
win32_spawn = Win32Spawn()
|
|
|
|
win32_spawn.env = env
|
|
|
|
env['SPAWN'] = win32_spawn.spawn
|
2014-05-24 13:04:49 +08:00
|
|
|
|
2012-08-01 15:33:58 +08:00
|
|
|
if env['PLATFORM'] == 'win32':
|
2012-08-01 07:15:51 +08:00
|
|
|
os.environ['PATH'] = rtconfig.EXEC_PATH + ";" + os.environ['PATH']
|
|
|
|
else:
|
|
|
|
os.environ['PATH'] = rtconfig.EXEC_PATH + ":" + os.environ['PATH']
|
2011-11-29 11:49:14 +08:00
|
|
|
|
|
|
|
# add program path
|
|
|
|
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
|
|
|
|
|
2014-02-07 23:23:44 +08:00
|
|
|
# add library build action
|
|
|
|
act = SCons.Action.Action(BuildLibInstallAction, 'Install compiled library... $TARGET')
|
|
|
|
bld = Builder(action = act)
|
|
|
|
Env.Append(BUILDERS = {'BuildLib': bld})
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
# parse rtconfig.h to get used component
|
|
|
|
PreProcessor = SCons.cpp.PreProcessor()
|
|
|
|
f = file('rtconfig.h', 'r')
|
|
|
|
contents = f.read()
|
|
|
|
f.close()
|
|
|
|
PreProcessor.process_contents(contents)
|
|
|
|
BuildOptions = PreProcessor.cpp_namespace
|
|
|
|
|
2012-08-11 16:43:47 +08:00
|
|
|
# add copy option
|
|
|
|
AddOption('--copy',
|
|
|
|
dest='copy',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='copy rt-thread directory to local.')
|
2012-08-22 14:19:04 +08:00
|
|
|
AddOption('--copy-header',
|
|
|
|
dest='copy-header',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='copy header of rt-thread directory to local.')
|
2013-06-19 17:57:22 +08:00
|
|
|
AddOption('--cscope',
|
|
|
|
dest='cscope',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='Build Cscope cross reference database. Requires cscope installed.')
|
2013-07-09 19:55:14 +08:00
|
|
|
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'):
|
|
|
|
# perform what scan-build does
|
|
|
|
env.Replace(
|
|
|
|
CC = 'ccc-analyzer',
|
|
|
|
CXX = 'c++-analyzer',
|
|
|
|
# skip as and link
|
|
|
|
LINK = 'true',
|
|
|
|
AS = 'true',)
|
|
|
|
env["ENV"].update(x for x in os.environ.items() if x[0].startswith("CCC_"))
|
|
|
|
# only check, don't compile. ccc-analyzer use CCC_CC as the CC.
|
2013-09-07 12:06:04 +08:00
|
|
|
# fsyntax-only will give us some additional warning messages
|
|
|
|
env['ENV']['CCC_CC'] = 'clang'
|
|
|
|
env.Append(CFLAGS=['-fsyntax-only', '-Wall', '-Wno-invalid-source-encoding'])
|
|
|
|
env['ENV']['CCC_CXX'] = 'clang++'
|
|
|
|
env.Append(CXXFLAGS=['-fsyntax-only', '-Wall', '-Wno-invalid-source-encoding'])
|
2013-07-09 19:55:14 +08:00
|
|
|
# remove the POST_ACTION as it will cause meaningless errors(file not
|
|
|
|
# found or something like that).
|
|
|
|
rtconfig.POST_ACTION = ''
|
2012-08-22 14:19:04 +08:00
|
|
|
|
2012-10-05 21:18:00 +08:00
|
|
|
# add build library option
|
|
|
|
AddOption('--buildlib',
|
|
|
|
dest='buildlib',
|
|
|
|
type='string',
|
|
|
|
help='building library of a component')
|
2014-02-07 23:23:44 +08:00
|
|
|
AddOption('--cleanlib',
|
|
|
|
dest='cleanlib',
|
|
|
|
action='store_true',
|
|
|
|
default=False,
|
|
|
|
help='clean up the library by --buildlib')
|
2012-10-05 21:18:00 +08:00
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
# add target option
|
|
|
|
AddOption('--target',
|
|
|
|
dest='target',
|
|
|
|
type='string',
|
2014-03-24 14:50:47 +08:00
|
|
|
help='set target project: mdk/iar/vs/ua')
|
2011-11-29 11:49:14 +08:00
|
|
|
|
|
|
|
#{target_name:(CROSS_TOOL, PLATFORM)}
|
|
|
|
tgt_dict = {'mdk':('keil', 'armcc'),
|
|
|
|
'mdk4':('keil', 'armcc'),
|
2012-11-08 07:02:25 +08:00
|
|
|
'iar':('iar', 'iar'),
|
2013-02-21 17:37:30 +08:00
|
|
|
'vs':('msvc', 'cl'),
|
2013-09-30 00:09:06 +08:00
|
|
|
'vs2012':('msvc', 'cl'),
|
2014-03-24 14:50:47 +08:00
|
|
|
'cb':('keil', 'armcc'),
|
|
|
|
'ua':('keil', 'armcc')}
|
2011-11-29 11:49:14 +08:00
|
|
|
tgt_name = GetOption('target')
|
|
|
|
if tgt_name:
|
2013-07-09 19:55:14 +08:00
|
|
|
# --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)
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
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) \
|
2012-02-17 17:20:33 +08:00
|
|
|
and rtconfig.PLATFORM == 'gcc':
|
2011-11-29 11:49:14 +08:00
|
|
|
AddDepend('RT_USING_MINILIBC')
|
|
|
|
|
2013-01-19 21:41:32 +08:00
|
|
|
# add comstr option
|
2013-01-29 16:54:03 +08:00
|
|
|
AddOption('--verbose',
|
|
|
|
dest='verbose',
|
2013-01-19 21:41:32 +08:00
|
|
|
action='store_true',
|
|
|
|
default=False,
|
2013-01-29 16:54:03 +08:00
|
|
|
help='print verbose information during build')
|
2013-01-19 21:41:32 +08:00
|
|
|
|
2013-01-29 16:54:03 +08:00
|
|
|
if not GetOption('verbose'):
|
|
|
|
# override the default verbose command string
|
2013-01-19 21:41:32 +08:00
|
|
|
env.Replace(
|
2013-03-31 23:05:04 +08:00
|
|
|
ARCOMSTR = 'AR $TARGET',
|
2013-01-19 21:41:32 +08:00
|
|
|
ASCOMSTR = 'AS $TARGET',
|
2013-03-31 23:05:04 +08:00
|
|
|
ASPPCOMSTR = 'AS $TARGET',
|
2013-01-19 21:41:32 +08:00
|
|
|
CCCOMSTR = 'CC $TARGET',
|
|
|
|
CXXCOMSTR = 'CXX $TARGET',
|
|
|
|
LINKCOMSTR = 'LINK $TARGET'
|
|
|
|
)
|
2011-11-29 11:49:14 +08:00
|
|
|
|
2014-04-10 15:03:11 +08:00
|
|
|
# we need to seperate the variant_dir for BSPs and the kernels. BSPs could
|
|
|
|
# have their own components etc. If they point to the same folder, SCons
|
|
|
|
# would find the wrong source code to compile.
|
|
|
|
bsp_vdir = 'build/bsp'
|
|
|
|
kernel_vdir = 'build/kernel'
|
|
|
|
# board build script
|
|
|
|
objs = SConscript('SConscript', variant_dir=bsp_vdir, duplicate=0)
|
2011-11-29 11:49:14 +08:00
|
|
|
# include kernel
|
2014-04-10 15:03:11 +08:00
|
|
|
objs.extend(SConscript(Rtt_Root + '/src/SConscript', variant_dir=kernel_vdir + '/src', duplicate=0))
|
2011-11-29 11:49:14 +08:00
|
|
|
# include libcpu
|
|
|
|
if not has_libcpu:
|
2014-04-10 15:03:11 +08:00
|
|
|
objs.extend(SConscript(Rtt_Root + '/libcpu/SConscript',
|
|
|
|
variant_dir=kernel_vdir + '/libcpu', duplicate=0))
|
2012-07-22 19:17:04 +08:00
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
# include components
|
2013-02-24 23:29:27 +08:00
|
|
|
objs.extend(SConscript(Rtt_Root + '/components/SConscript',
|
2014-04-10 15:03:11 +08:00
|
|
|
variant_dir=kernel_vdir + '/components',
|
2012-07-22 19:17:04 +08:00
|
|
|
duplicate=0,
|
|
|
|
exports='remove_components'))
|
2011-11-29 11:49:14 +08:00
|
|
|
|
|
|
|
return objs
|
|
|
|
|
|
|
|
def PrepareModuleBuilding(env, root_directory):
|
|
|
|
import rtconfig
|
|
|
|
|
|
|
|
global Env
|
|
|
|
global Rtt_Root
|
|
|
|
|
|
|
|
Env = env
|
|
|
|
Rtt_Root = root_directory
|
|
|
|
|
2014-03-24 14:50:47 +08:00
|
|
|
# add build/clean library option for library checking
|
|
|
|
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')
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
# add program path
|
|
|
|
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
|
|
|
|
|
2012-09-09 12:10:14 +08:00
|
|
|
def GetConfigValue(name):
|
|
|
|
assert type(name) == str, 'GetConfigValue: only string parameter is valid'
|
|
|
|
try:
|
|
|
|
return BuildOptions[name]
|
|
|
|
except:
|
|
|
|
return ''
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
def GetDepend(depend):
|
|
|
|
building = True
|
|
|
|
if type(depend) == type('str'):
|
|
|
|
if not BuildOptions.has_key(depend) or BuildOptions[depend] == 0:
|
|
|
|
building = False
|
|
|
|
elif BuildOptions[depend] != '':
|
|
|
|
return BuildOptions[depend]
|
|
|
|
|
|
|
|
return building
|
|
|
|
|
|
|
|
# for list type depend
|
|
|
|
for item in depend:
|
|
|
|
if item != '':
|
|
|
|
if not BuildOptions.has_key(item) or BuildOptions[item] == 0:
|
|
|
|
building = False
|
|
|
|
|
|
|
|
return building
|
|
|
|
|
|
|
|
def AddDepend(option):
|
|
|
|
BuildOptions[option] = 1
|
|
|
|
|
2011-12-10 23:31:55 +08:00
|
|
|
def MergeGroup(src_group, group):
|
|
|
|
src_group['src'] = src_group['src'] + group['src']
|
|
|
|
if group.has_key('CCFLAGS'):
|
|
|
|
if src_group.has_key('CCFLAGS'):
|
|
|
|
src_group['CCFLAGS'] = src_group['CCFLAGS'] + group['CCFLAGS']
|
|
|
|
else:
|
|
|
|
src_group['CCFLAGS'] = group['CCFLAGS']
|
|
|
|
if group.has_key('CPPPATH'):
|
|
|
|
if src_group.has_key('CPPPATH'):
|
|
|
|
src_group['CPPPATH'] = src_group['CPPPATH'] + group['CPPPATH']
|
|
|
|
else:
|
|
|
|
src_group['CPPPATH'] = group['CPPPATH']
|
|
|
|
if group.has_key('CPPDEFINES'):
|
|
|
|
if src_group.has_key('CPPDEFINES'):
|
|
|
|
src_group['CPPDEFINES'] = src_group['CPPDEFINES'] + group['CPPDEFINES']
|
|
|
|
else:
|
|
|
|
src_group['CPPDEFINES'] = group['CPPDEFINES']
|
|
|
|
if group.has_key('LINKFLAGS'):
|
|
|
|
if src_group.has_key('LINKFLAGS'):
|
|
|
|
src_group['LINKFLAGS'] = src_group['LINKFLAGS'] + group['LINKFLAGS']
|
|
|
|
else:
|
|
|
|
src_group['LINKFLAGS'] = group['LINKFLAGS']
|
2012-11-05 14:58:25 +08:00
|
|
|
if group.has_key('LIBS'):
|
|
|
|
if src_group.has_key('LIBS'):
|
|
|
|
src_group['LIBS'] = src_group['LIBS'] + group['LIBS']
|
2011-12-10 23:31:55 +08:00
|
|
|
else:
|
2012-11-05 14:58:25 +08:00
|
|
|
src_group['LIBS'] = group['LIBS']
|
|
|
|
if group.has_key('LIBPATH'):
|
|
|
|
if src_group.has_key('LIBPATH'):
|
|
|
|
src_group['LIBPATH'] = src_group['LIBPATH'] + group['LIBPATH']
|
|
|
|
else:
|
|
|
|
src_group['LIBPATH'] = group['LIBPATH']
|
2011-12-10 23:31:55 +08:00
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
def DefineGroup(name, src, depend, **parameters):
|
|
|
|
global Env
|
|
|
|
if not GetDepend(depend):
|
|
|
|
return []
|
|
|
|
|
2014-02-16 16:36:54 +08:00
|
|
|
# find exist group and get path of group
|
|
|
|
group_path = ''
|
|
|
|
for g in Projects:
|
|
|
|
if g['name'] == name:
|
|
|
|
group_path = g['path']
|
|
|
|
if group_path == '':
|
|
|
|
group_path = GetCurrentDir()
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
group = parameters
|
|
|
|
group['name'] = name
|
2014-02-16 16:36:54 +08:00
|
|
|
group['path'] = group_path
|
2014-02-07 23:23:44 +08:00
|
|
|
if type(src) == type(['src1']):
|
2011-11-29 11:49:14 +08:00
|
|
|
group['src'] = File(src)
|
|
|
|
else:
|
|
|
|
group['src'] = src
|
|
|
|
|
|
|
|
if group.has_key('CCFLAGS'):
|
|
|
|
Env.Append(CCFLAGS = group['CCFLAGS'])
|
|
|
|
if group.has_key('CPPPATH'):
|
|
|
|
Env.Append(CPPPATH = group['CPPPATH'])
|
|
|
|
if group.has_key('CPPDEFINES'):
|
|
|
|
Env.Append(CPPDEFINES = group['CPPDEFINES'])
|
|
|
|
if group.has_key('LINKFLAGS'):
|
|
|
|
Env.Append(LINKFLAGS = group['LINKFLAGS'])
|
2014-02-07 23:23:44 +08:00
|
|
|
|
|
|
|
# check whether to clean up library
|
2014-02-15 10:29:35 +08:00
|
|
|
if GetOption('cleanlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
|
2014-02-07 23:23:44 +08:00
|
|
|
if group['src'] != []:
|
2014-02-15 10:29:35 +08:00
|
|
|
print 'Remove library:', GroupLibFullName(name, Env)
|
|
|
|
do_rm_file(os.path.join(group['path'], GroupLibFullName(name, Env)))
|
2014-02-07 23:23:44 +08:00
|
|
|
|
|
|
|
# check whether exist group library
|
2014-02-15 10:29:35 +08:00
|
|
|
if not GetOption('buildlib') and os.path.exists(os.path.join(group['path'], GroupLibFullName(name, Env))):
|
2014-02-07 23:23:44 +08:00
|
|
|
group['src'] = []
|
2014-02-23 00:08:38 +08:00
|
|
|
if group.has_key('LIBS'): group['LIBS'] = group['LIBS'] + [GroupLibName(name, Env)]
|
|
|
|
else : group['LIBS'] = [GroupLibName(name, Env)]
|
|
|
|
if group.has_key('LIBPATH'): group['LIBPATH'] = group['LIBPATH'] + [GetCurrentDir()]
|
|
|
|
else : group['LIBPATH'] = [GetCurrentDir()]
|
2014-02-07 23:23:44 +08:00
|
|
|
|
2012-10-05 21:18:00 +08:00
|
|
|
if group.has_key('LIBS'):
|
|
|
|
Env.Append(LIBS = group['LIBS'])
|
|
|
|
if group.has_key('LIBPATH'):
|
|
|
|
Env.Append(LIBPATH = group['LIBPATH'])
|
2011-11-29 11:49:14 +08:00
|
|
|
|
|
|
|
objs = Env.Object(group['src'])
|
|
|
|
if group.has_key('LIBRARY'):
|
|
|
|
objs = Env.Library(name, objs)
|
|
|
|
|
2011-12-10 23:31:55 +08:00
|
|
|
# merge group
|
|
|
|
for g in Projects:
|
|
|
|
if g['name'] == name:
|
|
|
|
# merge to this group
|
|
|
|
MergeGroup(g, group)
|
|
|
|
return objs
|
|
|
|
|
|
|
|
# add a new group
|
|
|
|
Projects.append(group)
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
return objs
|
|
|
|
|
|
|
|
def GetCurrentDir():
|
|
|
|
conscript = File('SConscript')
|
|
|
|
fn = conscript.rfile()
|
|
|
|
name = fn.name
|
|
|
|
path = os.path.dirname(fn.abspath)
|
|
|
|
return path
|
|
|
|
|
2012-10-15 21:16:35 +08:00
|
|
|
PREBUILDING = []
|
|
|
|
def RegisterPreBuildingAction(act):
|
|
|
|
global PREBUILDING
|
|
|
|
assert callable(act), 'Could only register callable objects. %s received' % repr(act)
|
|
|
|
PREBUILDING.append(act)
|
|
|
|
|
|
|
|
def PreBuilding():
|
|
|
|
global PREBUILDING
|
|
|
|
for a in PREBUILDING:
|
|
|
|
a()
|
|
|
|
|
2014-02-07 23:23:44 +08:00
|
|
|
def GroupLibName(name, env):
|
2014-02-15 10:29:35 +08:00
|
|
|
import rtconfig
|
|
|
|
if rtconfig.PLATFORM == 'armcc':
|
|
|
|
return name + '_rvds'
|
|
|
|
elif rtconfig.PLATFORM == 'gcc':
|
|
|
|
return name + '_gcc'
|
|
|
|
|
|
|
|
return name
|
|
|
|
|
|
|
|
def GroupLibFullName(name, env):
|
|
|
|
return env['LIBPREFIX'] + GroupLibName(name, env) + env['LIBSUFFIX']
|
2014-02-07 23:23:44 +08:00
|
|
|
|
|
|
|
def BuildLibInstallAction(target, source, env):
|
|
|
|
lib_name = GetOption('buildlib')
|
|
|
|
for Group in Projects:
|
|
|
|
if Group['name'] == lib_name:
|
2014-02-15 10:29:35 +08:00
|
|
|
lib_name = GroupLibFullName(Group['name'], env)
|
2014-02-07 23:23:44 +08:00
|
|
|
dst_name = os.path.join(Group['path'], lib_name)
|
|
|
|
print 'Copy %s => %s' % (lib_name, dst_name)
|
|
|
|
do_copy_file(lib_name, dst_name)
|
|
|
|
break
|
|
|
|
|
2012-10-05 21:18:00 +08:00
|
|
|
def DoBuilding(target, objects):
|
|
|
|
program = None
|
|
|
|
# check whether special buildlib option
|
|
|
|
lib_name = GetOption('buildlib')
|
|
|
|
if lib_name:
|
|
|
|
# build library with special component
|
|
|
|
for Group in Projects:
|
|
|
|
if Group['name'] == lib_name:
|
2014-02-15 10:29:35 +08:00
|
|
|
lib_name = GroupLibName(Group['name'], Env)
|
2012-10-05 21:18:00 +08:00
|
|
|
objects = Env.Object(Group['src'])
|
|
|
|
program = Env.Library(lib_name, objects)
|
2014-02-07 23:23:44 +08:00
|
|
|
|
|
|
|
# add library copy action
|
|
|
|
Env.BuildLib(lib_name, program)
|
|
|
|
|
2012-10-05 21:18:00 +08:00
|
|
|
break
|
|
|
|
else:
|
2014-02-16 16:36:54 +08:00
|
|
|
# merge the repeated items in the Env
|
|
|
|
if Env.has_key('CPPPATH') : Env['CPPPATH'] = list(set(Env['CPPPATH']))
|
|
|
|
if Env.has_key('CPPDEFINES'): Env['CPPDEFINES'] = list(set(Env['CPPDEFINES']))
|
|
|
|
if Env.has_key('LIBPATH') : Env['LIBPATH'] = list(set(Env['LIBPATH']))
|
|
|
|
if Env.has_key('LIBS') : Env['LIBS'] = list(set(Env['LIBS']))
|
|
|
|
|
2012-10-05 21:18:00 +08:00
|
|
|
program = Env.Program(target, objects)
|
|
|
|
|
|
|
|
EndBuilding(target, program)
|
|
|
|
|
2012-08-11 16:43:47 +08:00
|
|
|
def EndBuilding(target, program = None):
|
2011-11-29 11:49:14 +08:00
|
|
|
import rtconfig
|
2012-02-19 17:11:35 +08:00
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
Env.AddPostAction(target, rtconfig.POST_ACTION)
|
|
|
|
|
|
|
|
if GetOption('target') == 'mdk':
|
2014-03-24 14:50:47 +08:00
|
|
|
from keil import MDKProject
|
|
|
|
from keil import MDK4Project
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
template = os.path.isfile('template.Uv2')
|
|
|
|
if template:
|
|
|
|
MDKProject('project.Uv2', Projects)
|
|
|
|
else:
|
|
|
|
template = os.path.isfile('template.uvproj')
|
|
|
|
if template:
|
|
|
|
MDK4Project('project.uvproj', Projects)
|
|
|
|
else:
|
|
|
|
print 'No template project file found.'
|
|
|
|
|
|
|
|
if GetOption('target') == 'mdk4':
|
2014-03-24 14:50:47 +08:00
|
|
|
from keil import MDKProject
|
|
|
|
from keil import MDK4Project
|
2011-11-29 11:49:14 +08:00
|
|
|
MDK4Project('project.uvproj', Projects)
|
|
|
|
|
|
|
|
if GetOption('target') == 'iar':
|
2014-03-24 14:50:47 +08:00
|
|
|
from iar import IARProject
|
2011-11-29 11:49:14 +08:00
|
|
|
IARProject('project.ewp', Projects)
|
2011-12-10 21:14:26 +08:00
|
|
|
|
2012-11-08 07:02:25 +08:00
|
|
|
if GetOption('target') == 'vs':
|
2014-03-24 14:50:47 +08:00
|
|
|
from vs import VSProject
|
2012-12-01 15:01:55 +08:00
|
|
|
VSProject('project.vcproj', Projects, program)
|
2012-11-08 07:02:25 +08:00
|
|
|
|
2013-09-30 00:09:06 +08:00
|
|
|
if GetOption('target') == 'vs2012':
|
2014-03-24 14:50:47 +08:00
|
|
|
from vs2012 import VS2012Project
|
2013-09-30 00:09:06 +08:00
|
|
|
VS2012Project('project.vcxproj', Projects, program)
|
|
|
|
|
2013-02-21 17:37:30 +08:00
|
|
|
if GetOption('target') == 'cb':
|
2014-03-24 14:50:47 +08:00
|
|
|
from codeblocks import CBProject
|
2013-02-21 17:37:30 +08:00
|
|
|
CBProject('project.cbp', Projects, program)
|
|
|
|
|
2014-03-24 14:50:47 +08:00
|
|
|
if GetOption('target') == 'ua':
|
|
|
|
from ua import PrepareUA
|
|
|
|
PrepareUA(Projects, Rtt_Root, str(Dir('#')))
|
|
|
|
|
2012-08-11 16:43:47 +08:00
|
|
|
if GetOption('copy') and program != None:
|
|
|
|
MakeCopy(program)
|
2012-08-22 14:19:04 +08:00
|
|
|
if GetOption('copy-header') and program != None:
|
|
|
|
MakeCopyHeader(program)
|
2012-08-11 16:43:47 +08:00
|
|
|
|
2013-06-19 17:57:22 +08:00
|
|
|
if GetOption('cscope'):
|
|
|
|
from cscope import CscopeDatabase
|
|
|
|
CscopeDatabase(Projects)
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
def SrcRemove(src, remove):
|
2012-02-17 17:20:33 +08:00
|
|
|
if type(src[0]) == type('str'):
|
|
|
|
for item in src:
|
|
|
|
if os.path.basename(item) in remove:
|
|
|
|
src.remove(item)
|
|
|
|
return
|
|
|
|
|
|
|
|
for item in src:
|
|
|
|
if os.path.basename(item.rstr()) in remove:
|
|
|
|
src.remove(item)
|
2012-02-19 17:11:35 +08:00
|
|
|
|
|
|
|
def GetVersion():
|
|
|
|
import SCons.cpp
|
|
|
|
import string
|
|
|
|
|
|
|
|
rtdef = os.path.join(Rtt_Root, 'include', 'rtdef.h')
|
|
|
|
|
|
|
|
# parse rtdef.h to get RT-Thread version
|
|
|
|
prepcessor = SCons.cpp.PreProcessor()
|
|
|
|
f = file(rtdef, 'r')
|
|
|
|
contents = f.read()
|
|
|
|
f.close()
|
|
|
|
prepcessor.process_contents(contents)
|
|
|
|
def_ns = prepcessor.cpp_namespace
|
|
|
|
|
|
|
|
version = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_VERSION']))
|
|
|
|
subversion = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_SUBVERSION']))
|
|
|
|
|
|
|
|
if def_ns.has_key('RT_REVISION'):
|
|
|
|
revision = int(filter(lambda ch: ch in '0123456789.', def_ns['RT_REVISION']))
|
|
|
|
return '%d.%d.%d' % (version, subversion, revision)
|
|
|
|
|
|
|
|
return '0.%d.%d' % (version, subversion)
|
2012-08-01 07:15:51 +08:00
|
|
|
|
2012-10-06 08:12:38 +08:00
|
|
|
def GlobSubDir(sub_dir, ext_name):
|
|
|
|
import os
|
|
|
|
import glob
|
|
|
|
|
2012-10-06 11:01:02 +08:00
|
|
|
def glob_source(sub_dir, ext_name):
|
|
|
|
list = os.listdir(sub_dir)
|
|
|
|
src = glob.glob(os.path.join(sub_dir, ext_name))
|
|
|
|
|
|
|
|
for item in list:
|
|
|
|
full_subdir = os.path.join(sub_dir, item)
|
|
|
|
if os.path.isdir(full_subdir):
|
|
|
|
src += glob_source(full_subdir, ext_name)
|
|
|
|
return src
|
|
|
|
|
|
|
|
dst = []
|
|
|
|
src = glob_source(sub_dir, ext_name)
|
|
|
|
for item in src:
|
|
|
|
dst.append(os.path.relpath(item, sub_dir))
|
|
|
|
return dst
|
2012-10-06 08:12:38 +08:00
|
|
|
|
2014-02-16 16:36:54 +08:00
|
|
|
def file_path_exist(path, *args):
|
|
|
|
return os.path.exists(os.path.join(path, *args))
|
|
|
|
|
2014-02-07 23:23:44 +08:00
|
|
|
def do_rm_file(src):
|
|
|
|
if os.path.exists(src):
|
|
|
|
os.unlink(src)
|
|
|
|
|
2012-08-01 07:15:51 +08:00
|
|
|
def do_copy_file(src, dst):
|
2012-08-11 16:43:47 +08:00
|
|
|
import shutil
|
|
|
|
# check source file
|
|
|
|
if not os.path.exists(src):
|
|
|
|
return
|
|
|
|
|
|
|
|
path = os.path.dirname(dst)
|
|
|
|
# mkdir if path not exist
|
|
|
|
if not os.path.exists(path):
|
|
|
|
os.makedirs(path)
|
|
|
|
|
|
|
|
shutil.copy2(src, dst)
|
|
|
|
|
|
|
|
def do_copy_folder(src_dir, dst_dir):
|
|
|
|
import shutil
|
|
|
|
# check source directory
|
|
|
|
if not os.path.exists(src_dir):
|
|
|
|
return
|
|
|
|
|
|
|
|
if os.path.exists(dst_dir):
|
|
|
|
shutil.rmtree(dst_dir)
|
|
|
|
|
|
|
|
shutil.copytree(src_dir, dst_dir)
|
|
|
|
|
|
|
|
source_ext = ["c", "h", "s", "S", "cpp", "xpm"]
|
|
|
|
source_list = []
|
|
|
|
|
|
|
|
def walk_children(child):
|
|
|
|
global source_list
|
|
|
|
global source_ext
|
|
|
|
|
|
|
|
# print child
|
|
|
|
full_path = child.rfile().abspath
|
|
|
|
file_type = full_path.rsplit('.',1)[1]
|
|
|
|
#print file_type
|
|
|
|
if file_type in source_ext:
|
|
|
|
if full_path not in source_list:
|
|
|
|
source_list.append(full_path)
|
|
|
|
|
|
|
|
children = child.all_children()
|
|
|
|
if children != []:
|
|
|
|
for item in children:
|
|
|
|
walk_children(item)
|
|
|
|
|
|
|
|
def MakeCopy(program):
|
|
|
|
global source_list
|
|
|
|
global Rtt_Root
|
|
|
|
global Env
|
|
|
|
|
|
|
|
target_path = os.path.join(Dir('#').abspath, 'rt-thread')
|
|
|
|
|
|
|
|
if Env['PLATFORM'] == 'win32':
|
|
|
|
RTT_ROOT = Rtt_Root.lower()
|
|
|
|
else:
|
|
|
|
RTT_ROOT = Rtt_Root
|
|
|
|
|
|
|
|
if target_path.startswith(RTT_ROOT):
|
|
|
|
return
|
2012-08-01 07:15:51 +08:00
|
|
|
|
2012-08-11 16:43:47 +08:00
|
|
|
for item in program:
|
|
|
|
walk_children(item)
|
|
|
|
|
|
|
|
source_list.sort()
|
|
|
|
|
|
|
|
# filte source file in RT-Thread
|
|
|
|
target_list = []
|
|
|
|
for src in source_list:
|
|
|
|
if Env['PLATFORM'] == 'win32':
|
|
|
|
src = src.lower()
|
|
|
|
|
|
|
|
if src.startswith(RTT_ROOT):
|
|
|
|
target_list.append(src)
|
|
|
|
|
|
|
|
source_list = target_list
|
|
|
|
# get source path
|
|
|
|
src_dir = []
|
|
|
|
for src in source_list:
|
|
|
|
src = src.replace(RTT_ROOT, '')
|
|
|
|
if src[0] == os.sep or src[0] == '/':
|
|
|
|
src = src[1:]
|
|
|
|
|
|
|
|
path = os.path.dirname(src)
|
|
|
|
sub_path = path.split(os.sep)
|
|
|
|
full_path = RTT_ROOT
|
|
|
|
for item in sub_path:
|
|
|
|
full_path = os.path.join(full_path, item)
|
|
|
|
if full_path not in src_dir:
|
|
|
|
src_dir.append(full_path)
|
|
|
|
|
|
|
|
for item in src_dir:
|
|
|
|
source_list.append(os.path.join(item, 'SConscript'))
|
|
|
|
|
|
|
|
for src in source_list:
|
|
|
|
dst = src.replace(RTT_ROOT, '')
|
|
|
|
if dst[0] == os.sep or dst[0] == '/':
|
|
|
|
dst = dst[1:]
|
|
|
|
print '=> ', dst
|
|
|
|
dst = os.path.join(target_path, dst)
|
|
|
|
do_copy_file(src, dst)
|
|
|
|
|
|
|
|
# copy tools directory
|
|
|
|
print "=> tools"
|
|
|
|
do_copy_folder(os.path.join(RTT_ROOT, "tools"), os.path.join(target_path, "tools"))
|
|
|
|
do_copy_file(os.path.join(RTT_ROOT, 'AUTHORS'), os.path.join(target_path, 'AUTHORS'))
|
|
|
|
do_copy_file(os.path.join(RTT_ROOT, 'COPYING'), os.path.join(target_path, 'COPYING'))
|
2012-08-22 14:19:04 +08:00
|
|
|
|
|
|
|
def MakeCopyHeader(program):
|
|
|
|
global source_ext
|
|
|
|
source_ext = []
|
|
|
|
source_ext = ["h", "xpm"]
|
|
|
|
global source_list
|
|
|
|
global Rtt_Root
|
|
|
|
global Env
|
|
|
|
|
|
|
|
target_path = os.path.join(Dir('#').abspath, 'rt-thread')
|
|
|
|
|
|
|
|
if Env['PLATFORM'] == 'win32':
|
|
|
|
RTT_ROOT = Rtt_Root.lower()
|
|
|
|
else:
|
|
|
|
RTT_ROOT = Rtt_Root
|
|
|
|
|
|
|
|
if target_path.startswith(RTT_ROOT):
|
|
|
|
return
|
|
|
|
|
|
|
|
for item in program:
|
|
|
|
walk_children(item)
|
|
|
|
|
|
|
|
source_list.sort()
|
|
|
|
|
|
|
|
# filte source file in RT-Thread
|
|
|
|
target_list = []
|
|
|
|
for src in source_list:
|
|
|
|
if Env['PLATFORM'] == 'win32':
|
|
|
|
src = src.lower()
|
|
|
|
|
|
|
|
if src.startswith(RTT_ROOT):
|
|
|
|
target_list.append(src)
|
|
|
|
|
|
|
|
source_list = target_list
|
|
|
|
|
|
|
|
for src in source_list:
|
|
|
|
dst = src.replace(RTT_ROOT, '')
|
|
|
|
if dst[0] == os.sep or dst[0] == '/':
|
|
|
|
dst = dst[1:]
|
|
|
|
print '=> ', dst
|
|
|
|
dst = os.path.join(target_path, dst)
|
|
|
|
do_copy_file(src, dst)
|
|
|
|
|
|
|
|
# copy tools directory
|
|
|
|
print "=> tools"
|
|
|
|
do_copy_folder(os.path.join(RTT_ROOT, "tools"), os.path.join(target_path, "tools"))
|
|
|
|
do_copy_file(os.path.join(RTT_ROOT, 'AUTHORS'), os.path.join(target_path, 'AUTHORS'))
|
|
|
|
do_copy_file(os.path.join(RTT_ROOT, 'COPYING'), os.path.join(target_path, 'COPYING'))
|