summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-12-19 23:16:16 +0800
committerruki <[email protected]>2024-12-19 13:37:55 +0800
commitbd435f07c33dc69ebe90c9a6b8ff54ef4518642f (patch)
treeb180cd0c35402041826bf0c7024b0e943ded9770
parent323eb11b3977f8d41848c2fea566738c9a91bdec (diff)
support include deps for tcc #5984
-rw-r--r--xmake/modules/core/tools/tcc.lua30
1 files changed, 26 insertions, 4 deletions
diff --git a/xmake/modules/core/tools/tcc.lua b/xmake/modules/core/tools/tcc.lua
index 0fbaa202b..98d81a998 100644
--- a/xmake/modules/core/tools/tcc.lua
+++ b/xmake/modules/core/tools/tcc.lua
@@ -144,15 +144,27 @@ 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() or nil
try
{
function ()
- local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, flags))
+
+ -- support `-MMD -MF depfile.d`? some old gcc does not support it at same time
+ if depfile and _g._HAS_MMD_MF == nil then
+ _g._HAS_MMD_MF = self:has_flags({"-MD", "-MF", os.nuldev()}, "cflags", { flagskey = "-MD -MF" }) or false
+ end
+
+ -- generate includes file
+ local compflags = flags
+ if depfile and _g._HAS_MMD_MF then
+ compflags = table.join(compflags, "-MD", "-MF", depfile)
+ end
+
+ -- do compile
+ local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, compflags))
return (outdata or "") .. (errdata or "")
end,
catch
@@ -190,6 +202,16 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
if warnings and #warnings > 0 and policy.build_warnings(opt) then
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
}
}