summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-18 13:05:14 +0800
committerruki <[email protected]>2015-05-18 13:05:14 +0800
commitf1de3034b9afbb88f83501730bf27c31078818ed (patch)
tree88a2c43f6521628df368071d44c861eb826636f4 /xmake/scripts
parent3f53e1ea0f6c9deff5295e689df141feba9cce4c (diff)
build makefile
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/action/_build.lua50
-rw-r--r--xmake/scripts/base/config.lua28
-rw-r--r--xmake/scripts/base/makefile.lua22
-rw-r--r--xmake/scripts/base/project.lua4
4 files changed, 93 insertions, 11 deletions
diff --git a/xmake/scripts/action/_build.lua b/xmake/scripts/action/_build.lua
new file mode 100644
index 000000000..19acd924f
--- /dev/null
+++ b/xmake/scripts/action/_build.lua
@@ -0,0 +1,50 @@
+--!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) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file _build.lua
+--
+
+-- define module: _build
+local _build = _build or {}
+
+-- load modules
+local utils = require("base/utils")
+local config = require("base/config")
+local makefile = require("base/makefile")
+
+-- done the given config
+function _build.done()
+
+ -- TODO
+ -- rebuild, update
+
+ -- build target for makefile
+ if not makefile.build(config.target_name()) then
+ -- error
+ utils.error("build target: %s failed!", config.target_name())
+ return false
+ end
+
+ -- ok
+ print("build ok!")
+ return true
+end
+
+-- return module: _build
+return _build
diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua
index 31fb4dd81..6ea64b372 100644
--- a/xmake/scripts/base/config.lua
+++ b/xmake/scripts/base/config.lua
@@ -140,13 +140,9 @@ function config._save(file, object)
return config._save_with_level(file, object, 0)
end
--- get the current target scope
-function config.getarget()
-
- -- check
- local configs = config._CONFIGS
- assert(configs)
-
+-- get the current target name
+function config.target_name()
+
-- the options
local options = xmake._OPTIONS
assert(options)
@@ -155,6 +151,20 @@ function config.getarget()
local name = options.target or options._DEFAULTS.target
assert(name and type(name) == "string")
+ -- ok
+ return name
+end
+
+-- get the current target scope
+function config.target()
+
+ -- check
+ local configs = config._CONFIGS
+ assert(configs)
+
+ -- the target name
+ local name = config.target_name()
+
-- for all targets?
if name == "all" then
return configs
@@ -232,7 +242,7 @@ function config.loadxconf()
config._CONFIGS = newenv._CONFIGS
-- clear configs if the host environment has been changed
- local target = config.getarget()
+ local target = config.target()
if target and target.host ~= xmake._HOST then
config._CONFIGS = {}
end
@@ -257,7 +267,7 @@ function config.loadxconf()
end
-- get the current target scope
- local target = config.getarget()
+ local target = config.target()
assert(target and type(target) == "table")
-- merge xmake._OPTIONS to target
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua
index 754131fa4..b7d8813ee 100644
--- a/xmake/scripts/base/makefile.lua
+++ b/xmake/scripts/base/makefile.lua
@@ -135,5 +135,27 @@ function makefile.make()
return true
end
+-- build target
+function makefile.build(target)
+
+ -- check
+ assert(target and type(target) == "string")
+
+ -- the configs
+ local configs = config._CONFIGS
+ assert(configs and configs.buildir)
+
+ -- done build
+ local ok = os.execute(string.format("make -f %s %s", configs.buildir .. "/makefile", target))
+ if ok ~= 0 then
+ -- error
+ utils.error("build target: %s failed!", target)
+ return false
+ end
+
+ -- ok
+ return true
+end
+
-- return module: makefile
return makefile
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index 73483ba5c..559501e00 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -55,7 +55,7 @@ function project.loadxproj(file)
-- init filter
local filter = function (v)
if v == "buildir" then
- local target = config.getarget()
+ local target = config.target()
return utils.ifelse(target, target.output, nil);
elseif v == "projectdir" then
return xmake._PROJECT_DIR
@@ -73,7 +73,7 @@ function project.loadxproj(file)
local configs = {}
-- get the config for the current target
- local target = config.getarget()
+ 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