summaryrefslogtreecommitdiff
path: root/bsp/phytium/aarch32/SConstruct
blob: 7283e357344e5d0b92c625b90fde205d71b7a47b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import sys
import rtconfig
import subprocess

IS_EXPORTED = False

# setup RT-Thread Root Path
if os.getenv('RTT_ROOT'):
    RTT_ROOT = os.getenv('RTT_ROOT')
else:
    RTT_ROOT = os.getcwd() + '/../../..'

sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
try:
    from building import *
except:
    print('Cannot found RT-Thread root directory, please check RTT_ROOT')
    print(RTT_ROOT)
    exit(-1)

if RTT_ROOT == 'rt-thread':
    IS_EXPORTED = True # if kenrel and bsp has been exported by export_project.py

# setup Phytium BSP Root Path
if IS_EXPORTED:
    BSP_ROOT = '.'
else:
    BSP_ROOT = RTT_ROOT + '/bsp/phytium'

TARGET = 'rtthread_a32.' + rtconfig.TARGET_EXT

DefaultEnvironment(tools=[])
env = Environment(tools = ['mingw'],
    AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
    CC = rtconfig.CC, CFLAGS = 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']

os.environ["BSP_ROOT"] = BSP_ROOT
os.environ["SDK_DIR"] = os.path.join(BSP_ROOT,'libraries','phytium_standalone_sdk')

Export('RTT_ROOT')
Export('BSP_ROOT')
Export('rtconfig')

def is_phytium_sdk_installed():
    py_target_folder = os.getcwd() + "/../libraries/phytium_standalone_sdk"
    return os.path.exists(py_target_folder)

def install_phytium_sdk():
    if is_phytium_sdk_installed():
        return 0

    install_script_path = os.getcwd() + "/../libraries/phytium_standalone_sdk_install.py"

    if os.path.exists(install_script_path):
        try:
            subprocess.call(["python", install_script_path])
        except:
            subprocess.call(["python3", install_script_path])
        
        if not is_phytium_sdk_installed():
            print("Error: phytium_standalone_sdk install failed")
            exit(0)
    else:
        print("Error: phytium_standalone_sdk_install.py is not exists, exit compilation")
        exit(0)
            
install_phytium_sdk()

# prepare building environment
objs = PrepareBuilding(env, RTT_ROOT, has_libcpu = False)

if not IS_EXPORTED: # if project is not exported, libraries and board need to manually add
    # include libraries
    objs.extend(SConscript(os.path.join(BSP_ROOT + '/libraries', 'SConscript')))

    # include board
    objs.extend(SConscript(os.path.join(BSP_ROOT + '/board', 'SConscript')))

if GetDepend('RT_USING_SMART'):
    # use smart link.lds
    env['LINKFLAGS'] = env['LINKFLAGS'].replace('link.lds', 'link_smart.lds')

# make a building
DoBuilding(TARGET, objs)