summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-08-28 22:41:25 +0800
committerruki <[email protected]>2023-08-28 22:41:25 +0800
commit1ec4357aa5a487ea6a1ae266fd9a94feba1b0760 (patch)
tree99b9d48a6c1c05b4fd787edcec52d88826117e15
parenta0e464bebf1ddd493ca33d381da399b12dfc8358 (diff)
improve to find emar
-rw-r--r--xmake/modules/detect/tools/find_emar.lua45
1 files changed, 28 insertions, 17 deletions
diff --git a/xmake/modules/detect/tools/find_emar.lua b/xmake/modules/detect/tools/find_emar.lua
index 5c09f9952..0a6ba4f7c 100644
--- a/xmake/modules/detect/tools/find_emar.lua
+++ b/xmake/modules/detect/tools/find_emar.lua
@@ -21,27 +21,12 @@
-- imports
import("core.tool.compiler")
import("lib.detect.find_program")
+import("lib.detect.find_tool")
import("detect.sdks.find_emsdk")
-- check
function _check(program)
- -- make an stub source file
- local libraryfile = os.tmpfile() .. ".a"
- local objectfile = os.tmpfile() .. ".o"
- local sourcefile = os.tmpfile() .. ".c"
- io.writefile(sourcefile, "int test(void)\n{return 0;}")
-
- -- compile it
- compiler.compile(sourcefile, objectfile)
-
- -- archive it
- os.runv(program, {"-cr", libraryfile, objectfile})
-
- -- remove files
- os.rm(objectfile)
- os.rm(sourcefile)
- os.rm(libraryfile)
end
-- find ar
@@ -61,7 +46,33 @@ function main(opt)
-- init options
opt = opt or {}
- opt.check = opt.check or _check
+ opt.check = opt.check or function (program)
+ local bindir = path.directory(program)
+ local filename = path.filename(program)
+ filename = filename:gsub("emar", "emcc")
+ local emcc_program = filename
+ if bindir and bindir ~= "." then
+ emcc_program = path.join(bindir, filename)
+ end
+ local emcc = assert(find_tool("emcc", {program = emcc_program, envs = opt.envs}), "emcc not found!")
+
+ -- make an stub source file
+ local libraryfile = os.tmpfile() .. ".a"
+ local objectfile = os.tmpfile() .. ".o"
+ local sourcefile = os.tmpfile() .. ".c"
+ io.writefile(sourcefile, "int test(void)\n{return 0;}")
+
+ -- compile it
+ os.runv(emcc.program, {"-c", "-o" .. objectfile, sourcefile}, {envs = opt.envs})
+
+ -- archive it
+ os.runv(program, {"-cr", libraryfile, objectfile}, {envs = opt.envs})
+
+ -- remove files
+ os.rm(objectfile)
+ os.rm(sourcefile)
+ os.rm(libraryfile)
+ end
-- init the search directories
local emsdk = find_emsdk()