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