@@ -144,15 +144,27 @@ end
144
144
145
145
-- compile the source file
146
146
function compile (self , sourcefile , objectfile , dependinfo , flags , opt )
147
-
148
- -- ensure the object directory
147
+ opt = opt or {}
149
148
os .mkdir (path .directory (objectfile ))
150
149
151
- -- compile it
150
+ local depfile = dependinfo and os . tmpfile () or nil
152
151
try
153
152
{
154
153
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 ))
156
168
return (outdata or " " ) .. (errdata or " " )
157
169
end ,
158
170
catch
@@ -190,6 +202,16 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
190
202
if warnings and # warnings > 0 and policy .build_warnings (opt ) then
191
203
cprint (" ${color.warning}%s" , table.concat (table .slice (warnings :split (' \n ' ), 1 , 8 ), ' \n ' ))
192
204
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
193
215
end
194
216
}
195
217
}
0 commit comments