]> Dogcows Code - chaz/yoink/blob - build/compile.lua
31b20fd1743c428661886ee8b11257cfa1e0a528
[chaz/yoink] / build / compile.lua
1 #!/usr/bin/env lua
2
3 --
4 -- Yoink
5 -- This script wraps around the compiler command to handle the creation of
6 -- dependency files. It works with new versions of GCC.
7 --
8
9
10 -- Get the next argument passed to the script.
11 function shift()
12 var = arg[1]
13 table.remove(arg, 1)
14 arguments = string.format("%s %q", tostring(arguments), tostring(var))
15 return var
16 end
17
18
19 -- The compiler command is the first argument.
20 compiler = shift()
21 arguments = ""
22
23
24 -- Consume each compiler argument, appending it to the arguments variable.
25 while 0 < #arg do
26 local v = shift(arg)
27 if v == "-o" then product = shift(arg) end
28 end
29 if not product then print("No output file specified.") os.exit(1) end
30
31
32 -- Now try the actual compile WITH dependency generation.
33 if os.execute(compiler.." -MD"..arguments) ~= 0 then
34 -- Try it without dependency generation.
35 if os.execute(compiler..arguments) ~= 0 then
36 print("The compile failed. :-(")
37 os.exit(1)
38 end
39 print("The compile succeeded without dependency generation.")
40 os.exit(0)
41 end
42
43
44 -- Remove the old dependency file.
45 dep = product..".d"
46 os.remove(dep)
47
48
49 -- GCC outputs file.d for a product named file.o.
50 gccdep = product:gsub("^.*/(.*)%.o$", "%1.d")
51 tmpname = gccdep..".tmp"
52
53 -- Fix up the dependency file with correct paths.
54 if os.execute("test -f "..gccdep) == 0 and os.rename(gccdep, tmpname) then
55 os.execute(string.format("sed -e 's|.*:|%s %s:|' <%s >>%s", product, dep, tmpname, dep))
56 os.execute(string.format("sed -e 's/^.*://' -e 's/^ *//' -e 's/ *\\\\$//' -e 's/$/:/' <%s >>%s", tmpname, dep))
57 os.remove(tmpname)
58 else
59 print("Couldn't find the dependency file at "..gccdep..".")
60 os.exit(1)
61 end
62
This page took 0.035916 seconds and 4 git commands to generate.