1
0
Fork 0
spectre/.bam/functions.lua
Henrik Hautakoski cbd26a211d .bam/functions.lua: in host_system() switch from 'family' to 'platform' variable.
family == "unix" contains FreeBSD and MacOS. that we dont have support for.
2020-12-28 19:27:39 +01:00

101 lines
2.2 KiB
Lua

Import(".bam/utils.lua")
local _systems = {
"Win32",
"Unix"
}
-- Returns a string of all supported systems
function supported_systems()
return table.concat(_systems, ', ')
end
-- Return True if 'value' is a supported system. False otherwise.
function valid_system(value)
return contains(_systems, value)
end
-- Find what host system we are on.
-- Returns nil if system could not be determined.
function host_system()
-- Check "platform" variable set by bam first.
if platform == "win32" or platform == "win64" then
return _systems[1]
end
if platform == "linux" then
return _systems[2]
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