summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-10-15 21:08:56 +0800
committerGitHub <[email protected]>2024-10-15 21:08:56 +0800
commit794b3c0f5ed3e77add8119f37c638b4fecafacd6 (patch)
treee93254cec96402377d18491d9b8a54250ba730ed
parentfcc2809210622102cdc0ec64256ff656b51eb509 (diff)
parentc772703a9cca7584c80b684dc0d24f51e53bfb8d (diff)
Merge pull request #5715 from xmake-io/sdcc
Support include deps for sdcc
-rw-r--r--xmake/modules/core/tools/gcc.lua5
-rw-r--r--xmake/modules/core/tools/sdcc.lua29
-rw-r--r--xmake/plugins/pack/batchcmds.lua1
-rw-r--r--xmake/toolchains/sdcc/check.lua6
-rw-r--r--xmake/toolchains/sdcc/xmake.lua14
5 files changed, 30 insertions, 25 deletions
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index c04d06e8a..ebc553117 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 ee5ffbb79..6cbec5d43 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
}
}
diff --git a/xmake/plugins/pack/batchcmds.lua b/xmake/plugins/pack/batchcmds.lua
index bf81ddc43..6b249b1a0 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")
diff --git a/xmake/toolchains/sdcc/check.lua b/xmake/toolchains/sdcc/check.lua
index 18f9a7f99..2d0b32154 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 18dc595ff..e8d45fca6 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