summaryrefslogtreecommitdiff
path: root/xmake/scripts/base
diff options
context:
space:
mode:
authorruki <[email protected]>2015-12-04 11:49:37 +0800
committerruki <[email protected]>2015-12-04 11:49:37 +0800
commit6ece8be70e5141a69720f28e4f18b20664142ae3 (patch)
tree9ae6301f68ecec013c6023a2b6d74bd702685f7a /xmake/scripts/base
parent7624723775b58c1811287465e6d7c27cede81b31 (diff)
support add_files *.a using ar
Diffstat (limited to 'xmake/scripts/base')
-rw-r--r--xmake/scripts/base/makefile.lua25
-rw-r--r--xmake/scripts/base/rule.lua7
2 files changed, 25 insertions, 7 deletions
diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua
index a7c7a7301..48550809a 100644
--- a/xmake/scripts/base/makefile.lua
+++ b/xmake/scripts/base/makefile.lua
@@ -36,7 +36,7 @@ local compiler = require("base/compiler")
local tools = require("tools/tools")
local platform = require("platform/platform")
--- make object for the *.o/obj source file
+-- make object for the *.[o|obj] source file
function makefile._make_object_for_object(file, target, srcfile, objfile)
-- get the source file type
@@ -66,7 +66,7 @@ function makefile._make_object_for_object(file, target, srcfile, objfile)
file:write(string.format(" %s\n", srcfile))
-- make body
- file:write(string.format("\t@echo adding%s %s\n", mode, srcfile))
+ file:write(string.format("\t@echo inserting%s %s\n", mode, srcfile))
file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:gsub("[%s=\"]", function (w) return string.format("%%%x", w:byte()) end)))
file:write(string.format("\t@%s\n", cmd))
@@ -77,7 +77,7 @@ function makefile._make_object_for_object(file, target, srcfile, objfile)
return true
end
--- make object for the *.a/lib source file
+-- make object for the *.[a|lib] source file
function makefile._make_object_for_static(file, target, srcfile, objfile)
-- get the source file type
@@ -97,8 +97,21 @@ function makefile._make_object_for_static(file, target, srcfile, objfile)
elseif mode == "profile" then mode = ".p"
else mode = "" end
+ -- get extractor name
+ local toolname = nil
+ local extractor, errors = tools.get("ex")
+ if not extractor then
+ utils.error(errors)
+ return false
+ end
+ toolname = extractor.name
+ if not toolname then
+ utils.error("cannot get the extractor name!")
+ return false
+ end
+
-- make command
- local cmd = string.format("xmake l cp %s %s", srcfile, objfile)
+ local cmd = string.format("xmake l extract \"%s\" %s %s > %s 2>&1", toolname, srcfile, objfile, makefile._LOGFILE)
-- make head
file:write(string.format("%s:", objfile))
@@ -107,8 +120,9 @@ function makefile._make_object_for_static(file, target, srcfile, objfile)
file:write(string.format(" %s\n", srcfile))
-- make body
- file:write(string.format("\t@echo adding%s %s\n", mode, srcfile))
+ file:write(string.format("\t@echo inserting%s %s\n", mode, srcfile))
file:write(string.format("\t@xmake l $(VERBOSE) verbose \"%s\"\n", cmd:gsub("[%s=\"]", function (w) return string.format("%%%x", w:byte()) end)))
+ file:write(string.format("\t@xmake l rmdir %s\n", path.directory(objfile)))
file:write(string.format("\t@%s\n", cmd))
-- make tail
@@ -320,6 +334,7 @@ function makefile._make_targets(file)
all = all .. " " .. name
end
file:write(string.format("all: %s\n\n", all))
+ file:write(string.format(".PHONY: all %s\n\n", all))
-- make it for all targets
for name, target in pairs(targets) do
diff --git a/xmake/scripts/base/rule.lua b/xmake/scripts/base/rule.lua
index 97baf2b24..d4f15a456 100644
--- a/xmake/scripts/base/rule.lua
+++ b/xmake/scripts/base/rule.lua
@@ -145,6 +145,9 @@ function rule.objectfiles(target_name, target, sourcefiles, buildir)
local objectfiles = {}
for _, sourcefile in ipairs(sourcefiles) do
+ -- translate: [lib]xxx*.[a|lib] => xxx/*.[o|obj] object file
+ sourcefile = sourcefile:gsub(rule.filename("(%w+)", "static"):gsub("%.", "%%.") .. "$", "%1/*")
+
-- make object file
local objectfile = string.format("%s/%s/%s/%s", objectdir, target_name, path.directory(sourcefile), rule.filename(path.basename(sourcefile), "object"))
@@ -191,13 +194,13 @@ function rule.sourcefiles(target)
local sourcefiles = {}
for _, targetfile in ipairs(targetfiles) do
- -- normalize *.o/obj filename
+ -- normalize *.[o|obj] filename
targetfile = targetfile:gsub("([%w%*]+)%.obj|", rule.filename("%1|", "object"))
targetfile = targetfile:gsub("([%w%*]+)%.obj$", rule.filename("%1", "object"))
targetfile = targetfile:gsub("([%w%*]+)%.o|", rule.filename("%1|", "object"))
targetfile = targetfile:gsub("([%w%*]+)%.o$", rule.filename("%1", "object"))
- -- normalize lib*.a/*.lib filename
+ -- normalize [lib]*.[a|lib] filename
targetfile = targetfile:gsub("([%w%*]+)%.lib|", rule.filename("%1|", "static"))
targetfile = targetfile:gsub("([%w%*]+)%.lib$", rule.filename("%1", "static"))
targetfile = targetfile:gsub("lib([%w%*]+)%.a|", rule.filename("%1|", "static"))