2015-01-23 14:34:09 +08:00
|
|
|
#
|
|
|
|
# File : building.py
|
|
|
|
# This file is part of RT-Thread RTOS
|
|
|
|
# COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# Change Logs:
|
|
|
|
# Date Author Notes
|
|
|
|
# 2015-01-20 Bernard Add copyright information
|
2015-07-25 23:50:17 +08:00
|
|
|
# 2015-07-25 Bernard Add LOCAL_CCFLAGS/LOCAL_CPPPATH/LOCAL_CPPDEFINES for
|
2018-06-14 09:30:35 +08:00
|
|
|
# group definition.
|
2015-01-23 14:34:09 +08:00
|
|
|
#
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import string
|
2018-11-10 18:29:08 +08:00
|
|
|
import utils
|
2020-06-11 09:17:16 +08:00
|
|
|
import operator
|
2022-04-22 08:23:35 +08:00
|
|
|
import rtconfig
|
2022-04-23 00:17:01 +08:00
|
|
|
import platform
|
2011-11-29 11:49:14 +08:00
|
|
|
|
|
|
|
from SCons.Script import *
|
2012-02-19 17:11:35 +08:00
|
|
|
from utils import _make_path_relative
|
2017-11-13 11:16:48 +08:00
|
|
|
from mkdist import do_copy_file
|
2022-04-22 08:23:35 +08:00
|
|
|
from options import AddOptions
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
|
|
|
|
BuildOptions = {}
|
|
|
|
Projects = []
|
|
|
|
Rtt_Root = ''
|
|
|
|
Env = None
|
|
|
|
|
2016-03-08 01:38:05 +08:00
|
|
|
# SCons PreProcessor patch
|
|
|
|
def start_handling_includes(self, t=None):
|
|
|
|
"""
|
|
|
|
Causes the PreProcessor object to start processing #import,
|
|
|
|
#include and #include_next lines.
|
|
|
|
|
|
|
|
This method will be called when a #if, #ifdef, #ifndef or #elif
|
|
|
|
evaluates True, or when we reach the #else in a #if, #ifdef,
|
|
|
|
#ifndef or #elif block where a condition already evaluated
|
|
|
|
False.
|
|
|
|
|
|
|
|
"""
|
|
|
|
d = self.dispatch_table
|
|
|
|
p = self.stack[-1] if self.stack else self.default_table
|
|
|
|
|
|
|
|
for k in ('import', 'include', 'include_next', 'define'):
|
|
|
|
d[k] = p[k]
|
|
|
|
|
|
|
|
def stop_handling_includes(self, t=None):
|
|
|
|
"""
|
|
|
|
Causes the PreProcessor object to stop processing #import,
|
|
|
|
#include and #include_next lines.
|
|
|
|
|
|
|
|
This method will be called when a #if, #ifdef, #ifndef or #elif
|
|
|
|
evaluates False, or when we reach the #else in a #if, #ifdef,
|
|
|
|
#ifndef or #elif block where a condition already evaluated True.
|
|
|
|
"""
|
|
|
|
d = self.dispatch_table
|
|
|
|
d['import'] = self.do_nothing
|
|
|
|
d['include'] = self.do_nothing
|
|
|
|
d['include_next'] = self.do_nothing
|
|
|
|
d['define'] = self.do_nothing
|
2018-06-14 09:30:35 +08:00
|
|
|
|
2016-03-08 01:38:05 +08:00
|
|
|
PatchedPreProcessor = SCons.cpp.PreProcessor
|
|
|
|
PatchedPreProcessor.start_handling_includes = start_handling_includes
|
|
|
|
PatchedPreProcessor.stop_handling_includes = stop_handling_includes
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
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:
|
2021-04-05 11:59:54 +08:00
|
|
|
print('Error removing file: ' + e)
|
2014-05-24 13:04:49 +08:00
|
|
|
return -1
|
|
|
|
return 0
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
import subprocess
|
|
|
|
|
2018-11-07 13:38:57 +08:00
|
|
|
newargs = ' '.join(args[1:])
|
2011-11-29 11:49:14 +08:00
|
|
|
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:
|
2021-04-05 11:59:54 +08:00
|
|
|
print('Error in calling command:' + cmdline.split(' ')[0])
|
|
|
|
print('Exception: ' + os.strerror(e.errno))
|
2018-12-24 09:08:22 +08:00
|
|
|
if (os.strerror(e.errno) == "No such file or directory"):
|
|
|
|
print ("\nPlease check Toolchains PATH setting.\n")
|
|
|
|
|
2014-06-07 16:46:00 +08:00
|
|
|
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
|
|
|
|
2018-06-23 10:07:48 +08:00
|
|
|
# generate cconfig.h file
|
|
|
|
def GenCconfigFile(env, BuildOptions):
|
2018-08-03 11:09:01 +08:00
|
|
|
|
2021-12-23 07:57:16 +08:00
|
|
|
if rtconfig.PLATFORM == 'gcc':
|
2018-06-23 10:07:48 +08:00
|
|
|
contents = ''
|
|
|
|
if not os.path.isfile('cconfig.h'):
|
|
|
|
import gcc
|
|
|
|
gcc.GenerateGCCConfig(rtconfig)
|
2018-06-22 15:03:02 +08:00
|
|
|
|
2018-06-23 10:07:48 +08:00
|
|
|
# try again
|
|
|
|
if os.path.isfile('cconfig.h'):
|
2018-11-07 13:38:57 +08:00
|
|
|
f = open('cconfig.h', 'r')
|
2018-06-23 10:07:48 +08:00
|
|
|
if f:
|
|
|
|
contents = f.read()
|
2018-12-25 14:18:50 +08:00
|
|
|
f.close()
|
2018-06-22 15:03:02 +08:00
|
|
|
|
2018-06-23 10:07:48 +08:00
|
|
|
prep = PatchedPreProcessor()
|
|
|
|
prep.process_contents(contents)
|
|
|
|
options = prep.cpp_namespace
|
2018-06-22 15:03:02 +08:00
|
|
|
|
2018-06-23 10:07:48 +08:00
|
|
|
BuildOptions.update(options)
|
|
|
|
|
|
|
|
# add HAVE_CCONFIG_H definition
|
|
|
|
env.AppendUnique(CPPDEFINES = ['HAVE_CCONFIG_H'])
|
2018-06-22 15:03:02 +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
|
|
|
|
|
|
|
global BuildOptions
|
|
|
|
global Projects
|
|
|
|
global Env
|
|
|
|
global Rtt_Root
|
|
|
|
|
2022-04-22 08:23:35 +08:00
|
|
|
AddOptions()
|
2018-06-23 10:07:48 +08:00
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
Env = env
|
2017-11-25 07:37:07 +08:00
|
|
|
Rtt_Root = os.path.abspath(root_directory)
|
2018-11-11 20:04:25 +08:00
|
|
|
|
|
|
|
# make an absolute root directory
|
|
|
|
RTT_ROOT = Rtt_Root
|
|
|
|
Export('RTT_ROOT')
|
|
|
|
|
2018-05-30 18:01:24 +08:00
|
|
|
# set RTT_ROOT in ENV
|
|
|
|
Env['RTT_ROOT'] = Rtt_Root
|
|
|
|
# set BSP_ROOT in ENV
|
|
|
|
Env['BSP_ROOT'] = Dir('#').abspath
|
|
|
|
|
2018-04-15 14:39:35 +08:00
|
|
|
sys.path = sys.path + [os.path.join(Rtt_Root, 'tools')]
|
2011-11-29 11:49:14 +08:00
|
|
|
|
2018-06-23 10:07:48 +08:00
|
|
|
# {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'),
|
2018-11-21 01:04:16 +08:00
|
|
|
'cdk':('gcc', 'gcc'),
|
2019-02-15 09:04:14 +08:00
|
|
|
'makefile':('gcc', 'gcc'),
|
2019-03-21 23:04:37 +08:00
|
|
|
'eclipse':('gcc', 'gcc'),
|
2020-10-16 15:16:35 +08:00
|
|
|
'ses' : ('gcc', 'gcc'),
|
2021-03-18 00:19:45 +08:00
|
|
|
'cmake':('gcc', 'gcc'),
|
2021-06-30 19:36:24 +08:00
|
|
|
'cmake-armclang':('keil', 'armclang'),
|
2020-10-16 15:16:35 +08:00
|
|
|
'codelite' : ('gcc', 'gcc')}
|
2018-06-23 10:07:48 +08:00
|
|
|
tgt_name = GetOption('target')
|
|
|
|
|
|
|
|
if tgt_name:
|
|
|
|
# --target will change the toolchain settings which clang-analyzer is
|
|
|
|
# depend on
|
|
|
|
if GetOption('clang-analyzer'):
|
2018-11-07 13:38:57 +08:00
|
|
|
print ('--clang-analyzer cannot be used with --target')
|
2018-06-23 10:07:48 +08:00
|
|
|
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
|
2018-11-10 18:29:08 +08:00
|
|
|
utils.ReloadModule(rtconfig)
|
2018-06-23 10:07:48 +08:00
|
|
|
except KeyError:
|
2021-04-05 11:59:54 +08:00
|
|
|
print('Unknow target: '+ tgt_name+'. Avaible targets: ' +', '.join(tgt_dict.keys()))
|
2018-06-23 10:07:48 +08:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# auto change the 'RTT_EXEC_PATH' when 'rtconfig.EXEC_PATH' get failed
|
|
|
|
if not os.path.exists(rtconfig.EXEC_PATH):
|
2018-06-27 08:27:45 +08:00
|
|
|
if 'RTT_EXEC_PATH' in os.environ:
|
2018-06-23 10:07:48 +08:00
|
|
|
# del the 'RTT_EXEC_PATH' and using the 'EXEC_PATH' setting on rtconfig.py
|
|
|
|
del os.environ['RTT_EXEC_PATH']
|
2018-11-10 18:29:08 +08:00
|
|
|
utils.ReloadModule(rtconfig)
|
2018-06-22 15:03:02 +08:00
|
|
|
|
2012-12-13 13:24:41 +08:00
|
|
|
# add compability with Keil MDK 4.6 which changes the directory of armcc.exe
|
2022-04-20 09:56:04 +08:00
|
|
|
if rtconfig.PLATFORM in ['armcc', 'armclang']:
|
2019-09-14 22:36:19 +08:00
|
|
|
if rtconfig.PLATFORM == 'armcc' and not os.path.isfile(os.path.join(rtconfig.EXEC_PATH, 'armcc.exe')):
|
2012-12-13 13:24:41 +08:00
|
|
|
if rtconfig.EXEC_PATH.find('bin40') > 0:
|
|
|
|
rtconfig.EXEC_PATH = rtconfig.EXEC_PATH.replace('bin40', 'armcc/bin')
|
2018-06-23 10:07:48 +08:00
|
|
|
Env['LINKFLAGS'] = Env['LINKFLAGS'].replace('RV31', 'armcc')
|
2012-12-13 13:24:41 +08:00
|
|
|
|
2014-11-19 14:52:36 +08:00
|
|
|
# reset AR command flags
|
2013-08-09 22:26:22 +08:00
|
|
|
env['ARCOM'] = '$AR --create $TARGET $SOURCES'
|
2018-06-23 10:07:48 +08:00
|
|
|
env['LIBPREFIX'] = ''
|
|
|
|
env['LIBSUFFIX'] = '.lib'
|
2014-02-07 23:23:44 +08:00
|
|
|
env['LIBLINKPREFIX'] = ''
|
2018-06-23 10:07:48 +08:00
|
|
|
env['LIBLINKSUFFIX'] = '.lib'
|
2014-02-07 23:23:44 +08:00
|
|
|
env['LIBDIRPREFIX'] = '--userlibpath '
|
2013-08-09 22:26:22 +08:00
|
|
|
|
2019-01-19 15:16:14 +08:00
|
|
|
elif rtconfig.PLATFORM == 'iar':
|
|
|
|
env['LIBPREFIX'] = ''
|
|
|
|
env['LIBSUFFIX'] = '.a'
|
|
|
|
env['LIBLINKPREFIX'] = ''
|
|
|
|
env['LIBLINKSUFFIX'] = '.a'
|
|
|
|
env['LIBDIRPREFIX'] = '--search '
|
|
|
|
|
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
|
2019-09-14 22:21:51 +08:00
|
|
|
env.PrependENVPath('PATH', os.environ['PATH'])
|
2019-01-05 07:39:36 +08:00
|
|
|
# add rtconfig.h/BSP path into Kernel group
|
|
|
|
DefineGroup("Kernel", [], [], CPPPATH=[str(Dir('#').abspath)])
|
2011-11-29 11:49:14 +08:00
|
|
|
|
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
|
2016-03-08 01:38:05 +08:00
|
|
|
PreProcessor = PatchedPreProcessor()
|
2018-11-07 13:38:57 +08:00
|
|
|
f = open('rtconfig.h', 'r')
|
2011-11-29 11:49:14 +08:00
|
|
|
contents = f.read()
|
|
|
|
f.close()
|
|
|
|
PreProcessor.process_contents(contents)
|
|
|
|
BuildOptions = PreProcessor.cpp_namespace
|
|
|
|
|
2013-07-09 19:55:14 +08:00
|
|
|
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
|
|
|
|
2018-06-23 10:07:48 +08:00
|
|
|
# generate cconfig.h file
|
|
|
|
GenCconfigFile(env, BuildOptions)
|
2011-11-29 11:49:14 +08:00
|
|
|
|
2018-06-23 10:07:48 +08:00
|
|
|
# auto append '_REENT_SMALL' when using newlib 'nano.specs' option
|
|
|
|
if rtconfig.PLATFORM == 'gcc' and str(env['LINKFLAGS']).find('nano.specs') != -1:
|
|
|
|
env.AppendUnique(CPPDEFINES = ['_REENT_SMALL'])
|
2013-07-09 19:55:14 +08:00
|
|
|
|
2017-11-02 16:57:17 +08:00
|
|
|
if GetOption('genconfig'):
|
|
|
|
from genconf import genconfig
|
|
|
|
genconfig()
|
|
|
|
exit(0)
|
|
|
|
|
2020-06-21 22:11:13 +08:00
|
|
|
if GetOption('stackanalysis'):
|
|
|
|
from WCS import ThreadStackStaticAnalysis
|
|
|
|
ThreadStackStaticAnalysis(Env)
|
|
|
|
exit(0)
|
2022-04-23 00:17:01 +08:00
|
|
|
if platform.system() != 'Windows':
|
|
|
|
if GetOption('menuconfig'):
|
|
|
|
from menuconfig import menuconfig
|
|
|
|
menuconfig(Rtt_Root)
|
|
|
|
exit(0)
|
2018-12-25 14:18:50 +08:00
|
|
|
|
|
|
|
if GetOption('pyconfig_silent'):
|
2019-07-24 18:30:44 +08:00
|
|
|
from menuconfig import guiconfig_silent
|
2018-12-25 14:18:50 +08:00
|
|
|
|
2019-07-24 18:30:44 +08:00
|
|
|
guiconfig_silent(Rtt_Root)
|
2018-12-25 14:18:50 +08:00
|
|
|
exit(0)
|
|
|
|
elif GetOption('pyconfig'):
|
2019-07-13 14:45:05 +08:00
|
|
|
from menuconfig import guiconfig
|
|
|
|
|
|
|
|
guiconfig(Rtt_Root)
|
|
|
|
exit(0)
|
2018-09-04 17:14:33 +08:00
|
|
|
|
2017-12-29 22:26:39 +08:00
|
|
|
configfn = GetOption('useconfig')
|
|
|
|
if configfn:
|
|
|
|
from menuconfig import mk_rtconfig
|
|
|
|
mk_rtconfig(configfn)
|
|
|
|
exit(0)
|
|
|
|
|
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
|
|
|
|
2017-12-02 10:53:19 +08:00
|
|
|
# fix the linker for C++
|
|
|
|
if GetDepend('RT_USING_CPLUSPLUS'):
|
|
|
|
if env['LINK'].find('gcc') != -1:
|
|
|
|
env['LINK'] = env['LINK'].replace('gcc', 'g++')
|
|
|
|
|
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.
|
2016-10-28 22:12:24 +08:00
|
|
|
bsp_vdir = 'build'
|
2014-04-10 15:03:11 +08:00
|
|
|
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'))
|
2021-05-10 20:34:33 +08:00
|
|
|
# include testcases
|
2021-05-17 15:11:34 +08:00
|
|
|
if os.path.isfile(os.path.join(Rtt_Root, 'examples/utest/testcases/SConscript')):
|
|
|
|
objs.extend(SConscript(Rtt_Root + '/examples/utest/testcases/SConscript',
|
2021-05-10 20:34:33 +08:00
|
|
|
variant_dir=kernel_vdir + '/examples/utest/testcases',
|
|
|
|
duplicate=0))
|
2011-11-29 11:49:14 +08:00
|
|
|
|
|
|
|
return objs
|
|
|
|
|
2015-03-14 09:46:37 +08:00
|
|
|
def PrepareModuleBuilding(env, root_directory, bsp_directory):
|
2011-11-29 11:49:14 +08:00
|
|
|
|
2015-03-18 15:50:10 +08:00
|
|
|
global BuildOptions
|
2011-11-29 11:49:14 +08:00
|
|
|
global Env
|
|
|
|
global Rtt_Root
|
|
|
|
|
2015-10-11 15:34:32 +08:00
|
|
|
# patch for win32 spawn
|
|
|
|
if env['PLATFORM'] == 'win32':
|
|
|
|
win32_spawn = Win32Spawn()
|
|
|
|
win32_spawn.env = env
|
|
|
|
env['SPAWN'] = win32_spawn.spawn
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
Env = env
|
|
|
|
Rtt_Root = root_directory
|
|
|
|
|
2015-03-14 09:46:37 +08:00
|
|
|
# parse bsp rtconfig.h to get used component
|
2016-03-08 01:38:05 +08:00
|
|
|
PreProcessor = PatchedPreProcessor()
|
2018-11-10 18:29:08 +08:00
|
|
|
f = open(bsp_directory + '/rtconfig.h', 'r')
|
2015-03-14 09:46:37 +08:00
|
|
|
contents = f.read()
|
|
|
|
f.close()
|
|
|
|
PreProcessor.process_contents(contents)
|
|
|
|
BuildOptions = PreProcessor.cpp_namespace
|
|
|
|
|
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'):
|
2018-11-07 13:38:57 +08:00
|
|
|
if not depend in BuildOptions or BuildOptions[depend] == 0:
|
2011-11-29 11:49:14 +08:00
|
|
|
building = False
|
|
|
|
elif BuildOptions[depend] != '':
|
|
|
|
return BuildOptions[depend]
|
2014-11-19 14:52:36 +08:00
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
return building
|
|
|
|
|
|
|
|
# for list type depend
|
|
|
|
for item in depend:
|
|
|
|
if item != '':
|
2018-11-07 13:38:57 +08:00
|
|
|
if not item in BuildOptions or BuildOptions[item] == 0:
|
2011-11-29 11:49:14 +08:00
|
|
|
building = False
|
|
|
|
|
|
|
|
return building
|
|
|
|
|
2016-10-28 22:12:24 +08:00
|
|
|
def LocalOptions(config_filename):
|
|
|
|
from SCons.Script import SCons
|
|
|
|
|
|
|
|
# parse wiced_config.h to get used component
|
|
|
|
PreProcessor = SCons.cpp.PreProcessor()
|
|
|
|
|
2018-11-10 18:29:08 +08:00
|
|
|
f = open(config_filename, 'r')
|
2016-10-28 22:12:24 +08:00
|
|
|
contents = f.read()
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
PreProcessor.process_contents(contents)
|
|
|
|
local_options = PreProcessor.cpp_namespace
|
|
|
|
|
|
|
|
return local_options
|
|
|
|
|
|
|
|
def GetLocalDepend(options, depend):
|
|
|
|
building = True
|
|
|
|
if type(depend) == type('str'):
|
2018-11-07 13:38:57 +08:00
|
|
|
if not depend in options or options[depend] == 0:
|
2016-10-28 22:12:24 +08:00
|
|
|
building = False
|
|
|
|
elif options[depend] != '':
|
|
|
|
return options[depend]
|
|
|
|
|
|
|
|
return building
|
|
|
|
|
|
|
|
# for list type depend
|
|
|
|
for item in depend:
|
|
|
|
if item != '':
|
2018-11-07 13:38:57 +08:00
|
|
|
if not item in options or options[item] == 0:
|
2016-10-28 22:12:24 +08:00
|
|
|
building = False
|
|
|
|
|
|
|
|
return building
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
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']
|
2022-04-08 12:55:05 +08:00
|
|
|
src_group['src'].sort()
|
2021-12-22 11:03:03 +08:00
|
|
|
if 'CFLAGS' in group:
|
|
|
|
if 'CFLAGS' in src_group:
|
|
|
|
src_group['CFLAGS'] = src_group['CFLAGS'] + group['CFLAGS']
|
|
|
|
else:
|
|
|
|
src_group['CFLAGS'] = group['CFLAGS']
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'CCFLAGS' in group:
|
|
|
|
if 'CCFLAGS' in src_group:
|
2011-12-10 23:31:55 +08:00
|
|
|
src_group['CCFLAGS'] = src_group['CCFLAGS'] + group['CCFLAGS']
|
|
|
|
else:
|
|
|
|
src_group['CCFLAGS'] = group['CCFLAGS']
|
2021-12-22 11:03:03 +08:00
|
|
|
if 'CXXFLAGS' in group:
|
|
|
|
if 'CXXFLAGS' in src_group:
|
|
|
|
src_group['CXXFLAGS'] = src_group['CXXFLAGS'] + group['CXXFLAGS']
|
|
|
|
else:
|
|
|
|
src_group['CXXFLAGS'] = group['CXXFLAGS']
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'CPPPATH' in group:
|
|
|
|
if 'CPPPATH' in src_group:
|
2011-12-10 23:31:55 +08:00
|
|
|
src_group['CPPPATH'] = src_group['CPPPATH'] + group['CPPPATH']
|
|
|
|
else:
|
|
|
|
src_group['CPPPATH'] = group['CPPPATH']
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'CPPDEFINES' in group:
|
|
|
|
if 'CPPDEFINES' in src_group:
|
2011-12-10 23:31:55 +08:00
|
|
|
src_group['CPPDEFINES'] = src_group['CPPDEFINES'] + group['CPPDEFINES']
|
|
|
|
else:
|
|
|
|
src_group['CPPDEFINES'] = group['CPPDEFINES']
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'ASFLAGS' in group:
|
|
|
|
if 'ASFLAGS' in src_group:
|
2018-06-04 14:18:31 +08:00
|
|
|
src_group['ASFLAGS'] = src_group['ASFLAGS'] + group['ASFLAGS']
|
|
|
|
else:
|
|
|
|
src_group['ASFLAGS'] = group['ASFLAGS']
|
2015-07-25 23:50:17 +08:00
|
|
|
|
|
|
|
# for local CCFLAGS/CPPPATH/CPPDEFINES
|
2021-12-22 11:03:03 +08:00
|
|
|
if 'LOCAL_CFLAGS' in group:
|
|
|
|
if 'LOCAL_CFLAGS' in src_group:
|
|
|
|
src_group['LOCAL_CFLAGS'] = src_group['LOCAL_CFLAGS'] + group['LOCAL_CFLAGS']
|
|
|
|
else:
|
|
|
|
src_group['LOCAL_CFLAGS'] = group['LOCAL_CFLAGS']
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'LOCAL_CCFLAGS' in group:
|
|
|
|
if 'LOCAL_CCFLAGS' in src_group:
|
2015-07-25 23:50:17 +08:00
|
|
|
src_group['LOCAL_CCFLAGS'] = src_group['LOCAL_CCFLAGS'] + group['LOCAL_CCFLAGS']
|
|
|
|
else:
|
|
|
|
src_group['LOCAL_CCFLAGS'] = group['LOCAL_CCFLAGS']
|
2021-12-22 11:03:03 +08:00
|
|
|
if 'LOCAL_CXXFLAGS' in group:
|
|
|
|
if 'LOCAL_CXXFLAGS' in src_group:
|
|
|
|
src_group['LOCAL_CXXFLAGS'] = src_group['LOCAL_CXXFLAGS'] + group['LOCAL_CXXFLAGS']
|
|
|
|
else:
|
|
|
|
src_group['LOCAL_CXXFLAGS'] = group['LOCAL_CXXFLAGS']
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'LOCAL_CPPPATH' in group:
|
|
|
|
if 'LOCAL_CPPPATH' in src_group:
|
2015-07-25 23:50:17 +08:00
|
|
|
src_group['LOCAL_CPPPATH'] = src_group['LOCAL_CPPPATH'] + group['LOCAL_CPPPATH']
|
|
|
|
else:
|
|
|
|
src_group['LOCAL_CPPPATH'] = group['LOCAL_CPPPATH']
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'LOCAL_CPPDEFINES' in group:
|
|
|
|
if 'LOCAL_CPPDEFINES' in src_group:
|
2015-07-25 23:50:17 +08:00
|
|
|
src_group['LOCAL_CPPDEFINES'] = src_group['LOCAL_CPPDEFINES'] + group['LOCAL_CPPDEFINES']
|
|
|
|
else:
|
|
|
|
src_group['LOCAL_CPPDEFINES'] = group['LOCAL_CPPDEFINES']
|
|
|
|
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'LINKFLAGS' in group:
|
|
|
|
if 'LINKFLAGS' in src_group:
|
2011-12-10 23:31:55 +08:00
|
|
|
src_group['LINKFLAGS'] = src_group['LINKFLAGS'] + group['LINKFLAGS']
|
|
|
|
else:
|
|
|
|
src_group['LINKFLAGS'] = group['LINKFLAGS']
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'LIBS' in group:
|
|
|
|
if 'LIBS' in src_group:
|
2012-11-05 14:58:25 +08:00
|
|
|
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']
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'LIBPATH' in group:
|
|
|
|
if 'LIBPATH' in src_group:
|
2012-11-05 14:58:25 +08:00
|
|
|
src_group['LIBPATH'] = src_group['LIBPATH'] + group['LIBPATH']
|
|
|
|
else:
|
|
|
|
src_group['LIBPATH'] = group['LIBPATH']
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'LOCAL_ASFLAGS' in group:
|
|
|
|
if 'LOCAL_ASFLAGS' in src_group:
|
2018-06-04 14:18:31 +08:00
|
|
|
src_group['LOCAL_ASFLAGS'] = src_group['LOCAL_ASFLAGS'] + group['LOCAL_ASFLAGS']
|
|
|
|
else:
|
|
|
|
src_group['LOCAL_ASFLAGS'] = group['LOCAL_ASFLAGS']
|
2011-12-10 23:31:55 +08:00
|
|
|
|
2021-11-30 13:49:57 +08:00
|
|
|
def _PretreatListParameters(target_list):
|
|
|
|
while '' in target_list: # remove null strings
|
|
|
|
target_list.remove('')
|
|
|
|
while ' ' in target_list: # remove ' '
|
|
|
|
target_list.remove(' ')
|
|
|
|
|
|
|
|
if(len(target_list) == 0):
|
|
|
|
return False # ignore this list, don't add this list to the parameter
|
|
|
|
|
|
|
|
return True # permit to add this list to the parameter
|
|
|
|
|
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
|
2018-05-30 18:01:24 +08:00
|
|
|
if type(src) == type([]):
|
2021-03-05 17:13:18 +08:00
|
|
|
# remove duplicate elements from list
|
|
|
|
src = list(set(src))
|
2011-11-29 11:49:14 +08:00
|
|
|
group['src'] = File(src)
|
|
|
|
else:
|
|
|
|
group['src'] = src
|
|
|
|
|
2021-12-22 11:03:03 +08:00
|
|
|
if 'CFLAGS' in group:
|
|
|
|
target = group['CFLAGS']
|
|
|
|
if len(target) > 0:
|
|
|
|
Env.AppendUnique(CFLAGS = target)
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'CCFLAGS' in group:
|
2021-11-30 13:49:57 +08:00
|
|
|
target = group['CCFLAGS']
|
|
|
|
if len(target) > 0:
|
|
|
|
Env.AppendUnique(CCFLAGS = target)
|
2021-12-22 11:03:03 +08:00
|
|
|
if 'CXXFLAGS' in group:
|
|
|
|
target = group['CXXFLAGS']
|
|
|
|
if len(target) > 0:
|
|
|
|
Env.AppendUnique(CXXFLAGS = target)
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'CPPPATH' in group:
|
2021-11-30 13:49:57 +08:00
|
|
|
target = group['CPPPATH']
|
|
|
|
if _PretreatListParameters(target) == True:
|
|
|
|
paths = []
|
|
|
|
for item in target:
|
|
|
|
paths.append(os.path.abspath(item))
|
|
|
|
target = paths
|
|
|
|
Env.AppendUnique(CPPPATH = target)
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'CPPDEFINES' in group:
|
2021-11-30 13:49:57 +08:00
|
|
|
target = group['CPPDEFINES']
|
|
|
|
if _PretreatListParameters(target) == True:
|
|
|
|
Env.AppendUnique(CPPDEFINES = target)
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'LINKFLAGS' in group:
|
2021-11-30 13:49:57 +08:00
|
|
|
target = group['LINKFLAGS']
|
|
|
|
if len(target) > 0:
|
|
|
|
Env.AppendUnique(LINKFLAGS = target)
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'ASFLAGS' in group:
|
2021-11-30 13:49:57 +08:00
|
|
|
target = group['ASFLAGS']
|
|
|
|
if len(target) > 0:
|
|
|
|
Env.AppendUnique(ASFLAGS = target)
|
2018-11-10 18:29:08 +08:00
|
|
|
if 'LOCAL_CPPPATH' in group:
|
|
|
|
paths = []
|
|
|
|
for item in group['LOCAL_CPPPATH']:
|
|
|
|
paths.append(os.path.abspath(item))
|
|
|
|
group['LOCAL_CPPPATH'] = paths
|
|
|
|
|
2022-04-22 08:23:35 +08:00
|
|
|
|
2018-11-10 18:29:08 +08:00
|
|
|
if rtconfig.PLATFORM == 'gcc':
|
2021-12-22 11:03:03 +08:00
|
|
|
if 'CFLAGS' in group:
|
|
|
|
group['CFLAGS'] = utils.GCCC99Patch(group['CFLAGS'])
|
2018-11-10 18:29:08 +08:00
|
|
|
if 'CCFLAGS' in group:
|
|
|
|
group['CCFLAGS'] = utils.GCCC99Patch(group['CCFLAGS'])
|
2021-12-22 11:03:03 +08:00
|
|
|
if 'CXXFLAGS' in group:
|
|
|
|
group['CXXFLAGS'] = utils.GCCC99Patch(group['CXXFLAGS'])
|
2018-11-10 18:29:08 +08:00
|
|
|
if 'LOCAL_CCFLAGS' in group:
|
|
|
|
group['LOCAL_CCFLAGS'] = utils.GCCC99Patch(group['LOCAL_CCFLAGS'])
|
2021-12-22 11:03:03 +08:00
|
|
|
if 'LOCAL_CXXFLAGS' in group:
|
|
|
|
group['LOCAL_CXXFLAGS'] = utils.GCCC99Patch(group['LOCAL_CXXFLAGS'])
|
|
|
|
if 'LOCAL_CFLAGS' in group:
|
|
|
|
group['LOCAL_CFLAGS'] = utils.GCCC99Patch(group['LOCAL_CFLAGS'])
|
2014-11-19 14:52:36 +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'] != []:
|
2021-04-05 11:59:54 +08:00
|
|
|
print('Remove library:'+ GroupLibFullName(name, Env))
|
2017-11-04 17:39:45 +08:00
|
|
|
fn = os.path.join(group['path'], GroupLibFullName(name, Env))
|
|
|
|
if os.path.exists(fn):
|
|
|
|
os.unlink(fn)
|
2014-02-07 23:23:44 +08:00
|
|
|
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'LIBS' in group:
|
2021-11-30 13:49:57 +08:00
|
|
|
target = group['LIBS']
|
|
|
|
if _PretreatListParameters(target) == True:
|
|
|
|
Env.AppendUnique(LIBS = target)
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'LIBPATH' in group:
|
2021-11-30 13:49:57 +08:00
|
|
|
target = group['LIBPATH']
|
|
|
|
if _PretreatListParameters(target) == True:
|
|
|
|
Env.AppendUnique(LIBPATH = target)
|
2011-11-29 11:49:14 +08:00
|
|
|
|
2015-07-25 23:50:17 +08:00
|
|
|
# check whether to build group library
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'LIBRARY' in group:
|
2014-11-18 17:04:35 +08:00
|
|
|
objs = Env.Library(name, group['src'])
|
|
|
|
else:
|
2015-07-25 23:50:17 +08:00
|
|
|
# only add source
|
2014-11-18 17:04:35 +08:00
|
|
|
objs = group['src']
|
2011-11-29 11:49:14 +08:00
|
|
|
|
2014-11-19 14:52:36 +08:00
|
|
|
# merge group
|
2011-12-10 23:31:55 +08:00
|
|
|
for g in Projects:
|
|
|
|
if g['name'] == name:
|
|
|
|
# merge to this group
|
|
|
|
MergeGroup(g, group)
|
|
|
|
return objs
|
|
|
|
|
2020-06-08 18:07:04 +08:00
|
|
|
def PriorityInsertGroup(groups, group):
|
|
|
|
length = len(groups)
|
|
|
|
for i in range(0, length):
|
2020-06-11 09:17:16 +08:00
|
|
|
if operator.gt(groups[i]['name'].lower(), group['name'].lower()):
|
2020-06-08 18:07:04 +08:00
|
|
|
groups.insert(i, group)
|
|
|
|
return
|
|
|
|
groups.append(group)
|
|
|
|
|
2014-11-19 14:52:36 +08:00
|
|
|
# add a new group
|
2020-06-08 18:07:04 +08:00
|
|
|
PriorityInsertGroup(Projects, group)
|
2011-12-10 23:31:55 +08:00
|
|
|
|
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):
|
2022-04-22 08:23:35 +08:00
|
|
|
|
2014-02-15 10:29:35 +08:00
|
|
|
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)
|
2021-04-05 11:59:54 +08:00
|
|
|
print('Copy '+lib_name+' => ' + dst_name)
|
2014-02-07 23:23:44 +08:00
|
|
|
do_copy_file(lib_name, dst_name)
|
|
|
|
break
|
|
|
|
|
2012-10-05 21:18:00 +08:00
|
|
|
def DoBuilding(target, objects):
|
2015-08-04 09:43:27 +08:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2015-10-14 11:07:42 +08:00
|
|
|
# handle local group
|
|
|
|
def local_group(group, objects):
|
2021-12-22 11:03:03 +08:00
|
|
|
if 'LOCAL_CFLAGS' in group or 'LOCAL_CXXFLAGS' in group or 'LOCAL_CCFLAGS' in group or 'LOCAL_CPPPATH' in group or 'LOCAL_CPPDEFINES' in group or 'LOCAL_ASFLAGS' in group:
|
|
|
|
CFLAGS = Env.get('CFLAGS', '') + group.get('LOCAL_CFLAGS', '')
|
2015-07-25 23:50:17 +08:00
|
|
|
CCFLAGS = Env.get('CCFLAGS', '') + group.get('LOCAL_CCFLAGS', '')
|
2021-12-22 11:03:03 +08:00
|
|
|
CXXFLAGS = Env.get('CXXFLAGS', '') + group.get('LOCAL_CXXFLAGS', '')
|
2015-07-25 23:50:17 +08:00
|
|
|
CPPPATH = Env.get('CPPPATH', ['']) + group.get('LOCAL_CPPPATH', [''])
|
|
|
|
CPPDEFINES = Env.get('CPPDEFINES', ['']) + group.get('LOCAL_CPPDEFINES', [''])
|
2018-06-04 14:18:31 +08:00
|
|
|
ASFLAGS = Env.get('ASFLAGS', '') + group.get('LOCAL_ASFLAGS', '')
|
2015-07-25 23:50:17 +08:00
|
|
|
|
|
|
|
for source in group['src']:
|
2021-12-22 11:03:03 +08:00
|
|
|
objects.append(Env.Object(source, CFLAGS = CFLAGS, CCFLAGS = CCFLAGS, CXXFLAGS = CXXFLAGS, ASFLAGS = ASFLAGS,
|
2015-10-14 11:07:42 +08:00
|
|
|
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES))
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
objects = one_list(objects)
|
2015-07-25 23:50:17 +08:00
|
|
|
|
2012-10-05 21:18:00 +08:00
|
|
|
program = None
|
|
|
|
# check whether special buildlib option
|
|
|
|
lib_name = GetOption('buildlib')
|
|
|
|
if lib_name:
|
2015-10-14 11:07:42 +08:00
|
|
|
objects = [] # remove all of objects
|
2012-10-05 21:18:00 +08:00
|
|
|
# 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)
|
2015-10-14 11:07:42 +08:00
|
|
|
if not local_group(Group, objects):
|
|
|
|
objects = Env.Object(Group['src'])
|
|
|
|
|
2012-10-05 21:18:00 +08:00
|
|
|
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:
|
2015-10-14 11:07:42 +08:00
|
|
|
# remove source files with local flags setting
|
|
|
|
for group in Projects:
|
2021-12-22 11:03:03 +08:00
|
|
|
if 'LOCAL_CFLAGS' in group or 'LOCAL_CXXFLAGS' in group or 'LOCAL_CCFLAGS' in group or 'LOCAL_CPPPATH' in group or 'LOCAL_CPPDEFINES' in group:
|
2015-10-14 11:07:42 +08:00
|
|
|
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:
|
|
|
|
local_group(group, objects)
|
|
|
|
|
2012-10-05 21:18:00 +08:00
|
|
|
program = Env.Program(target, objects)
|
|
|
|
|
|
|
|
EndBuilding(target, program)
|
2018-08-03 11:09:01 +08:00
|
|
|
|
2018-06-22 15:03:02 +08:00
|
|
|
def GenTargetProject(program = None):
|
2011-11-29 11:49:14 +08:00
|
|
|
|
|
|
|
if GetOption('target') == 'mdk':
|
2014-03-24 14:50:47 +08:00
|
|
|
from keil import MDKProject
|
|
|
|
from keil import MDK4Project
|
2014-11-19 14:57:10 +08:00
|
|
|
from keil import MDK5Project
|
2014-03-24 14:50:47 +08:00
|
|
|
|
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:
|
2014-11-19 14:57:10 +08:00
|
|
|
template = os.path.isfile('template.uvprojx')
|
|
|
|
if template:
|
|
|
|
MDK5Project('project.uvprojx', Projects)
|
|
|
|
else:
|
2018-11-07 13:38:57 +08:00
|
|
|
print ('No template project file found.')
|
2014-11-19 14:57:10 +08:00
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
if GetOption('target') == 'mdk4':
|
2014-03-24 14:50:47 +08:00
|
|
|
from keil import MDK4Project
|
2011-11-29 11:49:14 +08:00
|
|
|
MDK4Project('project.uvproj', Projects)
|
|
|
|
|
2014-11-19 14:57:10 +08:00
|
|
|
if GetOption('target') == 'mdk5':
|
|
|
|
from keil import MDK5Project
|
|
|
|
MDK5Project('project.uvprojx', Projects)
|
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
if GetOption('target') == 'iar':
|
2014-03-24 14:50:47 +08:00
|
|
|
from iar import IARProject
|
2014-11-19 14:52:36 +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('#')))
|
2014-11-19 14:52:36 +08:00
|
|
|
|
2018-05-30 18:01:24 +08:00
|
|
|
if GetOption('target') == 'vsc':
|
|
|
|
from vsc import GenerateVSCode
|
|
|
|
GenerateVSCode(Env)
|
2018-06-14 09:30:35 +08:00
|
|
|
|
2018-06-05 14:23:05 +08:00
|
|
|
if GetOption('target') == 'cdk':
|
|
|
|
from cdk import CDKProject
|
|
|
|
CDKProject('project.cdkproj', Projects)
|
2018-05-30 18:01:24 +08:00
|
|
|
|
2018-11-21 01:04:16 +08:00
|
|
|
if GetOption('target') == 'ses':
|
|
|
|
from ses import SESProject
|
|
|
|
SESProject(Env)
|
|
|
|
|
2019-02-15 09:04:14 +08:00
|
|
|
if GetOption('target') == 'makefile':
|
|
|
|
from makefile import TargetMakefile
|
|
|
|
TargetMakefile(Env)
|
|
|
|
|
2019-04-29 18:17:47 +08:00
|
|
|
if GetOption('target') == 'eclipse':
|
|
|
|
from eclipse import TargetEclipse
|
2019-06-18 20:11:12 +08:00
|
|
|
TargetEclipse(Env, GetOption('reset-project-config'), GetOption('project-name'))
|
2020-10-16 15:16:35 +08:00
|
|
|
|
|
|
|
if GetOption('target') == 'codelite':
|
|
|
|
from codelite import TargetCodelite
|
|
|
|
TargetCodelite(Projects, program)
|
2019-06-18 20:11:12 +08:00
|
|
|
|
2021-06-30 19:36:24 +08:00
|
|
|
if GetOption('target') == 'cmake' or GetOption('target') == 'cmake-armclang':
|
2021-03-18 00:10:52 +08:00
|
|
|
from cmake import CMakeProject
|
|
|
|
CMakeProject(Env,Projects)
|
|
|
|
|
2019-04-29 18:17:47 +08:00
|
|
|
|
2018-06-22 15:03:02 +08:00
|
|
|
def EndBuilding(target, program = None):
|
|
|
|
|
|
|
|
need_exit = False
|
|
|
|
|
|
|
|
Env['target'] = program
|
|
|
|
Env['project'] = Projects
|
|
|
|
|
2018-12-13 10:56:09 +08:00
|
|
|
if hasattr(rtconfig, 'BSP_LIBRARY_TYPE'):
|
|
|
|
Env['bsp_lib_type'] = rtconfig.BSP_LIBRARY_TYPE
|
|
|
|
|
2018-12-17 18:46:48 +08:00
|
|
|
if hasattr(rtconfig, 'dist_handle'):
|
|
|
|
Env['dist_handle'] = rtconfig.dist_handle
|
|
|
|
|
2018-06-22 15:03:02 +08:00
|
|
|
Env.AddPostAction(target, rtconfig.POST_ACTION)
|
|
|
|
# Add addition clean files
|
|
|
|
Clean(target, 'cconfig.h')
|
|
|
|
Clean(target, 'rtua.py')
|
|
|
|
Clean(target, 'rtua.pyc')
|
|
|
|
|
|
|
|
if GetOption('target'):
|
|
|
|
GenTargetProject(program)
|
|
|
|
|
2017-11-04 17:39:45 +08:00
|
|
|
BSP_ROOT = Dir('#').abspath
|
|
|
|
if GetOption('make-dist') and program != None:
|
|
|
|
from mkdist import MkDist
|
|
|
|
MkDist(program, BSP_ROOT, Rtt_Root, Env)
|
2018-08-03 11:09:01 +08:00
|
|
|
if GetOption('make-dist-strip') and program != None:
|
|
|
|
from mkdist import MkDist_Strip
|
|
|
|
MkDist_Strip(program, BSP_ROOT, Rtt_Root, Env)
|
2018-06-22 15:03:02 +08:00
|
|
|
need_exit = True
|
2019-06-17 20:34:05 +08:00
|
|
|
if GetOption('make-dist-ide') and program != None:
|
|
|
|
from mkdist import MkDist
|
2019-06-18 20:11:12 +08:00
|
|
|
project_path = GetOption('project-path')
|
|
|
|
project_name = GetOption('project-name')
|
2019-06-18 14:27:23 +08:00
|
|
|
|
|
|
|
if not isinstance(project_path, str) or len(project_path) == 0 :
|
2021-05-25 21:17:35 +08:00
|
|
|
project_path = os.path.join(BSP_ROOT, 'dist_ide_project')
|
|
|
|
print("\nwarning : --project-path not specified, use default path: {0}.".format(project_path))
|
2019-06-18 14:27:23 +08:00
|
|
|
if not isinstance(project_name, str) or len(project_name) == 0:
|
2021-05-25 21:17:35 +08:00
|
|
|
project_name = "dist_ide_project"
|
|
|
|
print("\nwarning : --project-name not specified, use default project name: {0}.".format(project_name))
|
2019-06-18 14:27:23 +08:00
|
|
|
|
2019-06-18 10:29:49 +08:00
|
|
|
rtt_ide = {'project_path' : project_path, 'project_name' : project_name}
|
2019-06-17 20:34:05 +08:00
|
|
|
MkDist(program, BSP_ROOT, Rtt_Root, Env, rtt_ide)
|
|
|
|
need_exit = True
|
2013-06-19 17:57:22 +08:00
|
|
|
if GetOption('cscope'):
|
|
|
|
from cscope import CscopeDatabase
|
|
|
|
CscopeDatabase(Projects)
|
|
|
|
|
2018-06-07 17:35:31 +08:00
|
|
|
if not GetOption('help') and not GetOption('target'):
|
|
|
|
if not os.path.exists(rtconfig.EXEC_PATH):
|
2018-11-07 13:40:41 +08:00
|
|
|
print ("Error: the toolchain path (" + rtconfig.EXEC_PATH + ") is not exist, please check 'EXEC_PATH' in path or rtconfig.py.")
|
2018-06-22 15:03:02 +08:00
|
|
|
need_exit = True
|
|
|
|
|
|
|
|
if need_exit:
|
|
|
|
exit(0)
|
2018-06-07 17:35:31 +08:00
|
|
|
|
2011-11-29 11:49:14 +08:00
|
|
|
def SrcRemove(src, remove):
|
2014-10-08 17:53:26 +08:00
|
|
|
if not src:
|
|
|
|
return
|
|
|
|
|
2018-06-14 11:55:15 +08:00
|
|
|
src_bak = src[:]
|
2018-06-14 09:30:35 +08:00
|
|
|
|
|
|
|
if type(remove) == type('str'):
|
|
|
|
if os.path.isabs(remove):
|
|
|
|
remove = os.path.relpath(remove, GetCurrentDir())
|
|
|
|
remove = os.path.normpath(remove)
|
|
|
|
|
2018-06-14 11:55:15 +08:00
|
|
|
for item in src_bak:
|
2018-06-14 09:30:35 +08:00
|
|
|
if type(item) == type('str'):
|
|
|
|
item_str = item
|
|
|
|
else:
|
|
|
|
item_str = item.rstr()
|
2018-04-07 17:14:12 +08:00
|
|
|
|
2018-06-14 09:30:35 +08:00
|
|
|
if os.path.isabs(item_str):
|
|
|
|
item_str = os.path.relpath(item_str, GetCurrentDir())
|
|
|
|
item_str = os.path.normpath(item_str)
|
2018-04-07 17:14:12 +08:00
|
|
|
|
|
|
|
if item_str == remove:
|
2018-06-14 11:55:15 +08:00
|
|
|
src.remove(item)
|
2018-06-14 09:30:35 +08:00
|
|
|
else:
|
|
|
|
for remove_item in remove:
|
|
|
|
remove_str = str(remove_item)
|
|
|
|
if os.path.isabs(remove_str):
|
|
|
|
remove_str = os.path.relpath(remove_str, GetCurrentDir())
|
|
|
|
remove_str = os.path.normpath(remove_str)
|
|
|
|
|
2018-06-14 11:55:15 +08:00
|
|
|
for item in src_bak:
|
2018-06-14 09:30:35 +08:00
|
|
|
if type(item) == type('str'):
|
|
|
|
item_str = item
|
|
|
|
else:
|
|
|
|
item_str = item.rstr()
|
|
|
|
|
|
|
|
if os.path.isabs(item_str):
|
|
|
|
item_str = os.path.relpath(item_str, GetCurrentDir())
|
|
|
|
item_str = os.path.normpath(item_str)
|
|
|
|
|
|
|
|
if item_str == remove_str:
|
2018-06-14 11:55:15 +08:00
|
|
|
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')
|
|
|
|
|
2014-11-19 14:52:36 +08:00
|
|
|
# parse rtdef.h to get RT-Thread version
|
2016-03-08 01:38:05 +08:00
|
|
|
prepcessor = PatchedPreProcessor()
|
2018-11-10 18:29:08 +08:00
|
|
|
f = open(rtdef, 'r')
|
2012-02-19 17:11:35 +08:00
|
|
|
contents = f.read()
|
|
|
|
f.close()
|
|
|
|
prepcessor.process_contents(contents)
|
|
|
|
def_ns = prepcessor.cpp_namespace
|
|
|
|
|
2021-04-05 11:59:54 +08:00
|
|
|
version = int([ch for ch in def_ns['RT_VERSION'] if ch in '0123456789.'])
|
|
|
|
subversion = int([ch for ch in def_ns['RT_SUBVERSION'] if ch in '0123456789.'])
|
2012-02-19 17:11:35 +08:00
|
|
|
|
2018-11-07 13:38:57 +08:00
|
|
|
if 'RT_REVISION' in def_ns:
|
2021-04-05 11:59:54 +08:00
|
|
|
revision = int([ch for ch in def_ns['RT_REVISION'] if ch in '0123456789.'])
|
2012-02-19 17:11:35 +08:00
|
|
|
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
|
|
|
|
2015-04-10 14:35:59 +08:00
|
|
|
def PackageSConscript(package):
|
|
|
|
from package import BuildPackage
|
|
|
|
|
|
|
|
return BuildPackage(package)
|