diff options
| author | ruki <[email protected]> | 2015-05-20 08:50:04 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-05-20 08:50:04 +0800 |
| commit | 9c161e7f113de8c020df176c1fab87e8c93083f5 (patch) | |
| tree | 3946ab2b828aa9365619eb07ed0d51b6f1fd721d | |
| parent | bf3130929b7cf628dad0300a835e13c7bb91feb0 (diff) | |
make config for the current target
| -rw-r--r-- | xmake/scripts/action/_build.lua | 4 | ||||
| -rw-r--r-- | xmake/scripts/base/config.lua | 74 | ||||
| -rw-r--r-- | xmake/scripts/base/main.lua | 14 | ||||
| -rw-r--r-- | xmake/scripts/base/makefile.lua | 43 | ||||
| -rw-r--r-- | xmake/scripts/base/project.lua | 12 | ||||
| -rw-r--r-- | xmake/scripts/platform/platform.lua | 12 |
6 files changed, 95 insertions, 64 deletions
diff --git a/xmake/scripts/action/_build.lua b/xmake/scripts/action/_build.lua index 19acd924f..cd80616f1 100644 --- a/xmake/scripts/action/_build.lua +++ b/xmake/scripts/action/_build.lua @@ -35,9 +35,9 @@ function _build.done() -- rebuild, update -- build target for makefile - if not makefile.build(config.target_name()) then + if not makefile.build(config.get("target")) then -- error - utils.error("build target: %s failed!", config.target_name()) + utils.error("build target: %s failed!", config.get("target")) return false end diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua index 6ea64b372..36a02120b 100644 --- a/xmake/scripts/base/config.lua +++ b/xmake/scripts/base/config.lua @@ -140,30 +140,61 @@ function config._save(file, object) return config._save_with_level(file, object, 0) end --- get the current target name -function config.target_name() - +-- make config for the current target +function config._make() + + -- check + local configs = config._CONFIGS + assert(configs) + -- the options local options = xmake._OPTIONS assert(options) - -- the target name - local name = options.target or options._DEFAULTS.target - assert(name and type(name) == "string") + -- init current config + config._CURRENT = config._CURRENT or {} + local current = config._CURRENT; - -- ok - return name + -- init the current target + current.target = options.target or options._DEFAULTS.target + assert(current.target) + + -- get configs from all targets first + for k, v in pairs(configs) do + if type(k) == "string" and not k:startswith("_") then + current[k] = v + end + end + + -- get configs from the current target + if configs._TARGET and current.target ~= "all" then + + -- get the target config + local target_config = configs._TARGET[current.target] + if target_config then + + -- merge to the current config + for k, v in pairs(target_config) do + current[k] = v + end + end + end end -- get the current target scope -function config.target() +function config._target() + + -- the options + local options = xmake._OPTIONS + assert(options) -- check local configs = config._CONFIGS assert(configs) - + -- the target name - local name = config.target_name() + local name = options.target or options._DEFAULTS.target + assert(name and type(name) == "string") -- for all targets? if name == "all" then @@ -174,6 +205,16 @@ function config.target() end end +-- get the given config from the current +function config.get(name) + + -- check + assert(config._CURRENT) + + -- get it + return config._CURRENT[name] +end + -- save xmake.xconf function config.savexconf() @@ -242,7 +283,7 @@ function config.loadxconf() config._CONFIGS = newenv._CONFIGS -- clear configs if the host environment has been changed - local target = config.target() + local target = config._target() if target and target.host ~= xmake._HOST then config._CONFIGS = {} end @@ -267,7 +308,7 @@ function config.loadxconf() end -- get the current target scope - local target = config.target() + local target = config._target() assert(target and type(target) == "table") -- merge xmake._OPTIONS to target @@ -304,17 +345,20 @@ function config.loadxconf() end end end + + -- make the current config + config._make() end -- dump configs function config.dump() -- check - assert(config._CONFIGS) + assert(config._CURRENT) -- dump if xmake._OPTIONS.verbose then - utils.dump(config._CONFIGS, "_PARENT") + utils.dump(config._CURRENT) end end diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua index e09613254..97ec71b01 100644 --- a/xmake/scripts/base/main.lua +++ b/xmake/scripts/base/main.lua @@ -282,19 +282,17 @@ function main._done_option() end assert(options.file) + -- init the build directory + if options.buildir and path.is_absolute(options.buildir) then + options.buildir = path.relative(options.buildir, xmake._PROJECT_DIR) + end + -- load xmake.xconf file first local errors = config.loadxconf() if not errors then -- load xmake.xproj file errors = project.loadxproj(options.file) end - assert(config._CONFIGS) - - -- init the build directory - if config._CONFIGS.buildir and path.is_absolute(config._CONFIGS.buildir) then - config._CONFIGS.buildir = path.relative(config._CONFIGS.buildir, xmake._PROJECT_DIR) - end - assert(config._CONFIGS.buildir) -- done help if options.help then @@ -329,7 +327,7 @@ function main._done_option() -- init platform if not platform.init() then -- error - utils.error("init platform: %s failed!", config.target().plat) + utils.error("init platform: %s failed!", config.get("plat")) return false end diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua index becf253d7..7d2680f61 100644 --- a/xmake/scripts/base/makefile.lua +++ b/xmake/scripts/base/makefile.lua @@ -57,6 +57,11 @@ function makefile._srcfiles(target) -- process source files for _, file in ipairs(files) do + -- convert to the relative path + if path.is_absolute(file) then + file = path.relative(file, xmake._PROJECT_DIR) + end + -- save it srcfiles[i] = file i = i + 1 @@ -69,17 +74,17 @@ function makefile._srcfiles(target) end -- get object files for the given source files -function makefile._objfiles(srcfiles) +function makefile._objfiles(name, srcfiles) -- check - assert(srcfiles) - - -- the platform configs - local configs = platform._CONFIGS - assert(configs and configs.format) + assert(name and srcfiles) + -- the build directory + local buildir = config.get("buildir") + assert(buildir) + -- the object file format - local format = configs.format.object + local format = platform._CONFIGS.format.object assert(format) -- make object files @@ -88,7 +93,7 @@ function makefile._objfiles(srcfiles) for _, srcfile in ipairs(srcfiles) do -- make object file - local objfile = path.directory(srcfile) .. "/" .. format[1] .. path.basename(srcfile) .. format[2] + local objfile = string.format("%s/%s/%s/%s/%s/%s", buildir, name, path.directory(srcfile), format[1], path.basename(srcfile), format[2]) -- save it objfiles[i] = path.translate(objfile) @@ -153,7 +158,7 @@ function makefile._make_target(file, name, target) -- get source and object files local srcfiles = makefile._srcfiles(target) - local objfiles = makefile._objfiles(srcfiles) + local objfiles = makefile._objfiles(name, srcfiles) assert(srcfiles and objfiles) -- make head @@ -227,17 +232,17 @@ end -- make makefile in the build directory function makefile.make() - -- the configs - local configs = config._CONFIGS - assert(configs and configs.buildir) + -- get the build directory + local buildir = config.get("buildir") + assert(buildir) -- make the build directory - if not os.isdir(configs.buildir) then - assert(os.mkdir(configs.buildir)) + if not os.isdir(buildir) then + assert(os.mkdir(buildir)) end -- open the makefile - local path = configs.buildir .. "/makefile" + local path = buildir .. "/makefile" local file = io.open(path, "w") if not file then -- error @@ -274,12 +279,12 @@ function makefile.build(target) -- check assert(target and type(target) == "string") - -- the configs - local configs = config._CONFIGS - assert(configs and configs.buildir) + -- get the build directory + local buildir = config.get("buildir") + assert(buildir) -- done build - local ok = os.execute(string.format("make -f %s %s", configs.buildir .. "/makefile", target)) + local ok = os.execute(string.format("make -f %s %s", buildir .. "/makefile", target)) if ok ~= 0 then -- error utils.error("build target: %s failed!", target) diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua index 559501e00..49088fca4 100644 --- a/xmake/scripts/base/project.lua +++ b/xmake/scripts/base/project.lua @@ -55,8 +55,7 @@ function project.loadxproj(file) -- init filter local filter = function (v) if v == "buildir" then - local target = config.target() - return utils.ifelse(target, target.output, nil); + return config.get("buildir") elseif v == "projectdir" then return xmake._PROJECT_DIR end @@ -73,13 +72,8 @@ function project.loadxproj(file) local configs = {} -- get the config for the current target - local target = config.target() - if target then - for k, v in pairs(target) do - if k and type(k) == "string" and not k:startswith("_") then - configs[k] = v - end - end + for k, v in pairs(config._CURRENT) do + configs[k] = v end -- init the project directory diff --git a/xmake/scripts/platform/platform.lua b/xmake/scripts/platform/platform.lua index 6ee8de802..e6c369236 100644 --- a/xmake/scripts/platform/platform.lua +++ b/xmake/scripts/platform/platform.lua @@ -34,18 +34,8 @@ function platform.init() platform._CONFIGS = platform._CONFIGS or {} local configs = platform._CONFIGS - -- get target - local target = config.target() - assert(target) - - -- init configs - configs.plat = target.plat - configs.host = target.host - configs.arch = target.arch - configs.mode = target.mode - -- load platform - local p = require("platform/_" .. target.plat) + local p = require("platform/_" .. config.get("plat")) if not p then return false end |
