summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-25 15:59:53 +0800
committerruki <[email protected]>2015-06-25 15:59:53 +0800
commit8f45b7c5b9e62f3ac2cc8782d4de1bff3ed31008 (patch)
treeb0d60cff07630412756bf5e401c61aff1db6e4b4
parent8d46305db1819357868d3c71a61d98856aa0fa5a (diff)
load and make configure for package
-rw-r--r--xmake/scripts/action/_package.lua181
-rw-r--r--xmake/scripts/base/clean.lua2
-rw-r--r--xmake/scripts/base/config.lua11
-rw-r--r--xmake/scripts/base/project.lua29
-rw-r--r--xmake/scripts/base/rule.lua14
5 files changed, 206 insertions, 31 deletions
diff --git a/xmake/scripts/action/_package.lua b/xmake/scripts/action/_package.lua
index adab5b393..ccd2c2e38 100644
--- a/xmake/scripts/action/_package.lua
+++ b/xmake/scripts/action/_package.lua
@@ -24,9 +24,12 @@
local _package = _package or {}
-- load modules
+local rule = require("base/rule")
local utils = require("base/utils")
local config = require("base/config")
+local global = require("base/global")
local string = require("base/string")
+local project = require("base/project")
local platform = require("platform/platform")
-- need access to the given file?
@@ -37,34 +40,127 @@ function _package.need(name)
end
-- configure target for the given architecture
-function _package._config(arch, target)
+function _package._config(arch, target_name)
-- need not configure it
if not arch then return true end
-- done the command
- return os.execute(string.format("xmake f -P %s -f %s -a %s %s", xmake._PROJECT_DIR, xmake._PROJECT_FILE, arch, target)) == 0;
+ return os.execute(string.format("xmake f -P %s -f %s -a %s %s", xmake._PROJECT_DIR, xmake._PROJECT_FILE, arch, target_name)) == 0;
end
-- build target for the given architecture
-function _package._build(arch, target)
+function _package._build(arch, target_name)
+
+ -- get the target name
+ if not target_name or target_name == "all" then
+ target_name = ""
+ end
-- configure it first
- if not _package._config(arch, target) then return false end
+ if not _package._config(arch, target_name) then return false end
- print(string.format("xmake -r -P %s %s", xmake._PROJECT_DIR, target))
-- rebuild it
- return os.execute(string.format("xmake -r -P %s %s", xmake._PROJECT_DIR, target)) == 0;
+ if os.execute(string.format("xmake -r -P %s %s", xmake._PROJECT_DIR, target_name)) ~= 0 then
+ -- errors
+ utils.error("build %s failed!", utils.ifelse(target_name, target_name, "all"))
+ return false
+ end
+
+ -- ok
+ return true
end
--- build target for all architectures
-function _package._build_all(archs, target)
+-- make configure for the given target
+function _package._makeconf(target_name, target)
+
+ -- check
+ assert(target_name and target)
+
+ -- the configs
+ local configs = _package._CONFIGS
+ assert(configs)
+
+ -- the architecture
+ local arch = config.get("arch")
+ if not arch then return false end
+
+ -- init configs for targets
+ configs._TARGETS = configs._TARGETS or {}
+ configs._TARGETS[target_name] = configs._TARGETS[target_name] or {}
+ local configs_target = configs._TARGETS[target_name]
+
+ -- init configs for architecture
+ configs_target[arch] = configs_target[arch] or {}
+ local configs_arch = configs_target[arch]
+
+ -- save the target kind
+ configs_arch.kind = target.kind
+
+ -- save the config file
+ configs_arch.config_h = rule.config_h(target)
+
+ -- save the target file
+ configs_arch.targetfile = rule.targetfile(target_name, target)
+
+ -- save the header files
+ configs_arch.headerfiles = rule.headerfiles(target)
- -- get the target
- if not target or target == "all" then
- target = ""
+ -- ok
+ return true
+end
+
+-- load configure for the given target
+function _package._loadconf(target_name)
+
+ -- reload configure
+ local errors = config.reload()
+ if errors then
+ -- error
+ utils.error(errors)
+ return false
+ end
+
+ -- make the platform configure
+ if not platform.make() then
+ utils.error("make platform configure: %s failed!", config.get("plat"))
+ return false
+ end
+
+ -- reload project
+ local errors = project.reload()
+ if errors then
+ -- error
+ utils.error(errors)
+ return false
+ end
+
+ -- the targets
+ local targets = project.targets()
+ assert(targets)
+
+ -- make configure for the given target
+ if target_name and target_name ~= "all" then
+ if not _package._makeconf(target_name, targets[target_name]) then
+ utils.error("make target configure: %s failed!", target_name)
+ return false
+ end
+ else
+ for target_name, target in pairs(targets) do
+ if not _package._makeconf(target_name, target) then
+ utils.error("make target configure: %s failed!", target_name)
+ return false
+ end
+ end
end
+ -- ok
+ return true
+end
+
+-- build target for all architectures
+function _package._build_all(archs, target_name)
+
-- exists the given architectures?
if archs then
@@ -74,16 +170,47 @@ function _package._build_all(archs, target)
-- build for all architectures
for _, arch in ipairs(archs) do
- if not _package._build(arch:trim(), target) then return false end
+
+ -- trim it
+ arch = arch:trim()
+
+ -- build it
+ if not _package._build(arch, target_name) then return false end
+
+ -- load configure
+ if not _package._loadconf(target_name) then return false end
+
end
-- build for single architecture
- elseif not _package._build(nil, target) then return false end
+ else
+
+ -- build it
+ if not _package._build(nil, target_name) then return false end
+
+ -- load configure
+ if not _package._loadconf(target_name) then return false end
+
+ end
-- ok
return true
end
+-- done package from the configure
+function _package._done()
+
+ -- the configs
+ local configs = _package._CONFIGS
+ assert(configs)
+
+ -- dump
+ utils.dump(configs)
+
+ -- ok
+ return true
+end
+
-- done
function _package.done()
@@ -94,13 +221,37 @@ function _package.done()
-- trace
print("package: ...")
+ -- init configs
+ _package._CONFIGS = _package._CONFIGS or {}
+ local configs = _package._CONFIGS
+
+ -- load the global configure first
+ global.load()
+
-- build the given target first for all architectures
if not _package._build_all(options.archs, options.target) then
-- errors
- utils.error("build %s failed!", utils.ifelse(options.target, options.target, "all"))
+ utils.error("build package failed!")
return false
end
-
+
+ -- save platform
+ configs.plat = config.get("plat")
+ assert(configs.plat)
+
+ -- save build directory
+ configs.buildir = config.get("buildir")
+
+ -- save project directory
+ configs.projectdir = xmake._PROJECT_DIR
+
+ -- done package
+ if not _package._done() then
+ -- errors
+ utils.error("package: failed!")
+ return false
+ end
+
-- trace
print("package: ok!")
diff --git a/xmake/scripts/base/clean.lua b/xmake/scripts/base/clean.lua
index 3426dc41e..0a84407ab 100644
--- a/xmake/scripts/base/clean.lua
+++ b/xmake/scripts/base/clean.lua
@@ -56,7 +56,7 @@ function clean._remove(filedirs)
return true
end
--- remove the given target_name
+-- remove the given target name
function clean._remove_target(target_name, target, target_only, buildir)
-- check
diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua
index d6f6d9625..eebe805bb 100644
--- a/xmake/scripts/base/config.lua
+++ b/xmake/scripts/base/config.lua
@@ -337,6 +337,17 @@ function config.clearup()
end
+-- reload configure
+function config.reload()
+
+ -- clear the old configure
+ config._CURRENT = nil
+ config._CONFIGS = nil
+
+ -- load it
+ return config.load()
+end
+
-- dump the current configure
function config.dump()
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index 7dc98b5b0..c5052dd19 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -431,27 +431,27 @@ function project._makeconf_for_target(target_name, target)
assert(target_name and target)
-- get the target configure file
- local configfile = target.config_h
- if not configfile then
+ local config_h = target.config_h
+ if not config_h then
return true
end
-- translate file path
- if not path.is_absolute(configfile) then
- configfile = path.absolute(configfile, xmake._PROJECT_DIR)
+ if not path.is_absolute(config_h) then
+ config_h = path.absolute(config_h, xmake._PROJECT_DIR)
else
- configfile = path.translate(configfile)
+ config_h = path.translate(config_h)
end
-- the prefix
local prefix = target.config_h_prefix or (target_name:upper() .. "_CONFIG")
-- open the file
- local file = project._CONFILES[configfile] or io.openmk(configfile)
+ local file = project._CONFILES[config_h] or io.openmk(config_h)
assert(file)
-- make the head
- if project._CONFILES[configfile] then file:write("\n") end
+ if project._CONFILES[config_h] then file:write("\n") end
file:write(string.format("#ifndef %s_H\n", prefix))
file:write(string.format("#define %s_H\n", prefix))
file:write("\n")
@@ -520,7 +520,7 @@ function project._makeconf_for_target(target_name, target)
file:write("#endif\n")
-- cache the file
- project._CONFILES[configfile] = file
+ project._CONFILES[config_h] = file
-- ok
return true
@@ -1154,6 +1154,19 @@ function project.load()
project._make_targets(configs)
end
+-- reload the project
+function project.reload()
+
+ -- clear it first
+ project._MTIMES = nil
+ project._TARGETS = nil
+ project._CONFILES = nil
+ project._CURDIR = nil
+
+ -- load it
+ return project.load()
+end
+
-- dump the current configure
function project.dump()
diff --git a/xmake/scripts/base/rule.lua b/xmake/scripts/base/rule.lua
index 59885d1b4..5dc4e5d53 100644
--- a/xmake/scripts/base/rule.lua
+++ b/xmake/scripts/base/rule.lua
@@ -56,21 +56,21 @@ function rule.filename(name, kind)
end
-- get configure file for the given target
-function rule.configfile(target)
+function rule.config_h(target)
-- get the target configure file
- local configfile = target.configfile
- if configfile then
+ local config_h = target.config_h
+ if config_h then
-- translate file path
- if not path.is_absolute(configfile) then
- configfile = path.absolute(configfile, xmake._PROJECT_DIR)
+ if not path.is_absolute(config_h) then
+ config_h = path.absolute(config_h, xmake._PROJECT_DIR)
else
- configfile = path.translate(configfile)
+ config_h = path.translate(config_h)
end
end
-- ok?
- return configfile
+ return config_h
end
-- get target file for the given target