From 3d9eda6bf206d4bbcccc840c1f3ba477aefcbfc5 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 12 May 2020 00:42:16 +0800 Subject: improve find_cross_toolchain --- xmake/modules/detect/sdks/find_cross_toolchain.lua | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/xmake/modules/detect/sdks/find_cross_toolchain.lua b/xmake/modules/detect/sdks/find_cross_toolchain.lua index 8c70e0b87..86fd829a1 100644 --- a/xmake/modules/detect/sdks/find_cross_toolchain.lua +++ b/xmake/modules/detect/sdks/find_cross_toolchain.lua @@ -33,17 +33,21 @@ function _find_bindir(sdkdir, opt) table.insert(bindirs, path.join(sdkdir, "bin")) table.insert(bindirs, path.join(sdkdir, "**", "bin")) - -- attempt to find *-ld - local ldname = is_host("windows") and "ld.exe" or "ld" - local ldpath = find_file((opt.cross or '*-') .. ldname, bindirs) - if ldpath then - return path.directory(ldpath), path.basename(ldpath):sub(1, -3) - end - - -- find ld - ldpath = find_file(ldname, bindirs) - if ldpath then - return path.directory(ldpath), "" + -- attempt to find *-[gcc|clang|ld] + for _, toolname in ipairs({"gcc", "clang", "ld"}) do + if is_plat("windows") then + toolname = toolname .. ".exe" + end + local toolpath = find_file((opt.cross or '*-') .. toolname, bindirs) + if toolpath then + return path.directory(toolpath), path.filename(toolpath):sub(1, -(#toolname + 1)) + end + + -- find tool path + toolpath = find_file(toolname, bindirs) + if toolpath then + return path.directory(toolpath), "" + end end -- attempt to use the bin directory -- cgit v1.3.1