Updated to the latest version of pm.
This commit is contained in:
parent
7826e03427
commit
e6f856e795
2 changed files with 66 additions and 32 deletions
98
first/c.pm
98
first/c.pm
|
@ -5,6 +5,7 @@
|
||||||
local io_open = io.open
|
local io_open = io.open
|
||||||
local string_gsub = string.gsub
|
local string_gsub = string.gsub
|
||||||
local string_gfind = string.gfind
|
local string_gfind = string.gfind
|
||||||
|
local string_find = string.find
|
||||||
local table_insert = table.insert
|
local table_insert = table.insert
|
||||||
local table_getn = table.getn
|
local table_getn = table.getn
|
||||||
local filetime = pm.filetime
|
local filetime = pm.filetime
|
||||||
|
@ -14,7 +15,6 @@ local filetime = pm.filetime
|
||||||
CCOMPILER = "gcc"
|
CCOMPILER = "gcc"
|
||||||
CC = "%CCOMPILER% %CBUILDFLAGS% %CDYNINCLUDES% %CINCLUDES% %CDEFINES% %CEXTRAFLAGS% -c -o %out% %in%"
|
CC = "%CCOMPILER% %CBUILDFLAGS% %CDYNINCLUDES% %CINCLUDES% %CDEFINES% %CEXTRAFLAGS% -c -o %out% %in%"
|
||||||
CPROGRAM = "%CCOMPILER% %CBUILDFLAGS% %CLINKFLAGS% %CEXTRAFLAGS% -o %out% %in% %CLIBRARIES%"
|
CPROGRAM = "%CCOMPILER% %CBUILDFLAGS% %CLINKFLAGS% %CEXTRAFLAGS% -o %out% %in% %CLIBRARIES%"
|
||||||
CDEPENDS = "%CCOMPILER% %CBUILDFLAGS% %CDYNINCLUDES% %CINCLUDES% %CDEFINES% %CEXTRAFLAGS% -MM -MG %in% > %out%"
|
|
||||||
AR = "%RM% %out% && ar cr %out% %in% && ranlib %out%"
|
AR = "%RM% %out% && ar cr %out% %in% && ranlib %out%"
|
||||||
|
|
||||||
CBUILDFLAGS = {"-g"}
|
CBUILDFLAGS = {"-g"}
|
||||||
|
@ -28,37 +28,61 @@ CLIBRARIES = EMPTY
|
||||||
--- Manage C file dependencies ----------------------------------------------
|
--- Manage C file dependencies ----------------------------------------------
|
||||||
|
|
||||||
local dependency_cache = {}
|
local dependency_cache = {}
|
||||||
local function load_dependency_file(fn)
|
local function calculate_dependencies(filename, includes)
|
||||||
local o = dependency_cache[fn]
|
-- Cache values, so we don't recalculate dependencies needlessly.
|
||||||
|
|
||||||
|
local o = dependency_cache[filename]
|
||||||
if o then
|
if o then
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Read in the dependency file.
|
local deps = {}
|
||||||
|
deps[filename] = true
|
||||||
|
|
||||||
local f = io_open(fn)
|
local calcdeps = 0
|
||||||
if not f then
|
calcdeps = function(filename, file)
|
||||||
print("failed to open "..fn)
|
file = file or io.open(filename)
|
||||||
return nil
|
if not file then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local localincludes = string_gsub(filename, "/[^/]*$", "")
|
||||||
|
if localincludes then
|
||||||
|
localincludes = {localincludes, unpack(includes)}
|
||||||
|
else
|
||||||
|
localincludes = includes
|
||||||
|
end
|
||||||
|
|
||||||
|
for line in file:lines() do
|
||||||
|
local _, _, f = string_find(line, '^[ \t]*#[ \t]*include[ \t]*["<]([^"]+)[">]')
|
||||||
|
if f then
|
||||||
|
for _, path in ipairs(localincludes) do
|
||||||
|
local subfilename = path.."/"..f
|
||||||
|
local subfile = io.open(subfilename)
|
||||||
|
if subfile then
|
||||||
|
if not deps[subfilename] then
|
||||||
|
deps[subfilename] = true
|
||||||
|
calcdeps(subfilename, subfile)
|
||||||
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Explicit close to avoid having to wait for the garbage collector
|
||||||
|
-- to free up the underlying fd.
|
||||||
|
|
||||||
|
file:close()
|
||||||
end
|
end
|
||||||
f = f:read("*a")
|
|
||||||
|
|
||||||
-- Massage the dependency file into a string containing one unescaped
|
|
||||||
-- filename per line.
|
|
||||||
|
|
||||||
f = string_gsub(f, "^.*[^\\]: *", "")
|
|
||||||
f = string_gsub(f, "\\\r?\n", "")
|
|
||||||
f = string_gsub(f, "([^\\]) +", "%1\n")
|
|
||||||
f = string_gsub(f, "\\", "")
|
|
||||||
|
|
||||||
-- Parse the string.
|
|
||||||
|
|
||||||
|
calcdeps(filename)
|
||||||
o = {}
|
o = {}
|
||||||
for l in string_gfind(f, "[^\n]+") do
|
for i, _ in pairs(deps) do
|
||||||
table_insert(o, l)
|
table_insert(o, i)
|
||||||
end
|
end
|
||||||
|
|
||||||
dependency_cache[fn] = o
|
dependency_cache[filename] = o
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -91,19 +115,29 @@ simple_with_clike_dependencies = simple {
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
__dependencies = function(self, inputs, outputs)
|
__dependencies = function(self, inputs, outputs)
|
||||||
local obj = simple {
|
local cincludes = self.CINCLUDES
|
||||||
CDYNINCLUDES = self.CDYNINCLUDES,
|
if (type(cincludes) == "string") then
|
||||||
command = self.makedepends,
|
cincludes = {cincludes}
|
||||||
outputs = {"%U%-%I%.d"},
|
end
|
||||||
unpack(inputs)
|
|
||||||
}
|
local includes = {}
|
||||||
local o = obj:__build()
|
for _, i in ipairs(cincludes) do
|
||||||
local depends = load_dependency_file(o[1])
|
local _, _, p = string_find(i, "^-I[ \t]*(.+)$")
|
||||||
|
if p then
|
||||||
|
table_insert(includes, p)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local depends = calculate_dependencies(inputs[1], includes)
|
||||||
if not depends then
|
if not depends then
|
||||||
self:__error("could not determine the dependencies for ",
|
self:__error("could not determine the dependencies for ",
|
||||||
pm.rendertable(inputs))
|
pm.rendertable(inputs))
|
||||||
end
|
end
|
||||||
|
if pm.verbose then
|
||||||
|
pm.message('"', inputs[1], '" appears to depend on ',
|
||||||
|
pm.rendertable(depends))
|
||||||
|
end
|
||||||
return depends
|
return depends
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
BIN
pm
BIN
pm
Binary file not shown.
Loading…
Add table
Reference in a new issue