1import os
2import sys
3import rtconfig
4from SCons.Script import *
5
6if os.getenv('RTT_ROOT'):
7    RTT_ROOT = os.getenv('RTT_ROOT')
8else:
9    RTT_ROOT = os.path.normpath(os.getcwd() + '/../../../..')
10
11sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
12try:
13    from building import *
14except:
15    print('Cannot found RT-Thread root directory, please check RTT_ROOT')
16    print(RTT_ROOT)
17    exit(-1)
18
19
20TARGET = 'rtthread.' + rtconfig.TARGET_EXT
21
22DefaultEnvironment(tools=[])
23env = Environment(tools = ['mingw'],
24    AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
25    CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS,
26    AR = rtconfig.AR, ARFLAGS = '-rc',
27    CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS,
28    LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
29env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
30
31if rtconfig.PLATFORM in ['iccarm']:
32    env.Replace(CCCOM = ['$CC $CFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -o $TARGET $SOURCES'])
33    env.Replace(ARFLAGS = [''])
34    env.Replace(LINKCOM = env["LINKCOM"] + ' --map project.map')
35
36Export('RTT_ROOT')
37Export('rtconfig')
38
39SDK_ROOT = os.path.abspath('./')
40
41if os.path.exists(SDK_ROOT + '/Libraries'):
42    libraries_path_prefix = SDK_ROOT + '/Libraries'
43else:
44    libraries_path_prefix = os.path.dirname(SDK_ROOT) + '/Libraries'
45
46SDK_LIB = libraries_path_prefix
47Export('SDK_LIB')
48
49# prepare building environment
50objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False)
51
52bsp_vdir = 'build'
53library_vdir = 'build/libraries'
54
55# common include drivers
56objs.extend(SConscript(os.path.join(libraries_path_prefix, 'ch32_drivers', 'SConscript'), variant_dir=library_vdir + '/ch32_drivers', duplicate=0))
57
58# make a building
59DoBuilding(TARGET, objs)
60