summaryrefslogtreecommitdiff
path: root/xmake/scripts/tools/ar.lua
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 /xmake/scripts/tools/ar.lua
parent95cc4b92a1b940058c2cc8f2bdf0e05ae222a33e (diff)
add dispatcher
Diffstat (limited to 'xmake/scripts/tools/ar.lua')
-rw-r--r--xmake/scripts/tools/ar.lua50
1 files changed, 50 insertions, 0 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)