X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=tools%2Fcompile.lua;fp=tools%2Fcompile.lua;h=0000000000000000000000000000000000000000;hp=3dfff3cb9ff2a95a5c23a449dc2d502c315fe449;hb=6c9943707d4f33035830eba0587a61a34eaecbc2;hpb=af88821a172c4dfd138b91b2a5148ae50b502fa2 diff --git a/tools/compile.lua b/tools/compile.lua deleted file mode 100755 index 3dfff3c..0000000 --- a/tools/compile.lua +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env lua - --- --- Yoink --- This script wraps around the compiler command to handle the creation of --- dependency files. It works with GCC. The script is based off of Emile --- van Bergen's `ccdeps-gcc' script. --- - - --- 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 = "" -paths = {} - - --- Consume each compiler argument, appending it to the arguments variable. -while 0 < #arg do - local v = shift() - if v == "-o" then - product = shift() - elseif v:match("%-[xubV]$") then - shift() -- Shift an extra one for the option's payload. - else - path = v:match("([^-].*)/") - if path then paths[path] = true end - 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, either in the current --- directory or in the directory where the source is. -depname = product:gsub("^.*/(.*)%.o$", "%1.d") -depfiles = {} -table.insert(depfiles, depname) -for path in pairs(paths) do table.insert(depfiles, path.."/"..depname) end - -for i,gccdep in ipairs(depfiles) do - 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) - os.exit() - end -end - -print("Couldn't find the dependency file.") -os.exit(1) -