summaryrefslogtreecommitdiff
path: root/xmake/modules/detect
diff options
context:
space:
mode:
authorDawnManget <[email protected]>2022-05-10 10:45:43 +0800
committerDawnManget <[email protected]>2022-05-10 10:45:43 +0800
commit8d0fb42d11874dd59bac82b45d1ca81e0df01780 (patch)
treefd0e8c7db3ee43fc434fe089cf56f0eeed261fa6 /xmake/modules/detect
parenta0a57a74cc301468d21f11cd5d78a272cce561b5 (diff)
review: add keil-c51 toolchain & rules
Diffstat (limited to 'xmake/modules/detect')
-rw-r--r--xmake/modules/detect/tools/find_bl51.lua25
-rw-r--r--xmake/modules/detect/tools/find_c51.lua28
-rw-r--r--xmake/modules/detect/tools/find_oh51.lua33
3 files changed, 32 insertions, 54 deletions
diff --git a/xmake/modules/detect/tools/find_bl51.lua b/xmake/modules/detect/tools/find_bl51.lua
index d44a1eb3c..001d1ed13 100644
--- a/xmake/modules/detect/tools/find_bl51.lua
+++ b/xmake/modules/detect/tools/find_bl51.lua
@@ -21,30 +21,23 @@
import("lib.detect.find_program")
import("lib.detect.find_programver")
import("detect.sdks.find_c51")
+import("lib.detect.find_tool")
function _check(program)
- import("detect.tools.find_c51")
+ local c51 = assert(find_tool("c51"), "c51 not found")
-- make temp source file
- local c51 = assert(find_c51())
- local temp_prefix = os.tmpfile()
- local cfile = temp_prefix .. ".c"
- local objfile = temp_prefix .. ".obj"
- local lstfile = temp_prefix .. ".lst"
- local tmpfile = "." .. temp_prefix .. ".un~"
- local binfile = temp_prefix .. ""
- local m51file = temp_prefix .. ".m51"
+ local tmpdir = os.tmpfile()
+ os.mkdir(tmpdir)
+ local cfile = path.join(tmpdir, "test.c")
+ local objfile = path.join(tmpdir, "test.obj")
+ local binfile = path.join(tmpdir, "test")
-- write test code
io.writefile(cfile, "void main() {}")
-- archive it
- os.runv(c51, {cfile})
+ os.runv(c51.program, {cfile})
os.runv(program, {objfile, "TO", binfile})
-- remove files
- os.rm(cfile)
- os.rm(objfile)
- os.rm(lstfile)
- os.rm(tmpfile)
- os.rm(binfile)
- os.rm(m51file)
+ os.rmdir(tmpdir)
end
-- find bl51
--
diff --git a/xmake/modules/detect/tools/find_c51.lua b/xmake/modules/detect/tools/find_c51.lua
index 954f03df6..616b81a4d 100644
--- a/xmake/modules/detect/tools/find_c51.lua
+++ b/xmake/modules/detect/tools/find_c51.lua
@@ -21,23 +21,19 @@
-- imports
import("lib.detect.find_program")
import("lib.detect.find_programver")
-local c51_module = import("detect.sdks.find_c51")
+import("detect.sdks.find_c51")
function _check(program)
-- make temp source file
- local cfile = os.tmpfile() .. ".c"
- local objfile = os.tmpfile() .. ".obj"
- local lstfile = os.tmpfile() .. ".c"
- local tmpfile = "." .. os.tmpfile() .. ".un~"
+ local tmpdir = os.tmpfile()
+ os.mkdir(tmpdir)
+ local cfile = path.join(tmpdir, "test.c")
-- write test code
io.writefile(cfile, "void main() {}")
-- archive it
os.runv(program, {cfile})
-- remove files
- os.rm(cfile)
- os.rm(objfile)
- os.rm(lstfile)
- os.rm(tmpfile)
+ os.rmdir(tmpdir)
end
-- find c51
--
@@ -57,15 +53,15 @@ function main(opt)
-- init options
opt = opt or {}
opt.check = opt.check or _check
- local program = find_program(opt.program or "c51.exe", opt)
+ local program = find_program(opt.program or "c51", opt)
if not program then
- local c51_module = c51_module.find_c51()
- if c51_module then
- if c51_module.sdkdir_c51 then
- program = find_program(path.join(c51_module.sdkdir_c51, "bin", "c51.exe"), opt)
+ local c51 = find_c51()
+ if c51 then
+ if c51.sdkdir_c51 then
+ program = find_program(path.join(c51.sdkdir_c51, "bin", "c51"), opt)
end
- if not program and c51_module.sdkdir_a51 then
- program = find_program(path.join(c51_module.sdkdir_a51, "bin", "c51.exe"), opt)
+ if not program and c51.sdkdir_a51 then
+ program = find_program(path.join(c51.sdkdir_a51, "bin", "c51"), opt)
end
end
end
diff --git a/xmake/modules/detect/tools/find_oh51.lua b/xmake/modules/detect/tools/find_oh51.lua
index df2a985b8..dc3310efe 100644
--- a/xmake/modules/detect/tools/find_oh51.lua
+++ b/xmake/modules/detect/tools/find_oh51.lua
@@ -22,36 +22,25 @@
import("lib.detect.find_program")
import("lib.detect.find_programver")
import("detect.sdks.find_c51")
+import("lib.detect.find_tool")
function _check(program)
- import("detect.tools.find_c51")
- import("detect.tools.find_bl51")
-
+ local c51 = assert(find_tool("c51"), "c51 not found")
+ local bl51 = assert(find_tool("bl51"), "bl51 not found")
-- make temp source file
- local c51 = assert(find_c51())
- local bl51 = assert(find_bl51())
- local temp_prefix = os.tmpfile()
- local cfile = temp_prefix .. ".c"
- local objfile = temp_prefix .. ".obj"
- local lstfile = temp_prefix .. ".lst"
- local tmpfile = "." .. temp_prefix .. ".un~"
- local binfile = temp_prefix .. ""
- local m51file = temp_prefix .. ".m51"
- local hexfile = temp_prefix .. ".hex"
+ local tmpdir = os.tmpfile()
+ os.mkdir(tmpdir)
+ local cfile = path.join(tmpdir, "test.c")
+ local objfile = path.join(tmpdir, "test.obj")
+ local binfile = path.join(tmpdir, "test")
-- write test code
io.writefile(cfile, "void main() {}")
-- archive it
- os.runv(c51, {cfile})
- os.runv(bl51, {objfile, "TO", binfile})
+ os.runv(c51.program, {cfile})
+ os.runv(bl51.program, {objfile, "TO", binfile})
os.runv(program, {binfile})
-- remove files
- os.rm(cfile)
- os.rm(objfile)
- os.rm(lstfile)
- os.rm(tmpfile)
- os.rm(binfile)
- os.rm(m51file)
- os.rm(hexfile)
+ os.rmdir(tmpdir)
end
-- find oh51
--