summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-05-08 23:43:28 +0800
committerruki <[email protected]>2024-05-08 23:43:28 +0800
commiteed3d87b3d383ad6fe5055c56ec2ebaa872a3b9a (patch)
tree4e6113269231d2d1dc24c1c154e3b800aec41bd9
parentf7ee280ab5326abf641fe7bc1ebf12b31cf2423c (diff)
improve find gcc_ar
-rw-r--r--xmake/modules/detect/tools/find_ar.lua4
-rw-r--r--xmake/modules/detect/tools/find_gcc_ar.lua57
-rw-r--r--xmake/modules/lib/detect/find_toolname.lua19
3 files changed, 69 insertions, 11 deletions
diff --git a/xmake/modules/detect/tools/find_ar.lua b/xmake/modules/detect/tools/find_ar.lua
index f6b001f21..f7bf6db77 100644
--- a/xmake/modules/detect/tools/find_ar.lua
+++ b/xmake/modules/detect/tools/find_ar.lua
@@ -51,11 +51,7 @@ end
-- @endcode
--
function main(opt)
-
- -- init options
opt = opt or {}
opt.check = opt.check or _check
-
- -- find program
return find_program(opt.program or "ar", opt)
end
diff --git a/xmake/modules/detect/tools/find_gcc_ar.lua b/xmake/modules/detect/tools/find_gcc_ar.lua
new file mode 100644
index 000000000..54f467621
--- /dev/null
+++ b/xmake/modules/detect/tools/find_gcc_ar.lua
@@ -0,0 +1,57 @@
+--!A cross-platform build utility based on Lua
+--
+-- 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) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file find_gcc_ar.lua
+--
+
+-- imports
+import("lib.detect.find_program")
+
+-- check
+function _check(program)
+
+ -- make a stub object file
+ local libraryfile = os.tmpfile() .. ".a"
+ local objectfile = os.tmpfile() .. ".o"
+ io.writefile(objectfile, "")
+
+ -- archive it
+ os.runv(program, {"-cr", libraryfile, objectfile})
+
+ -- remove files
+ os.rm(objectfile)
+ os.rm(libraryfile)
+end
+
+-- find ar
+--
+-- @param opt the argument options, e.g. {version = true}
+--
+-- @return program, version
+--
+-- @code
+--
+-- local ar = find_gcc_ar()
+-- local ar, version = find_ar({program = "xcrun -sdk macosx g++", version = true})
+--
+-- @endcode
+--
+function main(opt)
+ opt = opt or {}
+ opt.check = opt.check or _check
+ return find_program(opt.program or "gcc-ar", opt)
+end
diff --git a/xmake/modules/lib/detect/find_toolname.lua b/xmake/modules/lib/detect/find_toolname.lua
index 8a9541031..3f8171a07 100644
--- a/xmake/modules/lib/detect/find_toolname.lua
+++ b/xmake/modules/lib/detect/find_toolname.lua
@@ -74,7 +74,7 @@ function _find(program)
end
-- get file name first
- name = path.filename(program):lower()
+ local name = path.filename(program):lower()
-- remove arguments: " -xxx" or " --xxx"
name = name:gsub("%s%-+%w+", " ")
@@ -93,16 +93,21 @@ function _find(program)
end
-- try last valid name: xxx-xxx-toolname-5
+ --
+ -- e.g.
+ -- arm-none-eabi-gcc-ar -> gcc_ar
+ -- arm-none-eabi-gcc -> gcc
local partnames = {}
for partname in name:gmatch("([%a%+]+)") do
table.insert(partnames, partname)
end
- if #partnames > 0 then
- name = partnames[#partnames]
- end
- toolname = name:gsub("%+", "x")
- if module.find("detect.tools.find_" .. toolname) then
- return toolname
+ while #partnames > 0 do
+ name = table.concat(partnames, "_")
+ table.remove(partnames, 1)
+ toolname = name:gsub("%+", "x")
+ if module.find("detect.tools.find_" .. toolname) then
+ return toolname
+ end
end
end