summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-12-05 00:33:03 +0800
committerruki <[email protected]>2015-12-05 00:33:03 +0800
commit98a12249aff0eed41c11f31da54205dc876379bf (patch)
tree65afbecb1ae45a65f1ac27cd74bd071a17b1577f
parent95cc4b92a1b940058c2cc8f2bdf0e05ae222a33e (diff)
add dispatcher
-rw-r--r--xmake/scripts/base/makefile.lua18
-rw-r--r--xmake/scripts/platform/windows/tools/lib.lua (renamed from xmake/scripts/platform/windows/tools/extract.lua)70
-rw-r--r--xmake/scripts/platform/windows/windows.lua1
-rw-r--r--xmake/scripts/tools/ar.lua50
-rw-r--r--xmake/scripts/tools/dispatcher.lua90
-rw-r--r--xmake/scripts/tools/extract.lua95
-rw-r--r--xmake/scripts/tools/tools.lua10
7 files changed, 202 insertions, 132 deletions
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua
index 934772fe5..ec5557c23 100644
--- a/xmake/scripts/base/makefile.lua
+++ b/xmake/scripts/base/makefile.lua
@@ -97,15 +97,22 @@ function makefile._make_object_for_static(file, target, srcfile, objfile)
elseif mode == "profile" then mode = ".p"
else mode = "" end
- -- get extractor name
+ -- get the extractor tool name
local toolname = platform.tool("ex")
if not toolname then
- utils.error("cannot get extractor!")
+ utils.error("cannot get extractor name!")
+ return false
+ end
+
+ -- find the tool file path
+ local toolpath = tools.find(toolname)
+ if not toolpath or not os.isfile(toolpath) then
+ utils.error("cannot get extractor path!")
return false
end
-- make command
- local cmd = string.format("xmake l extract \"%s\" %s %s > %s 2>&1", toolname, srcfile, objfile, makefile._LOGFILE)
+ local cmd = string.format("xmake l dispatcher \"%s\" \"%s\" extract %s %s > %s 2>&1", toolname, toolpath, srcfile, objfile, makefile._LOGFILE)
-- make head
file:write(string.format("%s:", objfile))
@@ -229,7 +236,10 @@ function makefile._make_target(file, name, target)
-- get the linker from the given kind
local l = linker.get(target.kind)
- if not l then return false end
+ if not l then
+ utils.error("cannot get linker with kind: %s", target.kind)
+ return false
+ end
-- make head
file:write(string.format("%s: %s\n", name, targetfile))
diff --git a/xmake/scripts/platform/windows/tools/extract.lua b/xmake/scripts/platform/windows/tools/lib.lua
index 593807cdd..0e464f38c 100644
--- a/xmake/scripts/platform/windows/tools/extract.lua
+++ b/xmake/scripts/platform/windows/tools/lib.lua
@@ -17,41 +17,36 @@
-- Copyright (C) 2009 - 2015, ruki All rights reserved.
--
-- @author ruki
--- @file extract.lua
+-- @file lib.lua
--
--- define module: extract
-local extract = extract or {}
+-- define module: lib
+local lib = lib or {}
-- load modules
-local os = require("base/os")
-local path = require("base/path")
local utils = require("base/utils")
local string = require("base/string")
+local config = require("base/config")
+local platform = require("platform/platform")
--- the main function
---
--- extract /home/[lib]xxx.[a|lib] /home/xxx/*.[o|obj]
--- only support: lib -extract membername -out xxx.obj
-function extract.main(self, ...)
+-- init the compiler
+function lib.init(self, name)
- -- check
- local args = ...
- assert(#args == 3)
+ -- save name
+ self.name = name or "lib.exe"
- -- get toolname
- local toolname = args[1]
- assert(toolname)
+end
- -- be not ar?
- if not toolname:find("lib.exe", 1, true) then
- utils.error("%s is not lib.exe!", toolname)
- return false
- end
+-- extract the static library to object files
+function lib.extract(self, ...)
+
+ -- check
+ local args = ...
+ assert(#args == 2 and self.name)
-- get library and object file path
- local libfile = args[2]
- local objfile = args[3]
+ local libfile = args[1]
+ local objfile = args[2]
assert(libfile and objfile)
-- get object directory
@@ -62,15 +57,32 @@ function extract.main(self, ...)
return false
end
- -- trace
- print(toolname, libfile, objfile, objdir)
-
- -- abort
+ print(libfile, objfile)
assert(false)
-- ok
return true
end
--- return module: extract
-return extract
+-- the main function
+function lib.main(self, cmd)
+
+ -- the windows module
+ local windows = platform.module()
+ assert(windows)
+
+ -- enter envirnoment
+ windows.enter()
+
+ -- execute it
+ local ok = os.execute(cmd)
+
+ -- leave envirnoment
+ windows.leave()
+
+ -- ok?
+ return utils.ifelse(ok == 0, true, false)
+end
+
+-- return module: lib
+return lib
diff --git a/xmake/scripts/platform/windows/windows.lua b/xmake/scripts/platform/windows/windows.lua
index 00aa4f8ad..022a9c5f6 100644
--- a/xmake/scripts/platform/windows/windows.lua
+++ b/xmake/scripts/platform/windows/windows.lua
@@ -114,7 +114,6 @@ function windows.make(configs)
configs.tools.sh = config.get("sh")
configs.tools.as = config.get("as")
configs.tools.ex = config.get("ex")
-
end
-- get the option menu for action: xmake config or global
diff --git a/xmake/scripts/tools/ar.lua b/xmake/scripts/tools/ar.lua
index 66a29c4c3..dbe947111 100644
--- a/xmake/scripts/tools/ar.lua
+++ b/xmake/scripts/tools/ar.lua
@@ -50,6 +50,56 @@ function ar.command_link(self, objfiles, targetfile, flags, logfile)
return string.format("%s %s %s %s%s", self.name, flags, targetfile, objfiles, redirect)
end
+-- extract the static library to object files
+function ar.extract(self, ...)
+
+ -- check
+ local args = ...
+ assert(#args == 2 and self.name)
+
+ -- get library and object file path
+ local libfile = args[1]
+ local objfile = args[2]
+ assert(libfile and objfile)
+
+ -- get object directory
+ local objdir = path.directory(objfile)
+ if not os.isdir(objdir) then os.mkdir(objdir) end
+ if not os.isdir(objdir) then
+ utils.error("%s not found!", objdir)
+ return false
+ end
+
+ -- absolute the library path
+ libfile = path.absolute(libfile)
+ assert(libfile)
+
+ -- enter the object directory
+ ok, errors = os.cd(objdir)
+ if not ok then
+ utils.error(errors)
+ return false
+ end
+
+ -- extract it
+ local ok = os.execute(string.format("%s -x %s", self.name, libfile))
+ if ok ~= 0 then
+ utils.error("extract %s to %s failed!", libfile, objdir)
+ return false
+ end
+
+ -- leave the object directory
+ ok, errors = os.cd("-")
+ if not ok then
+ utils.error(errors)
+ return false
+ end
+
+ -- ok
+ return true
+end
+
+
-- the main function
function ar.main(self, cmd)
diff --git a/xmake/scripts/tools/dispatcher.lua b/xmake/scripts/tools/dispatcher.lua
new file mode 100644
index 000000000..3e7425d66
--- /dev/null
+++ b/xmake/scripts/tools/dispatcher.lua
@@ -0,0 +1,90 @@
+--!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 dispatcher.lua
+--
+
+-- define module: dispatcher
+local dispatcher = dispatcher or {}
+
+-- load modules
+local os = require("base/os")
+local path = require("base/path")
+local utils = require("base/utils")
+local string = require("base/string")
+
+-- the main function
+--
+-- dispatcher toolname toolpath action arguments ...
+function dispatcher.main(self, ...)
+
+ -- check
+ local args = ...
+ assert(#args >= 3)
+
+ -- get toolpath
+ local toolname = args[1]
+ local toolpath = args[2]
+ local action_name = args[3]
+ assert(toolname and toolpath and action_name)
+
+ -- load script
+ local script, errors = loadfile(toolpath)
+ if script then
+
+ -- load tool
+ local tool = script()
+
+ -- init tool
+ if tool and tool.init then
+ tool:init(toolname)
+ end
+
+ -- load action
+ local action = tool[action_name]
+ if action then
+
+ -- init arguments for action
+ local action_args = {}
+ for i = 4, #args do
+ table.insert(action_args, args[i])
+ end
+
+ -- done action
+ if not action(tool, action_args) then
+ utils.error("run action %s for '%s' failed!", action_name, toolname)
+ assert(false)
+ end
+ else
+ utils.error("load action %s for '%s' failed!", action_name, toolname)
+ assert(false)
+ end
+
+ else
+ utils.error(errors)
+ utils.error("load %s failed!", toolpath)
+ assert(false)
+ end
+
+ -- ok
+ return true
+end
+
+-- return module: dispatcher
+return dispatcher
diff --git a/xmake/scripts/tools/extract.lua b/xmake/scripts/tools/extract.lua
deleted file mode 100644
index 635eb8d73..000000000
--- a/xmake/scripts/tools/extract.lua
+++ /dev/null
@@ -1,95 +0,0 @@
---!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 extract.lua
---
-
--- define module: extract
-local extract = extract or {}
-
--- load modules
-local os = require("base/os")
-local path = require("base/path")
-local utils = require("base/utils")
-local string = require("base/string")
-
--- the main function
---
--- extract /home/[lib]xxx.[a|lib] /home/xxx/*.[o|obj]
--- only support: ar -x library
-function extract.main(self, ...)
-
- -- check
- local args = ...
- assert(#args == 3)
-
- -- get toolname
- local toolname = args[1]
- assert(toolname)
-
- -- be not ar?
- if not toolname:find("ar", 1, true) then
- utils.error("%s is not ar!", toolname)
- return false
- end
-
- -- get library and object file path
- local libfile = args[2]
- local objfile = args[3]
- assert(libfile and objfile)
-
- -- get object directory
- local objdir = path.directory(objfile)
- if not os.isdir(objdir) then os.mkdir(objdir) end
- if not os.isdir(objdir) then
- utils.error("%s not found!", objdir)
- return false
- end
-
- -- absolute the library path
- libfile = path.absolute(libfile)
- assert(libfile)
-
- -- enter the object directory
- ok, errors = os.cd(objdir)
- if not ok then
- utils.error(errors)
- return false
- end
-
- -- extract it
- local ok = os.execute(string.format("%s -x %s", toolname, libfile))
- if ok ~= 0 then
- utils.error("extract %s to %s failed!", libfile, objdir)
- return false
- end
-
- -- leave the object directory
- ok, errors = os.cd("-")
- if not ok then
- utils.error(errors)
- return false
- end
-
- -- ok
- return true
-end
-
--- return module: extract
-return extract
diff --git a/xmake/scripts/tools/tools.lua b/xmake/scripts/tools/tools.lua
index 8600a296f..31a68734b 100644
--- a/xmake/scripts/tools/tools.lua
+++ b/xmake/scripts/tools/tools.lua
@@ -35,7 +35,11 @@ function tools._match(name, toolname)
-- match full? ok
if name == toolname then return 100 end
-
+
+ -- match the name for windows? ok
+ if name:find("^" .. toolname .. "%.exe") then return 90 end
+ if name:find(toolname .. "%.exe") then return 85 end
+
-- match the last word? ok
if name:find(toolname .. "$") then return 80 end
@@ -75,7 +79,7 @@ function tools._find_from(root, name)
-- match score
local score = tools._match(name, toolname:lower())
-
+
-- ok?
if score >= 100 then return file end
@@ -173,7 +177,7 @@ function tools.load(name, root)
end
end
--- get the given tool from the current platform
+-- get the given tool script from the given kind
function tools.get(kind)
-- get the tool name