mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-07 00:59:00 +08:00
Previously, `scons -c` did not clean up the build directory and the automatically generated link.lds.generated. This is fixed now. Signed-off-by: Chen Wang <unicorn_wang@outlook.com>
62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
import os
|
|
import sys
|
|
import rtconfig
|
|
import platform
|
|
import subprocess
|
|
|
|
from rtconfig import RTT_ROOT
|
|
import sys
|
|
|
|
def generate_ldscript(input, output):
|
|
|
|
if not os.path.exists(input):
|
|
print('Error: file', input, 'not found')
|
|
return
|
|
|
|
if os.path.exists(output):
|
|
os.remove(output)
|
|
|
|
if rtconfig.PLATFORM == 'gcc':
|
|
|
|
gcc_cmd = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC)
|
|
|
|
# gcc -E -P -x c $input -o $output
|
|
if (platform.system() == 'Windows'):
|
|
child = subprocess.Popen([gcc_cmd, '-E', '-P', '-x', 'c', input, '-o', output], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
|
else:
|
|
child = subprocess.Popen(gcc_cmd + f' -E -P -x c {input} -o {output}', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
|
|
|
child.communicate()
|
|
|
|
print(output, 'is generated from', input)
|
|
|
|
|
|
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
|
|
from building import *
|
|
|
|
TARGET = 'rtthread.' + rtconfig.TARGET_EXT
|
|
|
|
DefaultEnvironment(tools=[])
|
|
env = Environment(tools = ['mingw'],
|
|
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
|
|
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
|
|
CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
|
|
AR = rtconfig.AR, ARFLAGS = '-rc',
|
|
LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
|
|
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
|
|
env['ASCOM'] = env['ASPPCOM']
|
|
|
|
Export('RTT_ROOT')
|
|
Export('rtconfig')
|
|
|
|
# prepare building environment
|
|
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)
|
|
|
|
generate_ldscript('link.lds', 'link.lds.generated')
|
|
|
|
# make a building
|
|
DoBuilding(TARGET, objs)
|
|
|
|
Clean(TARGET, 'link.lds.generated')
|
|
Clean(TARGET, 'build')
|