X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=build%2Fcompile.lua;fp=build%2Fcompile.lua;h=31b20fd1743c428661886ee8b11257cfa1e0a528;hp=0000000000000000000000000000000000000000;hb=bd62b2e6a6e5f1af5a635df3ff1a07f363d9ffe0;hpb=7ac3aee9efa7f9ce1a966df030b1f76f2b82ef2d diff --git a/build/compile.lua b/build/compile.lua new file mode 100755 index 0000000..31b20fd --- /dev/null +++ b/build/compile.lua @@ -0,0 +1,62 @@ +#!/usr/bin/env lua + +-- +-- Yoink +-- This script wraps around the compiler command to handle the creation of +-- dependency files. It works with new versions of GCC. +-- + + +-- Get the next argument passed to the script. +function shift() + var = arg[1] + table.remove(arg, 1) + arguments = string.format("%s %q", tostring(arguments), tostring(var)) + return var +end + + +-- The compiler command is the first argument. +compiler = shift() +arguments = "" + + +-- Consume each compiler argument, appending it to the arguments variable. +while 0 < #arg do + local v = shift(arg) + if v == "-o" then product = shift(arg) end +end +if not product then print("No output file specified.") os.exit(1) end + + +-- Now try the actual compile WITH dependency generation. +if os.execute(compiler.." -MD"..arguments) ~= 0 then + -- Try it without dependency generation. + if os.execute(compiler..arguments) ~= 0 then + print("The compile failed. :-(") + os.exit(1) + end + print("The compile succeeded without dependency generation.") + os.exit(0) +end + + +-- Remove the old dependency file. +dep = product..".d" +os.remove(dep) + + +-- GCC outputs file.d for a product named file.o. +gccdep = product:gsub("^.*/(.*)%.o$", "%1.d") +tmpname = gccdep..".tmp" + +-- Fix up the dependency file with correct paths. +if os.execute("test -f "..gccdep) == 0 and os.rename(gccdep, tmpname) then + os.execute(string.format("sed -e 's|.*:|%s %s:|' <%s >>%s", product, dep, tmpname, dep)) + os.execute(string.format("sed -e 's/^.*://' -e 's/^ *//' -e 's/ *\\\\$//' -e 's/$/:/' <%s >>%s", tmpname, dep)) + os.remove(tmpname) +else + print("Couldn't find the dependency file at "..gccdep..".") + os.exit(1) +end +