summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-03-18 20:22:38 +0800
committerruki <[email protected]>2016-03-18 20:22:38 +0800
commit413190f470fd28db5fb3f1c75a2b90183a327197 (patch)
treeb1a0833ff7e35a6ef81f597b6d8af5f90d6d968c
parent7a67767e0df44d9ef02daab981f7e300c627b95d (diff)
wrap target instance
-rwxr-xr-xxmake/actions/config/config_h.lua27
-rw-r--r--xmake/core/project/project.lua22
-rw-r--r--xmake/core/project/target.lua17
-rw-r--r--xmake/core/sandbox/modules/import/core/project/target.lua38
4 files changed, 88 insertions, 16 deletions
diff --git a/xmake/actions/config/config_h.lua b/xmake/actions/config/config_h.lua
index cd34647d1..c28e49f89 100755
--- a/xmake/actions/config/config_h.lua
+++ b/xmake/actions/config/config_h.lua
@@ -26,14 +26,14 @@ import("core.project.config")
import("core.project.project")
-- make configure for the given target name
-function _make_for_target(files, targetname, target)
+function _make_for_target(files, target)
-- get the target configure file
- local config_h = target.config_h
+ local config_h = target:get("config_h")
if not config_h then return end
-- the prefix
- local prefix = target.config_h_prefix or (targetname:upper() .. "_CONFIG")
+ local prefix = target:get("config_h_prefix") or (target:name():upper() .. "_CONFIG")
-- open the file
local file = files[config_h] or io.open(config_h, "w")
@@ -45,12 +45,13 @@ function _make_for_target(files, targetname, target)
file:print("")
-- make version
- if target.version then
+ local version = target:get("version")
+ if version then
file:print("// version")
- file:print("#define %s_VERSION \"%s\"", prefix, target.version)
+ file:print("#define %s_VERSION \"%s\"", prefix, version)
local i = 1
local m = {"MAJOR", "MINOR", "ALTER"}
- for v in target.version:gmatch("%d+") do
+ for v in version:gmatch("%d+") do
file:print("#define %s_VERSION_%s %s", prefix, m[i], v)
i = i + 1
if i > 3 then break end
@@ -60,13 +61,13 @@ function _make_for_target(files, targetname, target)
end
-- make the defines
- local defines = table.copy(target.defines_h)
+ local defines = table.copy(target:get("defines_h"))
-- make the undefines
- local undefines = table.copy(target.undefines_h)
+ local undefines = table.copy(target:get("undefines_h"))
-- make the options
- for _, name in ipairs(table.wrap(target.options)) do
+ for _, name in ipairs(table.wrap(target:get("options"))) do
-- get option if be enabled
local opt = nil
@@ -115,10 +116,10 @@ function _make_for_target_with_deps(files, targetname)
local target = project.target(targetname)
-- make configure for the target
- _make_for_target(files, targetname, target)
+ _make_for_target(files, target)
-- make configure for the dependent targets?
- for _, dep in ipairs(table.wrap(target.deps)) do
+ for _, dep in ipairs(table.wrap(target:get("deps"))) do
_make_for_target_with_deps(files, dep)
end
@@ -142,8 +143,8 @@ function make()
else
-- make configure for all targets
- for name, target in pairs(project.targets()) do
- _make_for_target(files, name, target)
+ for _, target in pairs(project.targets()) do
+ _make_for_target(files, target)
end
end
diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua
index c6aa99f42..8e941fb2e 100644
--- a/xmake/core/project/project.lua
+++ b/xmake/core/project/project.lua
@@ -801,9 +801,9 @@ function project.load()
return false, errors
end
- -- load targets
- local targets, errors = interp:load(xmake._PROJECT_FILE, "target", true, true)
- if not targets then
+ -- load results
+ local results, errors = interp:load(xmake._PROJECT_FILE, "target", true, true)
+ if not results then
return false, errors
end
@@ -813,6 +813,22 @@ function project.load()
return false, errors
end
+ -- make targets
+ local targets = {}
+ for targetname, targetinfo in pairs(results) do
+
+ -- init a target instance
+ local instance = table.inherit(target)
+ assert(instance)
+
+ -- save name and info
+ instance._NAME = targetname
+ instance._INFO = targetinfo
+
+ -- save it
+ targets[targetname] = instance
+ end
+
-- save targets
project._TARGETS = targets
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua
index a1fcda511..a213a4b79 100644
--- a/xmake/core/project/target.lua
+++ b/xmake/core/project/target.lua
@@ -39,5 +39,22 @@ function target.filename(name, kind)
return format[1] .. name .. format[2]
end
+-- get the target info
+function target.get(self, infoname)
+
+ -- check
+ assert(self and self._INFO and infoname)
+
+ -- get it
+ return self._INFO[infoname]
+end
+
+-- get the target name
+function target.name(self)
+
+ -- get it
+ return self._NAME
+end
+
-- return module
return target
diff --git a/xmake/core/sandbox/modules/import/core/project/target.lua b/xmake/core/sandbox/modules/import/core/project/target.lua
new file mode 100644
index 000000000..ca9394d9e
--- /dev/null
+++ b/xmake/core/sandbox/modules/import/core/project/target.lua
@@ -0,0 +1,38 @@
+--!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) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file target.lua
+--
+
+-- define module
+local sandbox_core_project_target = sandbox_core_project_target or {}
+
+-- load modules
+local project = require("project/project")
+local raise = require("sandbox/modules/raise")
+
+-- get the filename from the given name and kind
+function sandbox_core_project_target.filename(name, kind)
+
+ -- get it
+ return target.filename(name, kind)
+end
+
+-- return module
+return sandbox_core_project_target