summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-05 15:51:01 +0800
committerruki <[email protected]>2015-06-05 15:51:01 +0800
commitfe68854c321f2e586cab55dce6856b89241b4c20 (patch)
treeff5210d8c51de3814a77e316f51515586367cfb6 /xmake/scripts
parentce6af9d93717a57792fc7d371f0fea9c40878c2f (diff)
add table join and merge project root
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/base/preprocessor.lua3
-rw-r--r--xmake/scripts/base/project.lua45
-rw-r--r--xmake/scripts/base/table.lua69
3 files changed, 98 insertions, 19 deletions
diff --git a/xmake/scripts/base/preprocessor.lua b/xmake/scripts/base/preprocessor.lua
index 0ea137307..85d766aaf 100644
--- a/xmake/scripts/base/preprocessor.lua
+++ b/xmake/scripts/base/preprocessor.lua
@@ -23,6 +23,9 @@
-- define module: preprocessor
local preprocessor = preprocessor or {}
+-- load modules
+local utils = require("base/utils")
+
-- filter value
function preprocessor._filter(env, value, filter)
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index 3fc119330..03fe0c375 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -25,6 +25,7 @@ local project = project or {}
-- load modules
local utils = require("base/utils")
+local table = require("base/table")
local config = require("base/config")
local preprocessor = require("base/preprocessor")
@@ -87,30 +88,21 @@ function project._make_configs(scope, configs)
-- append configure to scope
elseif scope and not k:startswith("_") and k:endswith("s") then
- -- wrap it first
- local values = utils.wrap(v)
-
-- append all
- for _, _v in ipairs(values) do
+ scope[k] = scope[k] or {}
+ table.join2(scope[k], v)
- -- the configure item
- scope[k] = scope[k] or {}
- local item = scope[k]
-
- -- append it
- table.insert(item, _v)
- end
-- replace configure to scope
elseif scope and not k:startswith("_") then
+ -- the configure item
+ scope[k] = scope[k] or {}
+ local item = scope[k]
+
-- wrap it first
local values = utils.wrap(v)
if table.getn(values) == 1 then
- -- the configure item
- scope[k] = scope[k] or {}
- local item = scope[k]
-
-- replace it
item[1] = values[1]
end
@@ -128,11 +120,25 @@ function project._make()
-- init current
project._CURRENT = project._CURRENT or {}
- -- make the root configure to the current scope
- project._make_configs(nil, configs)
+ -- make the current configure
+ local root = {}
+ project._make_configs(root, configs)
- -- remove repeat values and unwrap it
+ -- merge and remove repeat values and unwrap it
for _, target in pairs(project._CURRENT) do
+
+ -- merge the root configure to all targets
+ for k, v in pairs(root) do
+ if not target[k] then
+ -- insert it
+ target[k] = v
+ elseif not k:startswith("_") and k:endswith("s") then
+ -- join root and target and update it
+ target[k] = table.join(root, target[k])
+ end
+ end
+
+ -- remove repeat values and unwrap it
for k, v in pairs(target) do
-- remove repeat first
@@ -182,7 +188,8 @@ function project.loadxproj(file)
, "mxxflags"
, "ldflags"
, "shflags"
- , "defines"}
+ , "defines"
+ , "optimize"}
-- init filter
local filter = function (v)
diff --git a/xmake/scripts/base/table.lua b/xmake/scripts/base/table.lua
new file mode 100644
index 000000000..1e0250bce
--- /dev/null
+++ b/xmake/scripts/base/table.lua
@@ -0,0 +1,69 @@
+--!The Automatic Cross-platform Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file table.lua
+--
+
+-- define module: table
+local table = table or {}
+
+-- join all objects and tables
+function table.join(...)
+
+ -- done
+ local args = {...}
+ local result = {}
+ for _, t in ipairs(args) do
+ if type(t) == "table" then
+ for _, v in ipairs(t) do
+ table.insert(result, v)
+ end
+ else
+ table.insert(result, t)
+ end
+ end
+
+ -- ok?
+ return result
+end
+
+-- join all objects and tables to self
+function table.join2(self, ...)
+
+ -- check
+ assert(self and type(self) == "table")
+
+ -- done
+ local args = {...}
+ for _, t in ipairs(args) do
+ if type(t) == "table" then
+ for _, v in ipairs(t) do
+ table.insert(self, v)
+ end
+ else
+ table.insert(self, t)
+ end
+ end
+
+ -- ok?
+ return self
+end
+
+-- return module: table
+return table