Updated to the version 0.1 of Prime Mover (which involves some syntax changes).

This commit is contained in:
dtrg
2006-10-15 00:28:12 +00:00
parent 708a83ef22
commit dbe10d2c19
34 changed files with 299 additions and 222 deletions

View File

@@ -11,7 +11,7 @@ ackfile = simple_with_clike_dependencies {
class = "ackfile",
CINCLUDES = {REDIRECT, "ACKINCLUDES"},
command = {
"%BINDIR%bin/ack %ACKBUILDFLAGS% %ACKINCLUDES% %ACKDEFINES% -c -o %out% %in%"
"%BINDIR%bin/ack %ACKBUILDFLAGS% %ACKINCLUDES:cincludes% %ACKDEFINES:cdefines% -c -o %out% %in%"
},
outputs = {"%U%-%I%.o"},
}

View File

@@ -1,3 +1,7 @@
-- $Id$
-- $HeadURL: https://svn.sourceforge.net/svnroot/primemover/pm/lib/c.pm $
-- $LastChangedDate: 2006-10-12 20:17:52Z $
-- pm includefile to compile *host* C programs.
-- Standard Lua boilerplate.
@@ -13,9 +17,13 @@ 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%"
AR = "%RM% %out% && ar cr %out% %in% && ranlib %out%"
CXXCOMPILER = "g++"
CC = "%CCOMPILER% %CBUILDFLAGS% %CDYNINCLUDES:cincludes% %CINCLUDES:cincludes% %CDEFINES:cdefines% %CEXTRAFLAGS% -c -o %out% %in%"
CXX = "%CXXCOMPILER% %CBUILDFLAGS% %CDYNINCLUDES:cincludes% %CINCLUDES:cincludes% %CDEFINES:cdefines% %CEXTRAFLAGS% -c -o %out% %in%"
CPROGRAM = "%CCOMPILER% %CBUILDFLAGS% %CLINKFLAGS% %CEXTRAFLAGS% -o %out% %in% %CLIBRARIES:clibraries%"
CXXPROGRAM = "%CXXCOMPILER% %CBUILDFLAGS% %CLINKFLAGS% %CEXTRAFLAGS% -o %out% %in% %CLIBRARIES:clibraries%"
CLIBRARY = "rm -f %out% && ar cr %out% %in% && ranlib %out%"
CBUILDFLAGS = {"-g"}
CINCLUDES = EMPTY
@@ -25,6 +33,44 @@ CLINKFLAGS = EMPTY
CDYNINCLUDES = EMPTY
CLIBRARIES = EMPTY
--- Custom string modifiers -------------------------------------------------
local function prepend(rule, arg, prefix)
if (arg == EMPTY) then
return EMPTY
end
local t = {}
for i, j in ipairs(arg) do
t[i] = prefix..j
end
return t
end
function pm.stringmodifier.cincludes(rule, arg)
return prepend(rule, arg, "-I")
end
function pm.stringmodifier.cdefines(rule, arg)
return prepend(rule, arg, "-D")
end
function pm.stringmodifier.clibraries(rule, arg)
if (arg == EMPTY) then
return EMPTY
end
local t = {}
for i, j in ipairs(arg) do
if string_find(j, "%.a$") then
t[i] = j
else
t[i] = "-l"..j
end
end
return t
end
--- Manage C file dependencies ----------------------------------------------
local dependency_cache = {}
@@ -41,7 +87,7 @@ local function calculate_dependencies(filename, includes)
local calcdeps = 0
calcdeps = function(filename, file)
file = file or io.open(filename)
file = file or io_open(filename)
if not file then
return
end
@@ -58,7 +104,7 @@ local function calculate_dependencies(filename, includes)
if f then
for _, path in ipairs(localincludes) do
local subfilename = path.."/"..f
local subfile = io.open(subfilename)
local subfile = io_open(subfilename)
if subfile then
if not deps[subfilename] then
deps[subfilename] = true
@@ -116,41 +162,44 @@ simple_with_clike_dependencies = simple {
end,
__dependencies = function(self, inputs, outputs)
local cincludes = self.CINCLUDES
local cincludes = self:__index("CINCLUDES")
if (type(cincludes) == "string") then
cincludes = {cincludes}
end
local includes = {}
for _, i in ipairs(cincludes) do
local _, _, p = string_find(i, "^-I[ \t]*(.+)$")
if p then
table_insert(includes, p)
end
table_insert(includes, self:__expand(i))
end
local depends = calculate_dependencies(inputs[1], includes)
local input = self:__expand(inputs[1])
local depends = calculate_dependencies(input, includes)
if not depends then
self:__error("could not determine the dependencies for ",
pm.rendertable(inputs))
pm.rendertable({input}))
end
if pm.verbose then
pm.message('"', inputs[1], '" appears to depend on ',
pm.message('"', input, '" appears to depend on ',
pm.rendertable(depends))
end
return depends
end,
__buildadditionalchildren = function(self)
self.CDYNINCLUDES = ""
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], "/[^/]*$", "")..'"'
table_insert(self.CDYNINCLUDES, (string_gsub(o[1], "/[^/]*$", "")))
end
end
end
-- If no paths on the list, replace the list with EMPTY so it doesn't
-- expand to anything.
if (table_getn(self.CDYNINCLUDES) == 0) then
self.CDYNINCLUDES = EMPTY
end
end
}
@@ -162,16 +211,28 @@ cfile = simple_with_clike_dependencies {
outputs = {"%U%-%I%.o"},
}
cxxfile = simple_with_clike_dependencies {
class = "cxxfile",
command = {"%CXX%"},
outputs = {"%U%-%I%.o"},
}
cprogram = simple {
class = "cprogram",
command = {"%CPROGRAM%"},
outputs = {"%U%-%I%"},
}
cxxprogram = simple {
class = "cxxprogram",
command = {"%CXXPROGRAM%"},
outputs = {"%U%-%I%"},
}
clibrary = simple {
class = "clibrary",
command = {
"%AR%"
"%CLIBRARY%"
},
outputs = {"%U%-%I%.a"},
}

View File

@@ -3,8 +3,8 @@ yacc = simple {
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%"
"yacc -t -b %out[1]:dirname%/y -d %in%",
"mv %out[1]:dirname%/y.tab.c %out[1]%"
}
}