forked from RT-Thread/userapps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrtflags.lua
More file actions
169 lines (142 loc) · 4.98 KB
/
rtflags.lua
File metadata and controls
169 lines (142 loc) · 4.98 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
-- Licensed under the Apache License, Version 2.0 (the "License");
-- You may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- Copyright (C) 2023-2023 RT-Thread Development Team
--
-- @author xqyjlj
-- @file rtflags.lua
--
-- Change Logs:
-- Date Author Notes
-- ------------ ---------- -----------------------------------------------
-- 2023-05-09 xqyjlj initial version
--
import("rt.rt_utils")
import("core.project.config")
function get_real_toolchains(toolchains)
toolchains = string.gsub(toolchains, "@", "")
return toolchains
end
function get_real_arch(toolchains)
local arch = config.arch()
if arch == "arm64" then
arch = "aarch64"
end
return arch
end
function get_ldscripts(shared)
if config.get("target_os") ~= "rt-smart" then
return {ldflags = {}}
end
local ldflags = {}
if not shared then
table.insert(ldflags, "--static")
end
return {ldflags = ldflags}
end
function get_sdk()
if config.get("target_os") ~= "rt-smart" then
return {ldflags = {}, ldflags_lib = {}, cxflags = {}}
end
local sdkdir = rt_utils.sdk_dir()
local arch = get_real_arch()
local rtdir = path.join(sdkdir, "rt-thread")
local incdir = path.join(sdkdir, "include")
local libdir = path.join(sdkdir, "lib")
local cxflags = {}
local ldflags_lib = {}
local ldflags = {}
if arch == "arm" then
arch = "arm/cortex-a"
elseif arch == "aarch64" then
arch = "aarch64/cortex-a"
elseif arch == "riscv64gc" then
arch = "risc-v/rv64gc/lp64"
elseif arch == "riscv64gcv" then
arch = "risc-v/rv64gcv/lp64"
elseif arch == "xuantie" then
arch = "risc-v/rv64gc/lp64d"
end
table.insert(cxflags, "-DHAVE_CCONFIG_H")
if os.isdir(incdir) then
table.insert(cxflags, "-I" .. incdir)
end
table.insert(cxflags, "-I" .. path.join(rtdir, "include"))
table.insert(cxflags, "-I" .. path.join(rtdir, "components", "dfs"))
table.insert(cxflags, "-I" .. path.join(rtdir, "components", "drivers"))
table.insert(cxflags, "-I" .. path.join(rtdir, "components", "finsh"))
table.insert(cxflags, "-I" .. path.join(rtdir, "components", "net"))
if os.isdir(libdir) then
table.insert(ldflags, "-L" .. libdir)
table.insert(ldflags, "-L" .. path.join(libdir, arch))
end
table.insert(ldflags_lib, "-L" .. libdir)
table.insert(ldflags_lib, "-L" .. path.join(libdir, arch))
table.insert(ldflags, "-L" .. path.join(rtdir, "lib", arch))
table.insert(ldflags, "-Wl,--start-group")
table.insert(ldflags, "-Wl,-whole-archive")
table.insert(ldflags, "-lrtthread")
table.insert(ldflags, "-Wl,-no-whole-archive")
table.insert(ldflags, "-Wl,--end-group")
return {ldflags = ldflags, ldflags_lib = ldflags_lib, cxflags = cxflags}
end
function get_package_info(package)
local rtn = {}
rtn.toolchains = get_real_toolchains(package:configs().toolchains)
rtn.version = package:version_str()
rtn.cc, _ = package:tool("cc")
rtn.cxx, _ = package:tool("cxx")
rtn.arch = get_real_arch()
rtn.toolchainsdir = path.directory(rtn.cc)
rtn.host = string.gsub(path.basename(rtn.cc), "smart", "linux") -- TODO: should replace, when toolchains renamed
rtn.host = string.gsub(rtn.host, "-gcc", "")
if rtn.arch == "aarch64" then
rtn.cpu = "armv8-a"
elseif rtn.arch == "arm" then
rtn.cpu = "armv7-a"
elseif rtn.arch == "x86_64" then
rtn.cpu = "generic64"
else
rtn.cpu = ""
end
vprint(rtn)
return rtn
end
function get_target_info(target)
local rtn = {}
rtn.toolchains = get_real_toolchains(target:get("toolchains"))
rtn.host = rtn.toolchains
if config.get("target_os") == "rt-smart" then
if string.startswith(rtn.toolchains, "riscv64") then
rtn.host = "riscv64-unknown-smart-musl"
end
end
rtn.host = string.gsub(rtn.host, "smart", "linux") -- TODO: should replace, when toolchains renamed
rtn.cc, _ = target:tool("cc")
rtn.cxx, _ = target:tool("cxx")
rtn.arch = get_real_arch()
rtn.toolchainsdir = path.directory(rtn.cc)
if rtn.arch == "aarch64" then
rtn.cpu = "armv8-a"
end
local instance = target:toolchain(rtn.toolchains)
rtn.cxflags = instance:get("cxflags") or {}
rtn.ldflags = instance:get("ldflags") or {}
if type(rtn.cxflags) == "string" then
rtn.cxflags = {rtn.cxflags}
end
if type(rtn.ldflags) == "string" then
rtn.ldflags = {rtn.ldflags}
end
vprint(rtn)
return rtn
end