diff options
Diffstat (limited to 'xmake/scripts/tools')
| -rw-r--r-- | xmake/scripts/tools/ar.lua | 50 | ||||
| -rw-r--r-- | xmake/scripts/tools/dispatcher.lua | 90 | ||||
| -rw-r--r-- | xmake/scripts/tools/extract.lua | 95 | ||||
| -rw-r--r-- | xmake/scripts/tools/tools.lua | 10 |
4 files changed, 147 insertions, 98 deletions
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 |
