summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-12-05 22:28:02 +0800
committerruki <[email protected]>2015-12-05 22:28:02 +0800
commit82fc443c84a02c7cf19248c5f9a70ef9f3a2032f (patch)
tree07189e5fefd41e23475c831d539d45e8b0e3af9c /xmake/scripts
parentf77eb028a770969a3e87af41e41fe1e66b3b7842 (diff)
impl add_files *.lib for windows
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/base/makefile.lua17
-rw-r--r--xmake/scripts/base/string.lua1
-rw-r--r--xmake/scripts/base/utils.lua21
-rw-r--r--xmake/scripts/platform/windows/tools/lib.lua38
-rw-r--r--xmake/scripts/tools/dispatcher.lua34
5 files changed, 70 insertions, 41 deletions
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua
index 3304d95f7..522e62bad 100644
--- a/xmake/scripts/base/makefile.lua
+++ b/xmake/scripts/base/makefile.lua
@@ -97,23 +97,8 @@ function makefile._make_object_for_static(file, target, srcfile, objfile)
elseif mode == "profile" then mode = ".p"
else mode = "" end
- -- get the extractor tool name
- local toolname = platform.tool("ex")
- if not toolname then
- 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 dispatcher %s %s extract %s %s > %s 2>&1", toolname:encode(), toolpath:encode(), srcfile:encode(), objfile:encode(), makefile._LOGFILE)
--- local cmd = string.format("xmake l dispatcher %s %s extract %s %s", toolname:encode(), toolpath:encode(), srcfile:encode(), objfile:encode())
+ local cmd = string.format("xmake l -P %s -f %s dispatcher ex extract %s %s > %s 2>&1", xmake._PROJECT_DIR, xmake._PROJECT_FILE, srcfile:encode(), objfile:encode(), makefile._LOGFILE)
-- make head
file:write(string.format("%s:", objfile))
diff --git a/xmake/scripts/base/string.lua b/xmake/scripts/base/string.lua
index d6f3bf748..b4be08cfa 100644
--- a/xmake/scripts/base/string.lua
+++ b/xmake/scripts/base/string.lua
@@ -25,6 +25,7 @@ local string = string or {}
-- find the last substring with the given pattern
function string.find_last(self, pattern, plain)
+
-- find the last substring
local curr = 0
repeat
diff --git a/xmake/scripts/base/utils.lua b/xmake/scripts/base/utils.lua
index 738013a76..fd1f053d6 100644
--- a/xmake/scripts/base/utils.lua
+++ b/xmake/scripts/base/utils.lua
@@ -25,23 +25,44 @@ local utils = utils or {}
-- the printf function
function utils.printf(msg, ...)
+
+ -- check
+ assert(msg)
+
+ -- trace
print(string.format(msg, ...))
end
-- the verbose function
function utils.verbose(msg, ...)
+
if xmake._OPTIONS.verbose then
+
+ -- check
+ assert(msg)
+
+ -- trace
print(string.format(msg, ...))
end
end
-- the error function
function utils.error(msg, ...)
+
+ -- check
+ assert(msg)
+
+ -- trace
print("error: " .. string.format(msg, ...))
end
-- the warning function
function utils.warning(msg, ...)
+
+ -- check
+ assert(msg)
+
+ -- trace
print("warning: " .. string.format(msg, ...))
end
diff --git a/xmake/scripts/platform/windows/tools/lib.lua b/xmake/scripts/platform/windows/tools/lib.lua
index ad83c9348..8fcd682e5 100644
--- a/xmake/scripts/platform/windows/tools/lib.lua
+++ b/xmake/scripts/platform/windows/tools/lib.lua
@@ -24,6 +24,8 @@
local lib = lib or {}
-- load modules
+local io = require("base/io")
+local path = require("base/path")
local utils = require("base/utils")
local string = require("base/string")
local config = require("base/config")
@@ -57,14 +59,44 @@ function lib.extract(self, ...)
return false
end
+ -- the windows module
+ local windows = platform.module()
+ assert(windows)
+
+ -- enter envirnoment
+ windows.enter()
+
-- list object files
- if not self:main(string.format("%s -list:%s", self.name, libfile)) then
+ local file = io.popen(string.format("%s -nologo -list %s", self.name, libfile))
+ if not file then
utils.error("extract %s to %s failed!", libfile, objdir)
+ windows.leave()
return false
end
- print(libfile, objfile)
- assert(false)
+ -- extrace all object files
+ for line in file:lines() do
+
+ -- is object file?
+ if line:find("%.obj") then
+
+ -- init command
+ local cmd = string.format("%s -nologo -extract:%s -out:%s\\%s %s", self.name, line, objdir, path.filename(line), libfile)
+
+ -- extract it
+ if 0 ~= os.execute(cmd) then
+ utils.error("extract %s to %s failed!", libfile, objdir)
+ windows.leave()
+ return false
+ end
+ end
+ end
+
+ -- exit file
+ file:close()
+
+ -- leave envirnoment
+ windows.leave()
-- ok
return true
diff --git a/xmake/scripts/tools/dispatcher.lua b/xmake/scripts/tools/dispatcher.lua
index 768c03017..d019937ec 100644
--- a/xmake/scripts/tools/dispatcher.lua
+++ b/xmake/scripts/tools/dispatcher.lua
@@ -28,6 +28,7 @@ local os = require("base/os")
local path = require("base/path")
local utils = require("base/utils")
local string = require("base/string")
+local tools = require("tools/tools")
-- the main function
--
@@ -36,49 +37,38 @@ function dispatcher.main(self, ...)
-- check
local args = ...
- assert(#args >= 3)
+ assert(#args >= 2)
- -- get toolpath
- local toolname = args[1]:decode()
- local toolpath = args[2]:decode()
- local action_name = args[3]
- assert(toolname and toolpath and action_name)
+ -- get tool kind and action name
+ local tool_kind = args[1]
+ local action_name = args[2]
+ assert(tool_kind and action_name)
- -- load script
- local script, errors = loadfile(toolpath)
- if script then
+ -- get the tool
+ local tool = tools.get(tool_kind)
+ if tool 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
+ for i = 3, #args do
table.insert(action_args, args[i]:decode())
end
-- done action
if not action(tool, action_args) then
- utils.error("run action %s for '%s' failed!", action_name, toolname)
+ utils.error("run action %s failed!", action_name)
assert(false)
end
else
- utils.error("load action %s for '%s' failed!", action_name, toolname)
+ utils.error("load action %s failed!", action_name)
assert(false)
end
else
- utils.error(errors)
- utils.error("load %s failed!", toolpath)
assert(false)
end