Skip to content

Commit

Permalink
support include deps for tcc #5984
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Dec 19, 2024
1 parent 323eb11 commit bd435f0
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions xmake/modules/core/tools/tcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit bd435f0

Please sign in to comment.