summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-05-25 10:56:12 +0800
committerruki <[email protected]>2016-05-25 10:56:12 +0800
commitc8f23de807e6efcd6b797a6dde6366d67f64906d (patch)
tree200b5923d2069d79d323493c2f359cf7e78a9828
parent7545edd1693c3daa4ce9b8ac5ccba200c6858b61 (diff)
impl extract library for windows
-rw-r--r--xmake/tools/ar.lua10
-rwxr-xr-xxmake/tools/lib.lua60
2 files changed, 63 insertions, 7 deletions
diff --git a/xmake/tools/ar.lua b/xmake/tools/ar.lua
index 27ecd0a0f..64161a901 100644
--- a/xmake/tools/ar.lua
+++ b/xmake/tools/ar.lua
@@ -73,12 +73,12 @@ function extract(libraryfile, objectdir)
-- check repeat object name
local repeats = {}
- local results = os.iorun("%s -t %s", _g.shellname, libraryfile)
- for _, line in ipairs(results:split('\n')) do
- if repeats[line] then
- raise("object name(%s) conflicts in library: %s", line, libraryfile)
+ local objectfiles = os.iorun("%s -t %s", _g.shellname, libraryfile)
+ for _, objectfile in ipairs(objectfiles:split('\n')) do
+ if repeats[objectfile] then
+ raise("object name(%s) conflicts in library: %s", objectfile, libraryfile)
end
- repeats[line] = true
+ repeats[objectfile] = true
end
-- leave the object directory
diff --git a/xmake/tools/lib.lua b/xmake/tools/lib.lua
index b2d81a2c6..4c7f6c819 100755
--- a/xmake/tools/lib.lua
+++ b/xmake/tools/lib.lua
@@ -21,10 +21,14 @@
--
-- init it
-function init(shellname)
+function init(shellname, kind)
-- save the shell name
_g.shellname = shellname or "lib.exe"
+
+ -- save the tool kind
+ _g.kind = kind or "ar"
+
end
-- get the property
@@ -34,9 +38,48 @@ function get(name)
return _g[name]
end
+-- extract the static library to object directory
+function extract(libraryfile, objectdir)
+
+ -- make the object directory first
+ os.mkdir(objectdir)
+
+ -- list object files
+ local objectfiles = os.iorun("%s -nologo -list %s", _g.shellname, libraryfile)
+
+ -- extrace all object files
+ for _, objectfile in ipairs(objectfiles:split('\n')) do
+
+ -- is object file?
+ if objectfile:find("%.obj") then
+
+ -- make the outputfile
+ local outputfile = path.translate(format("%s\\%s", objectdir, path.filename(objectfile)))
+
+ -- repeat? rename it
+ if os.isfile(outputfile) then
+ for i = 0, 10 do
+ outputfile = path.translate(format("%s\\%d_%s", objectdir, i, path.filename(objectfile)))
+ if not os.isfile(outputfile) then
+ break
+ end
+ end
+ end
+
+ -- extract it
+ os.run("%s -nologo -extract:%s -out:%s %s", _g.shellname, objectfile, outputfile, libraryfile)
+ end
+ end
+end
+
-- run command
function run(...)
+ -- extract it
+ if _g.kind == "ex" then
+ return extract(...)
+ end
+
-- run it
os.run(...)
end
@@ -44,7 +87,20 @@ end
-- check the given flags
function check(flags)
+ -- make an stub source file
+ local libfile = path.join(os.tmpdir(), "xmake.lib.lib")
+ local objfile = path.join(os.tmpdir(), "xmake.lib.obj")
+ local srcfile = path.join(os.tmpdir(), "xmake.lib.c")
+ io.write(srcfile, "int test(void)\n{return 0;}")
+
-- check it
- os.run("%s", _g.shellname, ifelse(flags, flags, ""))
+ os.run("cl -c -Fo%s %s", objfile, srcfile)
+ os.run("link -lib -out:%s %s", libfile, objfile)
+ os.run("%s %s -list %s", _g.shellname, ifelse(flags, flags, ""), libfile)
+
+ -- remove files
+ os.rm(objfile)
+ os.rm(srcfile)
+ os.rm(libfile)
end