mirror of
https://gitee.com/Vancouver2017/luban-lite-t3e-pro.git
synced 2025-12-14 10:28:54 +00:00
307 lines
11 KiB
Python
307 lines
11 KiB
Python
# File : SConstruct.py
|
|
# Building Script for User Applications
|
|
# 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-02-07 Bernard The firstly version
|
|
# 2018-04-15 Bernard Add the build option for library
|
|
#
|
|
|
|
import os
|
|
import sys
|
|
import platform
|
|
import shutil
|
|
import glob
|
|
|
|
# 0. path variable
|
|
cwd = os.getcwd()
|
|
tools_path = os.path.join(cwd, 'tools')
|
|
sdk_path = os.path.join(tools_path, 'sdk')
|
|
# luban-Lite root directory
|
|
AIC_ROOT = os.path.join(cwd, '../../../')
|
|
AIC_ROOT = os.path.normpath(AIC_ROOT)
|
|
config_path = os.path.join(AIC_ROOT, '.config')
|
|
toolchain_path = os.path.join(cwd, 'toolchain')
|
|
os.environ["M_EXEC_PATH"] = os.path.join(toolchain_path, 'bin')
|
|
if os.path.exists(config_path):
|
|
# luban-lite custom scripts
|
|
aic_script_path = os.path.join(AIC_ROOT, 'tools/scripts/')
|
|
sys.path.append(aic_script_path)
|
|
from aic_build import *
|
|
PRJ_CHIP,PRJ_BOARD,PRJ_KERNEL,PRJ_APP,PRJ_DEFCONFIG_NAME,PRJ_CUSTOM_LDS,MKIMAGE_POST_ACTION = get_prj_config(AIC_ROOT)
|
|
PRJ_NAME = PRJ_DEFCONFIG_NAME.replace('_defconfig','')
|
|
PRJ_OUT_DIR = 'output/' + PRJ_NAME + '/images/'
|
|
|
|
# 1. luban-lite paths
|
|
bsp_root = AIC_ROOT
|
|
rtt_root = os.path.join(AIC_ROOT, 'kernel/rt-thread/')
|
|
rtt_root = os.path.normpath(rtt_root)
|
|
chip_dir = os.path.join(AIC_ROOT, 'bsp/artinchip/sys/' + PRJ_CHIP)
|
|
chip_dir = os.path.normpath(chip_dir)
|
|
prj_out_dir = os.path.join(AIC_ROOT, PRJ_OUT_DIR)
|
|
prj_out_dir = os.path.normpath(prj_out_dir)
|
|
|
|
# 2. make local sdk
|
|
AddOption('--target',
|
|
dest = 'target',
|
|
type = 'string',
|
|
help = 'Generate target project: sdk')
|
|
|
|
if GetOption('target') == 'sdk':
|
|
if not os.path.exists(sdk_path):
|
|
os.mkdir(sdk_path)
|
|
else:
|
|
shutil.rmtree(sdk_path)
|
|
os.mkdir(sdk_path)
|
|
# copy "sdk/rtconfig.h"
|
|
#print('Copy rtconfig.h...')
|
|
#src_f = os.path.join(AIC_ROOT, 'rtconfig.h')
|
|
#des_f = os.path.join(sdk_path, 'rtconfig.h')
|
|
#shutil.copy(src_f, des_f)
|
|
# copy "sdk/rtconfig.py"
|
|
print('Copy rtconfig.py...')
|
|
src_f = os.path.join(chip_dir, 'rtconfig.py')
|
|
des_f = os.path.join(sdk_path, 'rtconfig.py')
|
|
shutil.copy(src_f, des_f)
|
|
# copy "sdk/rtua.py"
|
|
print('Copy rtua.py...')
|
|
src_f = os.path.join(prj_out_dir, 'rtua.py')
|
|
des_f = os.path.join(sdk_path, 'rtua.py')
|
|
shutil.copy(src_f, des_f)
|
|
# create "sdk/kernel/rt-thread/" folder
|
|
des_d = os.path.join(sdk_path, 'kernel')
|
|
sdk_rtt_d = os.path.join(des_d, 'rt-thread')
|
|
sdk_bsp_d = sdk_path
|
|
if not os.path.exists(des_d):
|
|
os.makedirs(sdk_rtt_d)
|
|
else:
|
|
shutil.rmtree(des_d)
|
|
os.makedirs(sdk_rtt_d)
|
|
# copy "sdk/kernel/rt-thread/tools/"
|
|
print('Copy rt-thread/tools/...')
|
|
src_d = os.path.join(rtt_root, 'tools')
|
|
des_d = os.path.join(sdk_rtt_d, 'tools')
|
|
src_d = os.path.normpath(src_d);
|
|
des_d = os.path.normpath(des_d);
|
|
if not os.path.exists(des_d):
|
|
if platform.system() == 'Linux':
|
|
shutil.copytree(src_d, des_d)
|
|
elif platform.system() == 'Windows':
|
|
shutil.copytree('\\\\?\\' + src_d, '\\\\?\\' + des_d)
|
|
sys.path.append(src_d)
|
|
from utils import _make_path_relative
|
|
# copy project .h files
|
|
print('Copy project .h files...')
|
|
sys.path.append(prj_out_dir)
|
|
from rtua import GetCPPPATH
|
|
cpppaths = GetCPPPATH(bsp_root, rtt_root)
|
|
tmp_d = os.path.join(rtt_root, "components/legacy/ipc")
|
|
tmp_d = os.path.normpath(tmp_d);
|
|
cpppaths.append(tmp_d)
|
|
tmp_d = os.path.join(rtt_root, "components/drivers/include/ipc")
|
|
tmp_d = os.path.normpath(tmp_d);
|
|
cpppaths.append(tmp_d)
|
|
tmp_d = os.path.join(rtt_root, "components/drivers/include/drivers")
|
|
tmp_d = os.path.normpath(tmp_d);
|
|
cpppaths.append(tmp_d)
|
|
for src_d in cpppaths:
|
|
if src_d.startswith(bsp_root):
|
|
rel_d = _make_path_relative(bsp_root, src_d)
|
|
des_d = os.path.join(sdk_bsp_d, rel_d)
|
|
elif src_d.startswith(rtt_root):
|
|
rel_d = _make_path_relative(rtt_root, src_d)
|
|
des_d = os.path.join(sdk_rtt_d, rel_d)
|
|
else:
|
|
continue
|
|
src_d = os.path.normpath(src_d);
|
|
des_d = os.path.normpath(des_d);
|
|
try:
|
|
os.makedirs(des_d)
|
|
except:
|
|
pass
|
|
for f in glob.iglob(src_d + '/*.h'):
|
|
des_f = os.path.basename(f)
|
|
des_f = os.path.join(des_d, des_f)
|
|
shutil.copy(f, des_f)
|
|
# copy "tools/env/"
|
|
print('Copy tools/env/...')
|
|
src_d = os.path.join(AIC_ROOT, 'tools/env')
|
|
des_d = os.path.join(tools_path, 'env')
|
|
src_d = os.path.normpath(src_d);
|
|
des_d = os.path.normpath(des_d);
|
|
if os.path.exists(des_d):
|
|
shutil.rmtree(des_d)
|
|
if not os.path.exists(des_d):
|
|
if platform.system() == 'Linux':
|
|
shutil.copytree(src_d, des_d)
|
|
elif platform.system() == 'Windows':
|
|
shutil.copytree('\\\\?\\' + src_d, '\\\\?\\' + des_d)
|
|
# copy "tools/scripts/"
|
|
print('Copy tools/scripts/...')
|
|
src_d = os.path.join(AIC_ROOT, 'tools/scripts')
|
|
des_d = os.path.join(tools_path, 'scripts')
|
|
src_d = os.path.normpath(src_d);
|
|
des_d = os.path.normpath(des_d);
|
|
if os.path.exists(des_d):
|
|
shutil.rmtree(des_d)
|
|
if not os.path.exists(des_d):
|
|
if platform.system() == 'Linux':
|
|
shutil.copytree(src_d, des_d)
|
|
elif platform.system() == 'Windows':
|
|
shutil.copytree('\\\\?\\' + src_d, '\\\\?\\' + des_d)
|
|
# copy "tools/onestep.sh"
|
|
print('Copy onestep.sh...')
|
|
src_f = os.path.join(AIC_ROOT, 'tools/onestep.sh')
|
|
des_f = os.path.join(tools_path, 'onestep.sh')
|
|
if os.path.exists(des_f):
|
|
os.remove(des_f)
|
|
shutil.copy(src_f, des_f)
|
|
# copy "win_env.bat"
|
|
print('Copy win_env.bat...')
|
|
src_f = os.path.join(AIC_ROOT, 'win_env.bat')
|
|
des_f = os.path.join(cwd, 'win_env.bat')
|
|
if os.path.exists(des_f):
|
|
os.remove(des_f)
|
|
shutil.copy(src_f, des_f)
|
|
# copy "win_cmd.bat"
|
|
print('Copy win_cmd.bat...')
|
|
src_f = os.path.join(AIC_ROOT, 'win_cmd.bat')
|
|
des_f = os.path.join(cwd, 'win_cmd.bat')
|
|
if os.path.exists(des_f):
|
|
os.remove(des_f)
|
|
shutil.copy(src_f, des_f)
|
|
print('Build local sdk succeed!')
|
|
exit(0)
|
|
elif GetOption('target') == 'clean' or GetOption('target') == 'c':
|
|
# rm "sdk"
|
|
if os.path.exists(sdk_path):
|
|
shutil.rmtree(sdk_path)
|
|
# rm "tools/env/"
|
|
des_d = os.path.join(tools_path, 'env')
|
|
des_d = os.path.normpath(des_d);
|
|
if os.path.exists(des_d):
|
|
shutil.rmtree(des_d)
|
|
# rm "tools/scripts/"
|
|
des_d = os.path.join(tools_path, 'scripts')
|
|
des_d = os.path.normpath(des_d);
|
|
if os.path.exists(des_d):
|
|
shutil.rmtree(des_d)
|
|
# rm "tools/onestep.sh"
|
|
des_f = os.path.join(tools_path, 'onestep.sh')
|
|
if os.path.exists(des_f):
|
|
os.remove(des_f)
|
|
# rm "win_env.bat"
|
|
des_f = os.path.join(cwd, 'win_env.bat')
|
|
if os.path.exists(des_f):
|
|
os.remove(des_f)
|
|
# rm "win_cmd.bat"
|
|
des_f = os.path.join(cwd, 'win_cmd.bat')
|
|
if os.path.exists(des_f):
|
|
os.remove(des_f)
|
|
exit(0)
|
|
|
|
# check local sdk
|
|
if os.path.exists(sdk_path): # local dm-app sdk
|
|
# 3. local sdk paths
|
|
bsp_root = sdk_path
|
|
rtt_root = os.path.join(sdk_path, 'kernel', 'rt-thread')
|
|
chip_dir = sdk_path
|
|
prj_out_dir = os.path.join(tools_path, 'scripts')
|
|
|
|
if not os.path.exists(config_path) and not os.path.exists(sdk_path):
|
|
print('Error: no luban-lite sdk!')
|
|
exit(-1)
|
|
else:
|
|
# 4. check & prepare toolchain
|
|
toolchain_prefix = 'xpack-riscv-none-embed-gcc'
|
|
toolchain_suffix = '.tar.gz'
|
|
if platform.system() == 'Linux':
|
|
toolchain_mid = 'linux-x64'
|
|
elif platform.system() == 'Windows':
|
|
toolchain_mid = 'win32-x64'
|
|
toolchain_ppath = os.path.join(cwd, 'tools/toolchain/')
|
|
toolchain_ppath = os.path.normpath(toolchain_ppath)
|
|
ready_f = os.path.join(toolchain_path, '.ready')
|
|
if os.path.exists(ready_f):
|
|
with open(ready_f, 'r') as f:
|
|
toolchain_os = f.read()
|
|
if platform.system() != toolchain_os:
|
|
shutil.rmtree(toolchain_path)
|
|
if not os.path.exists(ready_f):
|
|
trim_tar = ''
|
|
full_tar = ''
|
|
for root, dirs, files in os.walk(toolchain_ppath):
|
|
if root != toolchain_ppath:
|
|
break
|
|
for f in files:
|
|
if f.startswith(toolchain_prefix) and f.endswith(toolchain_mid + '-trim' + toolchain_suffix):
|
|
trim_tar = f
|
|
elif f.startswith(toolchain_prefix) and f.endswith(toolchain_mid + toolchain_suffix):
|
|
full_tar = f
|
|
else:
|
|
continue
|
|
if trim_tar != '':
|
|
tar_f = trim_tar
|
|
elif full_tar != '':
|
|
tar_f = full_tar
|
|
else:
|
|
print("Coundn't find toolchain tar file.")
|
|
exit(0)
|
|
abs_f = os.path.join(toolchain_ppath, tar_f)
|
|
print('Extract toolchain ' + tar_f + ' ...')
|
|
if not os.path.exists(toolchain_path):
|
|
os.mkdir(toolchain_path)
|
|
os.system('tar -xzf ' + abs_f \
|
|
+ ' --strip-components 1 -C ' + toolchain_path)
|
|
with open(ready_f, 'w') as f:
|
|
f.write(platform.system())
|
|
|
|
# 5. compile dynamic module app
|
|
from tools.ua import BuildApplication
|
|
from tools.ua import BuildLibrary
|
|
|
|
AddOption('--app',
|
|
dest='app',
|
|
nargs=1, type='string',
|
|
action='store',
|
|
metavar='DIR',
|
|
help='application to be built')
|
|
|
|
AddOption('--lib',
|
|
dest='lib',
|
|
nargs=1, type='string',
|
|
action='store',
|
|
metavar='DIR',
|
|
help='library to be built')
|
|
|
|
app = GetOption('app')
|
|
lib = GetOption('lib')
|
|
|
|
if app == None and lib == None:
|
|
print("none application or library, please use ")
|
|
print(" scons --app=your_app")
|
|
print(" scons --lib=your_lib")
|
|
exit(0)
|
|
else:
|
|
if app:
|
|
BuildApplication(app + '/' + app + '.mo', app +'/SConscript', bsp_root, rtt_root, chip_dir, prj_out_dir)
|
|
|
|
if lib:
|
|
BuildLibrary(lib + '/' + lib + '.so', lib +'/SConscript', bsp_root, rtt_root, chip_dir, prj_out_dir)
|