summaryrefslogtreecommitdiff
path: root/xmake/core/tool/builder.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2017-02-07 09:59:13 +0800
committerruki <[email protected]>2017-02-07 09:59:13 +0800
commit03165a0481bad23d0dacd2e2afbe1703cc1b3bfe (patch)
tree56c8234956c3a0cd9dd02fda7d01c4fa4486a4fa /xmake/core/tool/builder.lua
parent072f97eb86fd3626fb70325e17e028bf90766dc2 (diff)
remove repeat load implementaion for linker
Diffstat (limited to 'xmake/core/tool/builder.lua')
-rw-r--r--xmake/core/tool/builder.lua64
1 files changed, 64 insertions, 0 deletions
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index c0a75dac8..fe0af6af9 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -260,5 +260,69 @@ function builder:check(flags)
return ok
end
+-- load the linker from the given target kind
+function builder.load_linker(linker, linkername, targetkind, sourcekinds)
+
+ -- check
+ assert(sourcekinds)
+
+ -- wrap sourcekinds first
+ sourcekinds = table.wrap(sourcekinds)
+
+ -- get the linker info
+ local linkerinfo, errors = language.linkerinfo_of(targetkind, sourcekinds)
+ if not linkerinfo then
+ return nil, errors
+ end
+
+ -- get it directly from cache dirst
+ builder._INSTANCES = builder._INSTANCES or {}
+ if builder._INSTANCES[linkerinfo.kind] then
+ return builder._INSTANCES[linkerinfo.kind]
+ end
+
+ -- new instance
+ local instance = table.inherit(linker, builder)
+
+ -- load the linker tool from the source file type
+ local result, errors = tool.load(linkerinfo.kind)
+ if not result then
+ return nil, errors
+ end
+ instance._TOOL = result
+
+ -- load the name flags of archiver
+ local nameflags = {}
+ local nameflags_exists = {}
+ for _, sourcekind in ipairs(sourcekinds) do
+
+ -- load language
+ result, errors = language.load_sk(sourcekind)
+ if not result then
+ return nil, errors
+ end
+
+ -- merge name flags
+ for _, flaginfo in ipairs(table.wrap(result:nameflags()[linkername])) do
+ local key = flaginfo[1] .. flaginfo[2]
+ if not nameflags_exists[key] then
+ table.insert(nameflags, flaginfo)
+ nameflags_exists[key] = flaginfo
+ end
+ end
+ end
+ instance._NAMEFLAGS = nameflags
+
+ -- init flag kinds
+ instance._FLAGKINDS = {linkerinfo.flag}
+
+ -- save this instance
+ builder._INSTANCES[linkerinfo.kind] = instance
+
+ -- ok
+ return instance
+end
+
+
-- return module
return builder