diff options
| author | ruki <[email protected]> | 2015-06-08 14:38:34 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-08 14:38:34 +0800 |
| commit | d3258129a4a1ba9886b7e8d773ba8e4ec956b4a6 (patch) | |
| tree | 23c4c9a6087148c0c65f720fd5e87742429e9108 /xmake/scripts | |
| parent | 4d2fbb049f34e5899d962a148bf5e560fe9d978c (diff) | |
make switches to configure file
Diffstat (limited to 'xmake/scripts')
| -rw-r--r-- | xmake/scripts/action/_config.lua | 12 | ||||
| -rw-r--r-- | xmake/scripts/base/clean.lua | 8 | ||||
| -rw-r--r-- | xmake/scripts/base/project.lua | 138 | ||||
| -rw-r--r-- | xmake/scripts/base/rule.lua | 18 |
4 files changed, 175 insertions, 1 deletions
diff --git a/xmake/scripts/action/_config.lua b/xmake/scripts/action/_config.lua index 841e84fe2..7726be958 100644 --- a/xmake/scripts/action/_config.lua +++ b/xmake/scripts/action/_config.lua @@ -26,11 +26,16 @@ local _config = _config or {} -- load modules local utils = require("base/utils") local config = require("base/config") +local project = require("base/project") local makefile = require("base/makefile") -- done the given config function _config.done() + -- the options + local options = xmake._OPTIONS + assert(options) + -- dump config config.dump() @@ -41,6 +46,13 @@ function _config.done() return false end + -- make the configure file for the given target + if not project.makeconf(options.target) then + -- error + utils.error("make configure failed!") + return false + end + -- make makefile if not makefile.make() then -- error diff --git a/xmake/scripts/base/clean.lua b/xmake/scripts/base/clean.lua index 3426dc41e..e31466bdc 100644 --- a/xmake/scripts/base/clean.lua +++ b/xmake/scripts/base/clean.lua @@ -61,7 +61,13 @@ function clean._remove_target(target_name, target, target_only, buildir) -- check assert(target_name and target) - + + -- remove the configure file + local configfile = rule.configfile(target) + if configfile and not clean._remove(configfile) then + return false + end + -- remove the target file if not clean._remove(rule.targetfile(target_name, target, buildir)) then return false diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua index a0e963909..b8180fef7 100644 --- a/xmake/scripts/base/project.lua +++ b/xmake/scripts/base/project.lua @@ -24,11 +24,125 @@ local project = project or {} -- load modules +local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local config = require("base/config") local preprocessor = require("base/preprocessor") +-- make configure for the given target_name +function project._makeconf_for_target(target_name, target) + + -- check + assert(target_name and target) + + -- get the target configure file + local configfile = target.configfile + if not configfile then + return true + end + + -- translate file path + if not path.is_absolute(configfile) then + configfile = path.absolute(configfile, xmake._PROJECT_DIR) + else + configfile = path.translate(configfile) + end + + -- the prefix + local prefix = target_name:upper() + + -- open the file + local file = io.open(configfile, "w") + + -- make the head + file:write(string.format("#ifndef %s_CONFIG_H\n", prefix)) + file:write(string.format("#define %s_CONFIG_H\n", prefix)) + file:write("\n") + + -- make the defines + if target.defines then + file:write("// defines\n") + for _, define in ipairs(utils.wrap(target.defines)) do + file:write(string.format("#define %s\n", define)) + end + file:write("\n") + end + + -- load the switches + local switches = {} + if target.switches then + for _, switch in ipairs(utils.wrap(target.switches)) do + table.insert(switches, switch) + end + end + if target.switchfiles then + for _, switchfile in ipairs(utils.wrap(target.switchfiles)) do + if not path.is_absolute(switchfile) then + switchfile = path.absolute(switchfile, xmake._PROJECT_DIR) + end + local newenv, errors = preprocessor.loadfile(switchfile, "switches", {"defines"}) + if newenv and newenv._CONFIGS then + if newenv._CONFIGS.defines then + for _, switch in ipairs(newenv._CONFIGS.defines) do + table.insert(switches, switch) + end + end + else + -- error + utils.error(errors) + assert(false) + end + end + end + + -- make the switches + if #switches ~= 0 then + file:write("// switches\n") + for _, switch in ipairs(switches) do + file:write(string.format("#define %s\n", switch)) + end + file:write("\n") + end + + -- make the tail + file:write("#endif\n") + + -- exit the file + file:close() + + -- ok + return true +end + +-- make the configure file for the given target and dependents +function project._makeconf_for_target_and_deps(target_name) + + -- the targets + local targets = project.targets() + assert(targets) + + -- the target + local target = targets[target_name] + assert(target) + + -- make configure for the target + if not project._makeconf_for_target(target_name, target) then + return false + end + + -- exists the dependent targets? + if target.deps then + local deps = utils.wrap(target.deps) + for _, dep in ipairs(deps) do + if not project._makeconf_for_target_and_deps(dep) then return false end + end + end + + -- ok + return true +end + -- make the given configure to scope function project._make_configs(scope, configs) @@ -304,6 +418,7 @@ function project.loadxproj(file) , "objectdir" , "linkdirs" , "includedirs" + , "configfile" , "cflags" , "cxflags" , "cxxflags" @@ -386,5 +501,28 @@ function project.dump() end +-- make the configure file for the given target +function project.makeconf(target_name) + + -- the target name + if target_name and target_name ~= "all" then + -- make configure for the target and dependents + if not project._makeconf_for_target_and_deps(target_name) then return false end + else + + -- the targets + local targets = project.targets() + assert(targets) + + -- make configure for the targets + for target_name, target in pairs(targets) do + if not project._makeconf_for_target(target_name, target) then return false end + end + end + + -- ok + return true +end + -- return module: project return project diff --git a/xmake/scripts/base/rule.lua b/xmake/scripts/base/rule.lua index 795b7c1ab..6ce441be8 100644 --- a/xmake/scripts/base/rule.lua +++ b/xmake/scripts/base/rule.lua @@ -55,6 +55,24 @@ function rule.filename(name, kind) return format[1] .. name .. format[2] end +-- get configure file for the given target +function rule.configfile(target) + + -- get the target configure file + local configfile = target.configfile + if configfile then + -- translate file path + if not path.is_absolute(configfile) then + configfile = path.absolute(configfile, xmake._PROJECT_DIR) + else + configfile = path.translate(configfile) + end + end + + -- ok? + return configfile +end + -- get target file for the given target function rule.targetfile(target_name, target, buildir) |
