summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-18 12:45:41 +0800
committerruki <[email protected]>2015-05-18 12:45:41 +0800
commit3f53e1ea0f6c9deff5295e689df141feba9cce4c (patch)
treee8f461081849fa77b31a3b29e57e846de8cd5e8f /xmake/scripts
parent4e9518e18e817551772545092b186e8f570b4a0f (diff)
make target and dependence for makefile
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/action/_config.lua19
-rw-r--r--xmake/scripts/base/makefile.lua112
-rw-r--r--xmake/scripts/base/utils.lua12
3 files changed, 133 insertions, 10 deletions
diff --git a/xmake/scripts/action/_config.lua b/xmake/scripts/action/_config.lua
index 53e41b651..1af22d27e 100644
--- a/xmake/scripts/action/_config.lua
+++ b/xmake/scripts/action/_config.lua
@@ -24,7 +24,6 @@
local _config = _config or {}
-- load modules
-local os = require("base/os")
local utils = require("base/utils")
local config = require("base/config")
local makefile = require("base/makefile")
@@ -32,17 +31,17 @@ local makefile = require("base/makefile")
-- done the given config
function _config.done()
- -- the configs
- local configs = config._CONFIGS
- assert(configs and configs.buildir)
-
- -- make the build directory
- if not os.isdir(configs.buildir) then
- assert(os.mkdir(configs.buildir))
- end
-
-- save configs
if not config.savexconf() then
+ -- error
+ utils.error("save configure failed!")
+ return false
+ end
+
+ -- make makefile
+ if not makefile.make() then
+ -- error
+ utils.error("make makefile failed!")
return false
end
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua
index 5f71538c2..754131fa4 100644
--- a/xmake/scripts/base/makefile.lua
+++ b/xmake/scripts/base/makefile.lua
@@ -23,5 +23,117 @@
-- define module: makefile
local makefile = makefile or {}
+-- load modules
+local io = require("base/io")
+local os = require("base/os")
+local utils = require("base/utils")
+local config = require("base/config")
+local project = require("base/project")
+
+-- make the given target to the makefile
+function makefile._make_target(file, name, target)
+
+ -- check
+ assert(file and name and target)
+
+ -- make head
+ file:write(string.format("%s:", name))
+
+ -- make dependence for target
+ if target.deps then
+ local deps = utils.wrap(target.deps)
+ for _, dep in ipairs(deps) do
+ file:write(" " .. dep)
+ end
+ end
+
+ -- make dependence end
+ file:write("\n")
+
+ -- make body
+ file:write(string.format("\techo \"%s\"\n", name))
+
+ -- make end
+ file:write("\n")
+
+ -- ok
+ return true
+end
+
+-- make all targets to the makefile
+function makefile._make_targets(file)
+
+ -- check
+ assert(file and project and project._CONFIGS)
+
+ -- get all project targets
+ local targets = project._CONFIGS._TARGET
+ if not targets then
+ -- error
+ utils.error("not found target in this project!")
+ return false
+ end
+
+ -- make all first
+ local all = ""
+ for name, _ in pairs(targets) do
+ -- append the target name to all
+ all = all .. " " .. name
+ end
+ file:write(string.format("all: %s\n\n", all))
+
+ -- make it for all targets
+ for name, target in pairs(targets) do
+ -- make target
+ if not makefile._make_target(file, name, target) then
+ -- error
+ utils.error("failed to make target %s to makefile!", name)
+ return false
+ end
+
+ -- append the target name to all
+ all = all .. " " .. name
+ end
+
+ -- ok
+ return true
+end
+
+-- make makefile in the build directory
+function makefile.make()
+
+ -- the configs
+ local configs = config._CONFIGS
+ assert(configs and configs.buildir)
+
+ -- make the build directory
+ if not os.isdir(configs.buildir) then
+ assert(os.mkdir(configs.buildir))
+ end
+
+ -- open the makefile
+ local path = configs.buildir .. "/makefile"
+ local file = io.open(path, "w")
+ if not file then
+ -- error
+ utils.error("open %s failed!", path)
+ return false
+ end
+
+ -- make all targets to the makefile
+ if not makefile._make_targets(file) then
+ -- error
+ utils.error("save %s failed!", path)
+ file:close()
+ return false
+ end
+
+ -- close the makefile
+ file:close()
+
+ -- ok
+ return true
+end
+
-- return module: makefile
return makefile
diff --git a/xmake/scripts/base/utils.lua b/xmake/scripts/base/utils.lua
index 8def2a7e6..61998339e 100644
--- a/xmake/scripts/base/utils.lua
+++ b/xmake/scripts/base/utils.lua
@@ -134,5 +134,17 @@ function utils.dump(object, exclude)
return object
end
+-- wrap object to table
+function utils.wrap(object)
+
+ -- check
+ assert(object)
+
+ -- wrap it if not table
+ if type(object) ~= "table" then
+ return {object}
+ end
+end
+
-- return module: utils
return utils