|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import rtconfig |
| 4 | + |
| 5 | +if os.getenv('RTT_ROOT'): |
| 6 | + RTT_ROOT = os.getenv('RTT_ROOT') |
| 7 | +else: |
| 8 | + RTT_ROOT = os.path.normpath(os.getcwd() + '/../../../..') |
| 9 | + |
| 10 | +sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')] |
| 11 | +try: |
| 12 | + from building import * |
| 13 | +except: |
| 14 | + print('Cannot found RT-Thread root directory, please check RTT_ROOT') |
| 15 | + print(RTT_ROOT) |
| 16 | + exit(-1) |
| 17 | + |
| 18 | +def bsp_pkg_check(): |
| 19 | + import subprocess |
| 20 | + |
| 21 | + check_paths = [ |
| 22 | + os.path.join("packages", "gd32-arm-cmsis-latest"), |
| 23 | + os.path.join("packages", "gd32-arm-series-latest") |
| 24 | + ] |
| 25 | + |
| 26 | + need_update = not all(os.path.exists(p) for p in check_paths) |
| 27 | + |
| 28 | + if need_update: |
| 29 | + print("\n===============================================================================") |
| 30 | + print("Dependency packages missing, please running 'pkgs --update'...") |
| 31 | + print("If no packages are fetched, run 'pkgs --upgrade' first, then 'pkgs --update'...") |
| 32 | + print("===============================================================================") |
| 33 | + exit(1) |
| 34 | + |
| 35 | +RegisterPreBuildingAction(bsp_pkg_check) |
| 36 | + |
| 37 | +TARGET = 'rt-thread.' + rtconfig.TARGET_EXT |
| 38 | + |
| 39 | +DefaultEnvironment(tools=[]) |
| 40 | +env = Environment(tools = ['mingw'], |
| 41 | + AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS, |
| 42 | + CC = rtconfig.CC, CFLAGS = rtconfig.CFLAGS, |
| 43 | + AR = rtconfig.AR, ARFLAGS = '-rc', |
| 44 | + CXX = rtconfig.CXX, CXXFLAGS = rtconfig.CXXFLAGS, |
| 45 | + LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS) |
| 46 | +env.PrependENVPath('PATH', rtconfig.EXEC_PATH) |
| 47 | + |
| 48 | +if rtconfig.PLATFORM in ['iccarm']: |
| 49 | + env.Replace(CCCOM = ['$CC $CFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -o $TARGET $SOURCES']) |
| 50 | + env.Replace(ARFLAGS = ['']) |
| 51 | + env.Replace(LINKCOM = env["LINKCOM"] + ' --map rt-thread.map') |
| 52 | + |
| 53 | +Export('env') |
| 54 | +Export('RTT_ROOT') |
| 55 | +Export('rtconfig') |
| 56 | + |
| 57 | +SDK_ROOT = os.path.abspath('./') |
| 58 | + |
| 59 | +if os.path.exists(SDK_ROOT + '/libraries'): |
| 60 | + libraries_path_prefix = SDK_ROOT + '/libraries' |
| 61 | +else: |
| 62 | + libraries_path_prefix = os.path.dirname(SDK_ROOT) + '/libraries' |
| 63 | + |
| 64 | +SDK_LIB = libraries_path_prefix |
| 65 | +Export('SDK_LIB') |
| 66 | + |
| 67 | +# prepare building environment |
| 68 | +objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False) |
| 69 | + |
| 70 | +# include libraries |
| 71 | +objs.extend(SConscript(os.path.join(libraries_path_prefix, 'gd32_drivers', 'SConscript'))) |
| 72 | + |
| 73 | +# make a building |
| 74 | +DoBuilding(TARGET, objs) |
0 commit comments