diff options
| author | ruki <[email protected]> | 2017-02-03 22:26:58 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-02-03 22:26:58 +0800 |
| commit | cf41edd24d67f3b7de3edec43a0ab667bfb145f1 (patch) | |
| tree | 920ae7db8f383e71afec187940a0859c91ee1bf5 /xmake/core/language/language.lua | |
| parent | ca3f925d00366c8b478d63886245307567682aaa (diff) | |
add linkerkinds for language
Diffstat (limited to 'xmake/core/language/language.lua')
| -rw-r--r-- | xmake/core/language/language.lua | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index bf33b211a..7b3dfc93e 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -131,6 +131,29 @@ function _instance:sourceflags() return self._INFO.sourceflags end +-- get the linker kinds +function _instance:linkerkinds() + + -- attempt to get it from cache first + if self._LINKERKINDS then + return self._LINKERKINDS + end + + -- merge all for each language + local linkerkinds = {} + for linkerkind, sourcekinds in pairs(table.wrap(self._INFO.linkerkinds)) do + for _, sourcekind in ipairs(sourcekinds) do + linkerkinds[sourcekind] = table.join(linkerkinds[sourcekind] or {}, linkerkind) + end + end + + -- cache this results + self._LINKERKINDS = linkerkinds + + -- ok? + return linkerkinds +end + -- get the target kinds function _instance:targetkinds() @@ -230,6 +253,7 @@ function language._interpreter() "language.set_namedflags" , "language.set_sourcekinds" , "language.set_sourceflags" + , "language.set_linkerkinds" } } @@ -516,6 +540,47 @@ function language.sourceflags() return sourceflags end +-- get language linker kinds (sourcekind => linkerkinds) +-- +-- .e.g +-- +-- { +-- cc = {"ld", "go"} +-- , mm = {"ld"} +-- , go = {"go"} +-- , sc = {"ld"} +-- , cxx = {"ld", "go"} +-- , as = {"ld", "go"} +-- } +-- +function language.linkerkinds() + + -- attempt to get it from cache + if language._LINKERKINDS then + return language._LINKERKINDS + end + + -- load all languages + local languages, errors = language.load() + if not languages then + os.raise(errors) + end + + -- merge all for each language + local results = {} + for name, instance in pairs(languages) do + for sourcekind, linkerkinds in pairs(instance:linkerkinds()) do + results[sourcekind] = table.unique(table.join(results[sourcekind] or {}, linkerkinds)) + end + end + + -- cache it + language._LINKERKINDS = results + + -- ok + return results +end + -- get source kind of the source file name function language.sourcekind_of(sourcefile) @@ -538,5 +603,30 @@ function language.sourcekind_of(sourcefile) return sourcekind end +-- get linker kind of the source kinds +function language.linkerkind_of(sourcekinds) + + -- get linkerkinds + local linkerkinds = language.linkerkinds() + + -- compute the scores of linker kinds + local linkerscores = {} + for _, sourcekind in ipairs(sourcekinds) do + for _, linkerkind in ipairs(table.wrap(linkerkinds[sourcekind])) do + linkerscores[linkerkind] = (linkerscores[linkerkind] or 0) + 1 + end + end + + -- get the linker kind with max score + for linkerkind, linkerscore in pairs(linkerscores) do + if #sourcekinds == linkerscore then + return linkerkind + end + end + + -- ok + return nil, string.format("no suitable linker for '%s'", table.concat(sourcekinds, " ")) +end + -- return module return language |
