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 = 'rtthread.' + 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    LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
26env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
27
28if rtconfig.PLATFORM in ['iccarm']:
29    env.Replace(CCCOM = ['$CC $CFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -o $TARGET $SOURCES'])
30    env.Replace(ARFLAGS = [''])
31    env.Replace(LINKCOM = env["LINKCOM"] + ' --map project.map')
32
33Export('env')
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
50# include cmsis
51objs.extend(SConscript(os.path.join(libraries_path_prefix, 'CMSIS', 'SConscript')))
52
53# include usb libraries
54objs.extend(SConscript(os.path.join(libraries_path_prefix, 'usbd_library', 'SConscript')))
55
56# include drivers
57objs.extend(SConscript(os.path.join(libraries_path_prefix, 'rt_drivers', 'SConscript')))
58
59# make a building
60DoBuilding(TARGET, objs)
61