Skip to content

Commit bd435f0

Browse files
committed
support include deps for tcc #5984
1 parent 323eb11 commit bd435f0

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

xmake/modules/core/tools/tcc.lua

+26-4
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,27 @@ end
144144

145145
-- compile the source file
146146
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
147-
148-
-- ensure the object directory
147+
opt = opt or {}
149148
os.mkdir(path.directory(objectfile))
150149

151-
-- compile it
150+
local depfile = dependinfo and os.tmpfile() or nil
152151
try
153152
{
154153
function ()
155-
local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, flags))
154+
155+
-- support `-MMD -MF depfile.d`? some old gcc does not support it at same time
156+
if depfile and _g._HAS_MMD_MF == nil then
157+
_g._HAS_MMD_MF = self:has_flags({"-MD", "-MF", os.nuldev()}, "cflags", { flagskey = "-MD -MF" }) or false
158+
end
159+
160+
-- generate includes file
161+
local compflags = flags
162+
if depfile and _g._HAS_MMD_MF then
163+
compflags = table.join(compflags, "-MD", "-MF", depfile)
164+
end
165+
166+
-- do compile
167+
local outdata, errdata = os.iorunv(compargv(self, sourcefile, objectfile, compflags))
156168
return (outdata or "") .. (errdata or "")
157169
end,
158170
catch
@@ -190,6 +202,16 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
190202
if warnings and #warnings > 0 and policy.build_warnings(opt) then
191203
cprint("${color.warning}%s", table.concat(table.slice(warnings:split('\n'), 1, 8), '\n'))
192204
end
205+
206+
-- generate the dependent includes
207+
if depfile and os.isfile(depfile) then
208+
if dependinfo then
209+
dependinfo.depfiles_gcc = io.readfile(depfile, {continuation = "\\"})
210+
end
211+
212+
-- remove the temporary dependent file
213+
os.tryrm(depfile)
214+
end
193215
end
194216
}
195217
}

0 commit comments

Comments
 (0)