First version in CVS.
This commit is contained in:
143
first/c.pm
Normal file
143
first/c.pm
Normal file
@@ -0,0 +1,143 @@
|
||||
-- pm includefile to compile *host* C programs.
|
||||
|
||||
-- Standard Lua boilerplate.
|
||||
|
||||
local io_open = io.open
|
||||
local string_gsub = string.gsub
|
||||
local string_gfind = string.gfind
|
||||
local table_insert = table.insert
|
||||
local table_getn = table.getn
|
||||
local filetime = pm.filetime
|
||||
|
||||
-- Define some variables.
|
||||
|
||||
CCOMPILER = "gcc"
|
||||
CC = "%CCOMPILER% %CBUILDFLAGS% %CDYNINCLUDES% %CINCLUDES% %CDEFINES% %CEXTRAFLAGS% -c -o %out% %in%"
|
||||
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%"
|
||||
|
||||
CBUILDFLAGS = "-g -Os"
|
||||
CINCLUDES = {}
|
||||
CDEFINES = {}
|
||||
CEXTRAFLAGS = ""
|
||||
CLINKFLAGS = ""
|
||||
CDYNINCLUDES = ""
|
||||
CLIBRARIES = ""
|
||||
|
||||
--- Manage C file dependencies ----------------------------------------------
|
||||
|
||||
local dependency_cache = {}
|
||||
local function load_dependency_file(fn)
|
||||
local o = dependency_cache[fn]
|
||||
if o then
|
||||
return o
|
||||
end
|
||||
|
||||
-- Read in the dependency file.
|
||||
|
||||
local f = io_open(fn)
|
||||
if not f then
|
||||
print("failed to open "..fn)
|
||||
return nil
|
||||
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.
|
||||
|
||||
o = {}
|
||||
for l in string_gfind(f, "[^\n]+") do
|
||||
table_insert(o, l)
|
||||
end
|
||||
|
||||
dependency_cache[fn] = o
|
||||
return o
|
||||
end
|
||||
|
||||
-- This clause specialises 'simple' to add support for smart dependencies of C
|
||||
-- files.
|
||||
|
||||
simple_with_clike_dependencies = simple {
|
||||
class = "simple_with_clike_dependencies",
|
||||
makedepends = {"%CDEPENDS%"},
|
||||
|
||||
__init = function(self, p)
|
||||
simple.__init(self, p)
|
||||
|
||||
-- If we're a class, don't verify.
|
||||
|
||||
if ((type(p) == "table") and p.class) then
|
||||
return
|
||||
end
|
||||
|
||||
-- If dynamicheaders is an object, turn it into a singleton list.
|
||||
|
||||
if self.dynamicheaders then
|
||||
if (type(self.dynamicheaders) ~= "table") then
|
||||
self:__error("doesn't know what to do with dynamicheaders, which ",
|
||||
"should be a list or an object but was a ", type(self.dynamicheaders))
|
||||
end
|
||||
if self.dynamicheaders.class then
|
||||
self.dynamicheaders = {self.dynamicheaders}
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
__dependencies = function(self, inputs, outputs)
|
||||
local obj = simple {
|
||||
CDYNINCLUDES = self.CDYNINCLUDES,
|
||||
command = self.makedepends,
|
||||
outputs = {"%U%-%I%.d"},
|
||||
unpack(inputs)
|
||||
}
|
||||
local o = obj:__build()
|
||||
local depends = load_dependency_file(o[1])
|
||||
if not depends then
|
||||
self:__error("could not determine the dependencies for ",
|
||||
pm.rendertable(inputs))
|
||||
end
|
||||
return depends
|
||||
end,
|
||||
|
||||
__buildadditionalchildren = function(self)
|
||||
self.CDYNINCLUDES = ""
|
||||
if self.dynamicheaders then
|
||||
for _, i in ipairs(self.dynamicheaders) do
|
||||
local o = i:__build()
|
||||
if o[1] then
|
||||
self.CDYNINCLUDES = self.CDYNINCLUDES..' "-I'..string_gsub(o[1], "/[^/]*$", "")..'"'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
-- These are the publically useful clauses.
|
||||
|
||||
cfile = simple_with_clike_dependencies {
|
||||
class = "cfile",
|
||||
command = {"%CC%"},
|
||||
outputs = {"%U%-%I%.o"},
|
||||
}
|
||||
|
||||
cprogram = simple {
|
||||
class = "cprogram",
|
||||
command = {"%CPROGRAM%"},
|
||||
outputs = {"%U%-%I%"},
|
||||
}
|
||||
|
||||
clibrary = simple {
|
||||
class = "clibrary",
|
||||
command = {
|
||||
"%AR%"
|
||||
},
|
||||
outputs = {"%U%-%I%.a"},
|
||||
}
|
||||
34
first/llgen.pm
Normal file
34
first/llgen.pm
Normal file
@@ -0,0 +1,34 @@
|
||||
-- $Source$
|
||||
-- $State$
|
||||
|
||||
-- This is unpleasant. LLgen can generate an arbitrary number of output files,
|
||||
-- which means we need our own output filename generator.
|
||||
|
||||
LLgen = simple {
|
||||
class = "LLgen",
|
||||
command = {
|
||||
"rm -f %out%",
|
||||
"cd %out[1]:dirname% && LLgen %in%"
|
||||
},
|
||||
|
||||
outputs = {"%U%/" },
|
||||
__outputs = function(self, inputs)
|
||||
local o = simple.__outputs(self, inputs)[1]
|
||||
|
||||
local outputs = {o.."Lpars.h", o.."Lpars.c"}
|
||||
|
||||
for _, i in ipairs(inputs) do
|
||||
i = string.gsub(i, "^.*/", "")
|
||||
i = string.gsub(i, "%.g$", ".c")
|
||||
table.insert(outputs, o..i)
|
||||
end
|
||||
|
||||
return outputs
|
||||
end
|
||||
}
|
||||
|
||||
-- Revision history
|
||||
-- $Log$
|
||||
-- Revision 1.1 2006-07-20 23:18:18 dtrg
|
||||
-- First version in CVS.
|
||||
--
|
||||
18
first/yacc.pm
Normal file
18
first/yacc.pm
Normal file
@@ -0,0 +1,18 @@
|
||||
yacc = simple {
|
||||
class = "yacc",
|
||||
outputs = {"%U%/%I%.c"},
|
||||
|
||||
command = {
|
||||
"yacc -t -b %{return posix.dirname(self.out[1])}%/y -d %in%",
|
||||
"mv %{return posix.dirname(self.out[1])}%/y.tab.c %out%"
|
||||
}
|
||||
}
|
||||
|
||||
flex = simple {
|
||||
class = "flex",
|
||||
outputs = {"%U%/%I%.c"},
|
||||
|
||||
command = {
|
||||
"flex -s -t %in% > %out%"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user