From e0017bacc10923be9f179fce68aeb6cee971ef4a Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 15 Oct 2024 00:51:31 +0800 Subject: [PATCH 1/3] improve to checkout sdcc --- xmake/toolchains/sdcc/check.lua | 6 +++--- xmake/toolchains/sdcc/xmake.lua | 14 ++------------ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/xmake/toolchains/sdcc/check.lua b/xmake/toolchains/sdcc/check.lua index 18f9a7f9989..2d0b32154be 100644 --- a/xmake/toolchains/sdcc/check.lua +++ b/xmake/toolchains/sdcc/check.lua @@ -20,6 +20,7 @@ -- imports import("core.project.config") +import("lib.detect.find_tool") import("detect.sdks.find_cross_toolchain") -- check the cross toolchain @@ -31,8 +32,7 @@ function main(toolchain) toolchain:config_set("cross", cross_toolchain.cross) toolchain:config_set("bindir", cross_toolchain.bindir) toolchain:configs_save() - else - raise("sdcc toolchain not found!") + return true end - return cross_toolchain + return find_tool("sdcc") end diff --git a/xmake/toolchains/sdcc/xmake.lua b/xmake/toolchains/sdcc/xmake.lua index 18dc595ffc3..e8d45fca6d4 100644 --- a/xmake/toolchains/sdcc/xmake.lua +++ b/xmake/toolchains/sdcc/xmake.lua @@ -18,17 +18,11 @@ -- @file xmake.lua -- --- define toolchain toolchain("sdcc") - - -- set homepage + set_kind("standalone") set_homepage("http://sdcc.sourceforge.net/") set_description("Small Device C Compiler") - -- mark as standalone toolchain - set_kind("standalone") - - -- set toolset set_toolset("cc", "sdcc") set_toolset("cxx", "sdcc") set_toolset("cpp", "sdcpp") @@ -37,22 +31,18 @@ toolchain("sdcc") set_toolset("sh", "sdcc") set_toolset("ar", "sdar") - -- set archs set_archs("stm8", "mcs51", "z80", "z180", "r2k", "r3ka", "s08", "hc08") - -- set formats set_formats("static", "$(name).lib") set_formats("object", "$(name).rel") set_formats("binary", "$(name).bin") set_formats("symbol", "$(name).sym") - -- check toolchain on_check("check") - -- on load on_load(function (toolchain) local arch = toolchain:arch() - if arch then + if arch and arch ~= "none" then toolchain:add("cxflags", "-m" .. arch) toolchain:add("ldflags", "-m" .. arch) end From 7fa81fa0ac749aae01627daf073e195c1e917d1a Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 15 Oct 2024 00:55:31 +0800 Subject: [PATCH 2/3] support to parse include deps for sdcc --- xmake/modules/core/tools/gcc.lua | 5 +---- xmake/modules/core/tools/sdcc.lua | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index c04d06e8a41..ebc5531174f 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -866,12 +866,9 @@ end -- compile the source file function compile(self, sourcefile, objectfile, dependinfo, flags, opt) - - -- ensure the object directory + opt = opt or {} os.mkdir(path.directory(objectfile)) - -- compile it - opt = opt or {} local depfile = dependinfo and os.tmpfile() or nil try { diff --git a/xmake/modules/core/tools/sdcc.lua b/xmake/modules/core/tools/sdcc.lua index ee5ffbb7937..6cbec5d43db 100644 --- a/xmake/modules/core/tools/sdcc.lua +++ b/xmake/modules/core/tools/sdcc.lua @@ -183,15 +183,23 @@ end -- compile the source file function compile(self, sourcefile, objectfile, dependinfo, flags, opt) - - -- ensure the object directory + opt = opt or {} os.mkdir(path.directory(objectfile)) - -- compile it + local depfile = dependinfo and os.tmpfile() .. ".rel" or nil try { function () - local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, flags)) + + -- generate includes file + local compflags = flags + if depfile then + compflags = table.join(compflags, "-M") + end + os.iorunv(compargv(self, sourcefile, depfile, compflags)) + + -- do compile + outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, flags)) return (outdata or "") .. (errdata or "") end, catch @@ -217,7 +225,6 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) errors = table.concat(table.slice(lines, start, start + ((#lines - start > 16) and 16 or (#lines - start))), "\n") end - -- raise compiling errors raise(errors) end }, @@ -225,13 +232,23 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) { function (ok, warnings) - -- print some warnings + -- show warnings if warnings and #warnings > 0 and policy.build_warnings(opt) then if progress.showing_without_scroll() then print("") end cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n')) end + + -- generate the dependent includes + if depfile and os.isfile(depfile) then + if dependinfo then + dependinfo.depfiles_gcc = io.readfile(depfile, {continuation = "\\"}) + end + + -- remove the temporary dependent file + os.tryrm(depfile) + end end } } From c772703a9cca7584c80b684dc0d24f51e53bfb8d Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 16 Oct 2024 00:31:15 +0800 Subject: [PATCH 3/3] fix project.policy --- xmake/plugins/pack/batchcmds.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua index bf81ddc4327..6b249b1a087 100644 --- a/xmake/plugins/pack/batchcmds.lua +++ b/xmake/plugins/pack/batchcmds.lua @@ -21,6 +21,7 @@ -- imports import("core.base.option") import("core.base.hashset") +import("core.project.project") import("utils.archive") import("utils.binary.deplibs", {alias = "get_depend_libraries"}) import("private.utils.batchcmds")