]>
Dogcows Code - chaz/yoink/blob - tools/compile.lua
5 -- This script wraps around the compiler command to handle the creation of
6 -- dependency files. It works with GCC. The script is based off of Emile
7 -- van Bergen's `ccdeps-gcc' script.
11 -- Get the next argument passed to the script.
15 arguments
= string.format("%s %q", tostring(arguments
), tostring(var
))
20 -- The compiler command is the first argument.
26 -- Consume each compiler argument, appending it to the arguments variable.
31 elseif v
:match("%-[xubV]$") then
32 shift() -- Shift an extra one for the option's payload.
34 path
= v
:match("([^-].*)/")
35 if path
then paths
[path
] = true end
38 if not product
then print("No output file specified.") os
.exit(1) end
41 -- Now try the actual compile WITH dependency generation.
42 if os
.execute(compiler
.." -MD"..arguments
) ~= 0 then
43 -- Try it without dependency generation.
44 if os
.execute(compiler
..arguments
) ~= 0 then
45 print("The compile failed. :-(")
48 print("The compile succeeded without dependency generation.")
53 -- Remove the old dependency file.
58 -- GCC outputs file.d for a product named file.o, either in the current
59 -- directory or in the directory where the source is.
60 depname
= product
:gsub("^.*/(.*)%.o$", "%1.d")
62 table.insert(depfiles
, depname
)
63 for path
in pairs(paths
) do table.insert(depfiles
, path
.."/"..depname
) end
65 for i
,gccdep
in ipairs(depfiles
) do
66 tmpname = gccdep
..".tmp"
67 -- Fix up the dependency file with correct paths.
68 if os
.execute("test -f "..gccdep
) == 0 and os
.rename(gccdep
, tmpname) then
69 os
.execute(string.format("sed -e 's|.*:|%s %s:|' <%s >>%s", product
, dep
, tmpname, dep
))
70 os
.execute(string.format("sed -e 's/^.*://' -e 's/^ *//' -e 's/ *\\\\$//' -e 's/$/:/' <%s >>%s", tmpname, dep
))
76 print("Couldn't find the dependency file.")
This page took 0.041466 seconds and 4 git commands to generate.