Build/Core/Target/Target.lua

272 lines
7.5 KiB
Lua

_auCurrentPlatforms = {}
_auCurrentArchs = {}
_auCurrentFlags = {}
_auExtendedConfig = false
_auExtendedArch = false
auRequire("Core/Target/arch")
auRequire("Core/Target/flags")
auRequire("Core/Target/platform")
local function addTarget(prefix, available, flags)
auForEachKV(available, function(key, value)
local option = prefix .. "-" .. key
newoption
{
trigger = option,
description = ""
}
if (_OPTIONS[option]) then
table.insert(flags, key)
end
end)
end
local function defineOutputNames(platformName)
local name = nil
if (not platformName) then
return
end
local alt = Aurora.Platforms[platformName].stylizedName
if (alt) then
name = alt
else
name = platformName:gsub("^%l", string.upper)
end
Aurora.Platforms[platformName].outputName = name
end
local function start()
addTarget("target", Aurora.Platforms, _auCurrentPlatforms)
addTarget("target", Aurora.Architectures, _auCurrentArchs)
addTarget("flag", Aurora.Flags, _auCurrentFlags)
auForEach(_auCurrentPlatforms, defineOutputNames)
_auExtendedArch = #_auCurrentArchs > 1
end
local function startProject()
auFilterForPlatforms(function(platform)
defines(Aurora.Platforms[platform].defines)
end)
end
local function startSolution()
local platforms = {}
if (not _auExtendedArch) then
auForEach(_auCurrentPlatforms, function(platform)
table.insert(platforms, platform)
end)
else
auForEach(_auCurrentArchs, function(arch)
auForEach(_auCurrentPlatforms, function(platform)
table.insert(platforms, platform .. arch)
end)
end)
end
configurations(Aurora.Settings.aNamesOfConfigs)
_G.platforms(platforms)
if (not _auExtendedArch) then
local arch = _auCurrentArchs[1]
auForEach(_auCurrentPlatforms, function(platform)
auFilter({"platforms:"..platform})
system(Aurora.Platforms[platform].system)
architecture(Aurora.Architectures[arch].architecture)
auFilter{}
end)
else
auForEach(_auCurrentArchs, function(arch)
auForEach(_auCurrentPlatforms, function(platform)
auFilter({"platforms:"..platform .. arch})
system(Aurora.Platforms[platform].system)
architecture(Aurora.Architectures[arch].architecture)
auFilter{}
end)
end)
end
end
local function auFilterForArchs(callback, ...)
auForEach(_auCurrentArchs, function(arch, ...)
auFilter(auConcatVararg({"architecture:" .. arch}, ...))
callback(arch)
auFilter {}
end, ...)
end
local function auFilterForPlatforms(callback, ...)
auFilterForConfigPlatforms(function(config, platform)
callback(platform)
end, extendedFilter)
end
local function auFilterForConfigs(callback, ...)
auFilterForConfigPlatforms(function(config, platform)
callback(config)
end, extendedFilter)
end
local function auFilterForConfigPlatforms(callback, ...)
auForEach(_auCurrentPlatforms, function(platform, ...)
auForEach(_auCurrentArchs, function(arch, ...)
auForEach(Aurora.Settings.aNamesOfConfigs, function(config, ...)
auFilter(auFilterOf({platforms = platform, configs = config, archs = arch}))
callback(config, platform, arch)
auFilter {}
end, ...)
end, ...)
end, ...)
end
local function auFilterOf(configFilter, ...)
local ret = {}
local andOptions = {}
local test = function(val, orArray, notArray)
if (orArray) then
if (type(orArray) == "string") then
if (orArray ~= val) then
return
end
elseif (#orArray > 0) then
if (not auContains(orArray, val)) then
return
end
end
end
if (notArray) then
if (type(notArray) == "string") then
if (notArray == val) then
return
end
elseif (#notArray > 0) then
if (auContains(notArray, val)) then
return
end
end
end
return true
end
-- TODO: clean up
local validPlatforms = {}
local validArchs = {}
local validConfigs = {}
auForEach(Aurora.Settings.aNamesOfConfigs, function(config)
if (not test(config, configFilter.configs, configFilter.notConfigs)) then
return
end
table.insert(validConfigs, config)
end)
auForEach(_auCurrentArchs, function(arch)
if (not test(arch, configFilter.archs, configFilter.notArchs)) then
return
end
table.insert(validArchs, arch)
end)
auForEach(_auCurrentPlatforms, function(platform)
if (not test(platform, configFilter.platforms, configFilter.notPlatforms)) then
return
end
if (not _auExtendedArch) then
table.insert(validPlatforms, platform)
else
auForEach(_auCurrentArchs, function(arch)
table.insert(validPlatforms, platform .. arch)
end)
end
end)
auForEach(configFilter.options, function(option)
table.insert(andOptions, "options:" .. option)
end)
auForEach(configFilter.notOptions, function(option)
table.insert(andOptions, "not options:" .. option)
end)
auForEach(configFilter.depends, function(dependency)
if (not _auProjects[dependency]) then
table.insert(andOptions, "platforms:none")
end
end)
auForEach(configFilter.notDepends, function(dependency)
if (_auProjects[dependency]) then
table.insert(andOptions, "platforms:none")
end
end)
local supportedArchs = {}
auForEach(validArchs, function(arch)
table.insert(supportedArchs, "architecture:" .. auFetchGlobal("Architectures")[arch].architecture)
end)
if (#supportedArchs == 0) then
table.insert(supportedArchs, "platforms:none")
end
ret = {table.concat(supportedArchs, " or ")}
local supportedPlatforms = {}
auForEach(validPlatforms, function(platform)
table.insert(supportedPlatforms, "platforms:" .. platform)
end)
if (#supportedPlatforms == 0) then
table.insert(supportedPlatforms, "platforms:none")
end
ret = auMergeArray(ret, {table.concat(supportedPlatforms, " or ")})
local supportedConfigs = {}
auForEach(validConfigs, function(config)
table.insert(supportedConfigs, "configurations:" .. config)
end)
if (#supportedConfigs == 0) then
table.insert(supportedConfigs, "platforms:none")
end
ret = auMergeArray(ret, {table.concat(supportedConfigs, " or ")})
--local ret = {table.concat(ret, " or ")}
if (#andOptions) then
ret = auMergeArray(ret, andOptions)
end
--print(json.encode(configFilter), json.encode(ret))
return auConcatArrays(ret, ...)
end
return {
start = start,
startSolution = startSolution,
startProject = startProject,
auFilterForPlatforms = auFilterForPlatforms,
auFilterForConfigs = auFilterForConfigs,
auFilterForConfigPlatforms = auFilterForConfigPlatforms,
auFilterOf = auFilterOf,
auFilterForArchs = auFilterForArchs,
defineOutputNames = defineOutputNames
}