1
0
Fork 0
spectre/.bam/functions.lua

93 lines
2 KiB
Lua

local _systems = {
"Win32",
"Unix"
}
-- Returns a string of all supported systems
function supported_systems()
return table.concat(_systems, ', ')
end
-- Detect what system we currently are on.
function system()
if family ~= nil then
if family == "windows" then
return _systems[1]
end
if family == "unix" then
return _systems[2]
end
end
local win = os.getenv('OS')
if win ~= nil and win:lower():match('windows') then
return _systems[1]
end
return nil
end
-- Copy settings with a optional label prefix.
function CopySettings(settings, prefix)
local n = TableDeepCopy(settings)
if prefix ~= nil then
n.labelprefix = string.format("[%s] ", prefix)
end
return n
end
-- Defines a module
-- path: base path to source files.
-- src: table of source files.
function Module(path, src)
local r = {}
for k, v in pairs(src) do
r[k] = path .. "/" .. v
end
return r
end
-- Copy a directory src to dst
-- src = "path/to/a", dest = "path/to/b" -> the whole content
-- of "a" will be copied to "path/to/b"
function CopyDir(dst, src)
local r = {}
local base = PathDir(src)
local files = CollectRecursive(Path(src) .. "/*")
for k, v in pairs(files) do
local rdir = PathDir(v:sub(base:len() + 1))
r[k] = CopyToDirectory(PathJoin(dst, rdir), v)
end
return r
end
-- Build example binary.
-- This function Imports "examples/<name>/bam.lua"
-- that file must define a table "src" that contains the source files.
function BuildExample(settings, name, dependencies)
Import("examples/" .. name .. "/bam.lua")
exe = Link(settings, "examples/" .. name, Compile(settings, src))
if dependencies ~= nil and #dependencies > 0 then
AddDependency(exe, dependencies)
end
return exe
end
-- Build examples binaries.
-- Just a wrapper for BuildExample. taking a table of names instead.
function BuildExamples(settings, names, dependencies)
local r = {}
for i = 1, #names do
r[i] = BuildExample(settings, names[i], dependencies)
end
return r
end