summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-20 10:40:16 +0800
committerruki <[email protected]>2015-05-20 10:40:16 +0800
commitd0c91342731cdbaa3e25e239574ce41593297ee1 (patch)
treecab29bc6d12be7aa4f67e6dad5a57dbe73717220
parent9c161e7f113de8c020df176c1fab87e8c93083f5 (diff)
make the current project configure
-rw-r--r--tests/console/xmake.xproj19
-rw-r--r--xmake/scripts/base/config.lua18
-rw-r--r--xmake/scripts/base/makefile.lua7
-rw-r--r--xmake/scripts/base/project.lua130
-rw-r--r--xmake/scripts/base/utils.lua61
5 files changed, 211 insertions, 24 deletions
diff --git a/tests/console/xmake.xproj b/tests/console/xmake.xproj
index ede8887f4..b1aeba5df 100644
--- a/tests/console/xmake.xproj
+++ b/tests/console/xmake.xproj
@@ -15,6 +15,17 @@
]
project: console
{
+ # the modes
+ modes: debug
+ {
+ defines: DEBUG=1
+ }
+
+ modes: release, profile
+ {
+ defines: DEBUG=0
+ }
+
target: hello1
{
kind: static
@@ -46,6 +57,12 @@ project: console
linkdirs: src/hello1
includedirs: src/hello1
cflags: -DHELLO1
+
+ # the modes
+ modes: release
+ {
+ defines: NDEBUG
+ }
}
target: demo_cpp
@@ -76,7 +93,7 @@ project: console
deps: hello3
files: src/demo/*.mm
mxflags: -DHELLO3
- ldflags: -lhello3, -L$(buildir)/lib
+ ldflags: -lhello3, -lhello3, -L$(buildir)/lib
# the linux platform
platforms: linux
diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua
index 36a02120b..d2ffc546b 100644
--- a/xmake/scripts/base/config.lua
+++ b/xmake/scripts/base/config.lua
@@ -29,7 +29,7 @@ local utils = require("base/utils")
local option = require("base/option")
local preprocessor = require("base/preprocessor")
--- auto configs
+-- make the automatic configure
function config._auto(name)
-- get platform or host
@@ -140,10 +140,10 @@ function config._save(file, object)
return config._save_with_level(file, object, 0)
end
--- make config for the current target
+-- make configure for the current target
function config._make()
- -- check
+ -- the configs
local configs = config._CONFIGS
assert(configs)
@@ -153,7 +153,7 @@ function config._make()
-- init current config
config._CURRENT = config._CURRENT or {}
- local current = config._CURRENT;
+ local current = config._CURRENT
-- init the current target
current.target = options.target or options._DEFAULTS.target
@@ -205,7 +205,7 @@ function config._target()
end
end
--- get the given config from the current
+-- get the given configure from the current
function config.get(name)
-- check
@@ -274,7 +274,7 @@ function config.loadxconf()
-- load and execute the xmake.xconf
local path = options.project .. "/xmake.xconf"
- local newenv, errors = preprocessor.loadfile(path, "config", configures, {"target"})
+ local newenv = preprocessor.loadfile(path, "config", configures, {"target"})
-- exists local configures?
if newenv then
@@ -287,10 +287,6 @@ function config.loadxconf()
if target and target.host ~= xmake._HOST then
config._CONFIGS = {}
end
- elseif errors then
- -- error
- utils.error("load %s failed!", path)
- utils.error("%s", errors)
end
-- the target name
@@ -350,7 +346,7 @@ function config.loadxconf()
config._make()
end
--- dump configs
+-- dump the current configure
function config.dump()
-- check
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua
index 7d2680f61..b09a1b237 100644
--- a/xmake/scripts/base/makefile.lua
+++ b/xmake/scripts/base/makefile.lua
@@ -69,6 +69,9 @@ function makefile._srcfiles(target)
end
end
+ -- remove repeat files
+ srcfiles = utils.unique(srcfiles)
+
-- ok?
return srcfiles
end
@@ -194,10 +197,10 @@ end
function makefile._make_targets(file)
-- check
- assert(file and project and project._CONFIGS)
+ assert(file)
-- get all project targets
- local targets = project._CONFIGS._TARGET
+ local targets = project.targets()
if not targets then
-- error
utils.error("not found target in this project!")
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index 49088fca4..0b7783e2c 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -28,6 +28,117 @@ local utils = require("base/utils")
local config = require("base/config")
local preprocessor = require("base/preprocessor")
+-- make the given configure to scope
+function project._make_configs(scope, configs)
+
+ -- check
+ assert(scope and configs)
+
+ -- the current mode
+ local mode = config.get("mode")
+ assert(mode)
+
+ -- the current platform
+ local plat = config.get("plat")
+ assert(plat)
+
+ -- done
+ for k, v in pairs(configs) do
+
+ -- check
+ assert(type(k) == "string")
+
+ -- enter the platform configure?
+ if k == "_PLATFORMS" then
+
+ -- append configure to scope for the current mode
+ for _k, _v in pairs(v) do
+ if _k == plat then
+ project._make_configs(scope, _v)
+ end
+ end
+
+ -- enter the mode configure?
+ elseif k == "_MODES" then
+
+ -- append configure to scope for the current mode
+ for _k, _v in pairs(v) do
+ if _k == mode then
+ project._make_configs(scope, _v)
+ end
+ end
+
+ -- append configure to scope
+ elseif not k:startswith("_") then
+
+ -- wrap it first
+ local values = utils.wrap(v)
+
+ -- append all
+ for _, _v in ipairs(values) do
+
+ -- the configure item
+ scope[k] = scope[k] or {}
+ local item = scope[k]
+
+ -- append it
+ item[table.getn(item) + 1] = _v
+ end
+ end
+ end
+end
+
+-- make the current project configure
+function project._make()
+
+ -- the configs
+ local configs = project._CONFIGS
+ assert(configs and configs._TARGET)
+
+ -- init current config
+ project._CURRENT = project._CURRENT or {}
+ local current = project._CURRENT
+
+ -- init all targets
+ for name, target in pairs(configs._TARGET) do
+
+ -- init target scope first
+ current[name] = current[name] or {}
+ local scope = current[name]
+
+ -- make the root configure to this scope
+ project._make_configs(scope, configs)
+
+ -- make the target configure to this scope
+ project._make_configs(scope, target)
+ end
+
+ -- remove repeat values and unwrap it
+ for _, target in pairs(current) do
+ for k, v in pairs(target) do
+
+ -- remove repeat first
+ v = utils.unique(v)
+
+ -- unwrap it if be only one
+ v = utils.unwrap(v)
+
+ -- update it
+ target[k] = v
+ end
+ end
+end
+
+-- get the current configure for targets
+function project.targets()
+
+ -- check
+ assert(project._CURRENT)
+
+ -- return it
+ return project._CURRENT
+end
+
-- load xproj
function project.loadxproj(file)
@@ -35,11 +146,10 @@ function project.loadxproj(file)
assert(file)
-- init configures
- local configures = { "kind"
+ local configures = { "kind"
, "deps"
, "files"
, "links"
- , "mflags"
, "headers"
, "headerdir"
, "targetdir"
@@ -47,9 +157,12 @@ function project.loadxproj(file)
, "linkdirs"
, "includedirs"
, "cflags"
+ , "cxflags"
, "cxxflags"
- , "ldflags"
+ , "mflags"
, "mxflags"
+ , "mxxflags"
+ , "ldflags"
, "defines"}
-- init filter
@@ -86,7 +199,7 @@ function project.loadxproj(file)
end
-- load and execute the xmake.xproj
- local newenv, errors = preprocessor.loadfile(file, "project", configures, {"target", "platforms"}, filter, import)
+ local newenv, errors = preprocessor.loadfile(file, "project", configures, {"target", "platforms", "modes"}, filter, import)
if newenv and newenv._CONFIGS then
-- ok
project._CONFIGS = newenv._CONFIGS
@@ -98,17 +211,20 @@ function project.loadxproj(file)
return string.format("load %s failed!", file)
end
+ -- make the current project configure
+ project._make()
+
end
--- dump configs
+-- dump the current configure
function project.dump()
-- check
- assert(project._CONFIGS)
+ assert(project._CURRENT)
-- dump
if xmake._OPTIONS.verbose then
- utils.dump(project._CONFIGS, "_PARENT")
+ utils.dump(project._CURRENT)
end
end
diff --git a/xmake/scripts/base/utils.lua b/xmake/scripts/base/utils.lua
index 61998339e..7e4322eb9 100644
--- a/xmake/scripts/base/utils.lua
+++ b/xmake/scripts/base/utils.lua
@@ -76,7 +76,7 @@ function utils._dump_with_level(object, exclude, level)
for l = 1, level do
io.write(" ")
end
- io.write("{\n")
+ io.write("{\n")
-- dump body
local i = 0
@@ -85,12 +85,11 @@ function utils._dump_with_level(object, exclude, level)
-- exclude some keys
if not exclude or type(k) ~= "string" or not k:find(exclude) then
- -- dump spaces
+ -- dump spaces and separator
for l = 1, level do
io.write(" ")
end
- -- dump separator
io.write(utils.ifelse(i == 0, " ", ", "))
-- dump key
@@ -134,6 +133,23 @@ function utils.dump(object, exclude)
return object
end
+-- unwrap object if be only one
+function utils.unwrap(object)
+
+ -- check
+ assert(object)
+
+ -- unwrap it
+ if type(object) == "table" and table.getn(object) == 1 then
+ for _, v in pairs(object) do
+ return v
+ end
+ end
+
+ -- ok
+ return object
+end
+
-- wrap object to table
function utils.wrap(object)
@@ -144,6 +160,45 @@ function utils.wrap(object)
if type(object) ~= "table" then
return {object}
end
+
+ -- ok
+ return object
+end
+
+-- remove repeat from the given array
+function utils.unique(array)
+
+ -- check
+ assert(array)
+
+ -- remove repeat
+ if type(array) == "table" then
+
+ -- not only one?
+ if table.getn(array) ~= 1 then
+
+ -- make unique table
+ local unique = {}
+ for _, v in ipairs(array) do
+ if type(v) == "string" then
+ unique[v] = v
+ else
+ unique["\"" .. v .. "\""] = v
+ end
+ end
+
+ -- make array again
+ array = {}
+ local i = 1
+ for _, v in pairs(unique) do
+ array[i] = v
+ i = i + 1
+ end
+ end
+ end
+
+ -- ok
+ return array
end
-- return module: utils