summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-07-01 17:47:32 +0800
committerruki <[email protected]>2015-07-01 17:47:32 +0800
commitc6cc4e543cbfc3e23761ebb4cc0f825055928ed2 (patch)
tree4439e995ace4807584b7057af165abee2d14051f
parent739a215a2ef11cfe1c8363e965ee19f82d41987d (diff)
support multiple architecture for configure
-rw-r--r--xmake/scripts/base/config.lua122
1 files changed, 94 insertions, 28 deletions
diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua
index eebe805bb..e50e946d5 100644
--- a/xmake/scripts/base/config.lua
+++ b/xmake/scripts/base/config.lua
@@ -33,12 +33,23 @@ local global = require("base/global")
-- make configure for the current target
function config._make(configs)
+ -- check
+ assert(configs and configs.plat and configs.arch and configs._PLATS)
+
-- the options
local options = xmake._OPTIONS
assert(options)
+ -- the configs for platform
+ local configs_plat = configs._PLATS[configs.plat]
+ assert(configs_plat)
+
+ -- the configs for architecture
+ local configs_arch = configs_plat[configs.arch]
+ assert(configs_arch)
+
-- init current target configure
- local current = {}
+ local current = {plat = configs.plat, arch = configs.arch, __rebuild = configs.__rebuild}
-- get configs from the global configure first
if global._CURRENT then
@@ -48,17 +59,17 @@ function config._make(configs)
end
-- get configs from all targets
- for k, v in pairs(configs) do
+ for k, v in pairs(configs_arch) do
if type(k) == "string" and not k:find("^_%u+") then
current[k] = v
end
end
-- get configs from the current target
- if configs._TARGET and current.target ~= "all" then
+ if configs_arch._TARGETS and current.target ~= "all" then
-- get the target config
- local target_config = configs._TARGET[current.target]
+ local target_config = configs_arch._TARGETS[current.target]
if target_config then
-- merge it
@@ -81,7 +92,14 @@ end
-- need configure?
function config._need(name)
- return name and name ~= "target" and name ~= "file" and name ~= "project" and name ~= "verbose" and name ~= "clean"
+ return name and
+ name ~= "plat" and
+ name ~= "arch" and
+ name ~= "target" and
+ name ~= "file" and
+ name ~= "project" and
+ name ~= "verbose" and
+ name ~= "clean"
end
-- get the current target scope
@@ -93,18 +111,33 @@ function config._target()
-- check
local configs = config._CONFIGS
- assert(configs)
+ assert(configs and configs.plat and configs.arch)
-- the target name
local name = options.target or options._DEFAULTS.target
assert(name and type(name) == "string")
+ -- init the configs for platform
+ configs._PLATS = configs._PLATS or {}
+ configs._PLATS[configs.plat] = configs._PLATS[configs.plat] or {}
+ local configs_plat = configs._PLATS[configs.plat]
+
+ -- init the configs for architecture
+ configs_plat[configs.arch] = configs_plat[configs.arch] or {}
+ local configs_arch = configs_plat[configs.arch]
+
+ -- init targets
+ configs_arch._TARGETS = configs_arch._TARGETS or {}
+ if name ~= "all" then
+ configs_arch._TARGETS[name] = configs_arch._TARGETS[name] or {}
+ end
+
-- for all targets?
if name == "all" then
- return configs
- elseif configs._TARGET then
+ return configs_arch
+ elseif configs_arch._TARGETS then
-- get it
- return configs._TARGET[name]
+ return configs_arch._TARGETS[name]
end
end
@@ -128,17 +161,46 @@ end
function config.set(name, value)
-- check
- assert(config._CURRENT and name)
+ assert(config._CURRENT and config._CONFIGS and name)
- -- get the current target
- local target = config._target()
- assert(target)
+ -- set platform or rebuild?
+ if name == "plat" or name == "__rebuild" then
+
+ config._CONFIGS[name] = value
+ config._CURRENT[name] = value
+
+ -- set architecture?
+ elseif name == "arch" then
+
+ -- the configs
+ local configs = config._CONFIGS
+ if configs.arch == "auto" then
- -- set it to the current target configure for saving to file
- target[name] = value
+ -- the configs for platform
+ local configs_plat = configs._PLATS[configs.plat]
+ assert(configs_plat)
- -- set it to the current configure
- config._CURRENT[name] = value
+ -- update configs of the auto architecture
+ configs_plat[value] = configs_plat["auto"]
+ configs_plat["auto"] = nil
+
+ end
+
+ config._CONFIGS.arch = value
+ config._CURRENT.arch = value
+
+ -- set others
+ else
+ -- get the current target
+ local target = config._target()
+ assert(target)
+
+ -- set it to the current target configure for saving to file
+ target[name] = value
+
+ -- set it to the current configure
+ config._CURRENT[name] = value
+ end
end
-- get the configure directory
@@ -217,22 +279,23 @@ function config.load()
-- clear configs and mark as "rebuild" if the plat has been changed
if current and current.plat and options.plat and current.plat ~= options.plat then
- -- clear configs and mark as "rebuild"
- config._CONFIGS = { __rebuild = true }
+ -- clear architecture and mark as "rebuild"
+ configs.arch = nil
+ configs.__rebuild = true
end
-- mark as "rebuild" if the arch has been changed
if current and current.arch and options.arch and current.arch ~= options.arch then
-- mark as "rebuild"
- config._CONFIGS.__rebuild = true
+ configs.__rebuild = true
end
-- mark as "rebuild" if the mode has been changed
if current and current.mode and options.mode and current.mode ~= options.mode then
-- mark as "rebuild"
- config._CONFIGS.__rebuild = true
+ configs.__rebuild = true
end
elseif errors then
-- error
@@ -260,11 +323,13 @@ function config.load()
configs.__rebuild = true
end
- -- init targets
- configs._TARGET = configs._TARGET or {}
- if name ~= "all" then
- configs._TARGET[name] = configs._TARGET[name] or {}
- end
+ -- init the platform
+ configs.plat = options.plat or configs.plat or options._DEFAULTS.plat or option.defaults("config").plat
+ assert(configs.plat)
+
+ -- init the architecture
+ configs.arch = options.arch or configs.arch or options._DEFAULTS.arch or option.defaults("config").arch
+ assert(configs.arch)
-- get the current target scope
local target = config._target()
@@ -308,8 +373,9 @@ function config.load()
end
end
- -- make the current config
- config._CURRENT = config._make(config._CONFIGS)
+ -- make the current configure
+ config._CURRENT = config._make(configs)
+
end
-- clear up and remove all auto values