diff options
| author | ruki <[email protected]> | 2020-07-28 22:39:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-07-28 22:39:13 +0800 |
| commit | 3480e577e689dd0374963eaadf08283d760d0a5b (patch) | |
| tree | 22a920f3239d4f4ecf90425172487b342aa3d76e | |
| parent | 08eb918cbbeeabaff7a50a306d8e46f6e6d4544b (diff) | |
improve cross-compilation
| -rw-r--r-- | xmake/modules/detect/sdks/find_cross_toolchain.lua | 27 | ||||
| -rw-r--r-- | xmake/toolchains/cross/check.lua | 1 | ||||
| -rw-r--r-- | xmake/toolchains/gnu-rm/check.lua | 1 |
3 files changed, 20 insertions, 9 deletions
diff --git a/xmake/modules/detect/sdks/find_cross_toolchain.lua b/xmake/modules/detect/sdks/find_cross_toolchain.lua index 9e4e851e0..7082d2625 100644 --- a/xmake/modules/detect/sdks/find_cross_toolchain.lua +++ b/xmake/modules/detect/sdks/find_cross_toolchain.lua @@ -78,17 +78,26 @@ function main(sdkdir, opt) -- init arguments opt = opt or {} - -- get root directory - if not sdkdir or not os.isdir(sdkdir) then - return + -- get sdk directories + local sdkdirs = {} + if sdkdir then + table.insert(sdkdirs, sdkdir) + elseif opt.cross and not is_subhost("windows") then + -- we attempt to find cross toolchain from /usr, e.g. /usr/bin/aarch64-linux-gnu-gcc + table.insert(sdkdirs, "/usr/") + table.insert(sdkdirs, "/usr/local") end -- find bin directory and cross - local bindir, cross = _find_bindir(sdkdir, opt) - if not bindir then - return + local result + for _, _sdkdir in ipairs(sdkdirs) do + if os.isdir(_sdkdir) then + local bindir, cross = _find_bindir(_sdkdir, opt) + if bindir then + result = {sdkdir = _sdkdir, bindir = bindir, cross = cross} + break + end + end end - - -- found - return {sdkdir = sdkdir, bindir = bindir, cross = cross} + return result end diff --git a/xmake/toolchains/cross/check.lua b/xmake/toolchains/cross/check.lua index 34b62ccc0..436dc6076 100644 --- a/xmake/toolchains/cross/check.lua +++ b/xmake/toolchains/cross/check.lua @@ -38,6 +38,7 @@ function main(toolchain) if cross_toolchain then config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + config.set("sdkdir", cross_toolchain.sdkdir, {readonly = true, force = true}) else raise("cross toolchain not found!") end diff --git a/xmake/toolchains/gnu-rm/check.lua b/xmake/toolchains/gnu-rm/check.lua index 34b62ccc0..436dc6076 100644 --- a/xmake/toolchains/gnu-rm/check.lua +++ b/xmake/toolchains/gnu-rm/check.lua @@ -38,6 +38,7 @@ function main(toolchain) if cross_toolchain then config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + config.set("sdkdir", cross_toolchain.sdkdir, {readonly = true, force = true}) else raise("cross toolchain not found!") end |
