summaryrefslogtreecommitdiff
path: root/xmake/core/language/language.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2017-02-06 09:58:47 +0800
committerruki <[email protected]>2017-02-06 09:58:47 +0800
commit0654eea2d0cc1fe8e5c3827265d72089122fbf0c (patch)
tree1fe7febe744ed3f72db91ae11ffa31b32a0aeb78 /xmake/core/language/language.lua
parent5ec9b3343cb391979d96201423d1e23fde2f9a85 (diff)
get linker info for language and improve docs
Diffstat (limited to 'xmake/core/language/language.lua')
-rw-r--r--xmake/core/language/language.lua42
1 files changed, 33 insertions, 9 deletions
diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua
index 42bedf09e..0aa61c116 100644
--- a/xmake/core/language/language.lua
+++ b/xmake/core/language/language.lua
@@ -142,6 +142,17 @@ function _instance:targetkinds()
return self._INFO.targetkinds
end
+-- get the target flags (targetkind => linkerflag)
+--
+-- .e.g
+-- {binary = "ldflags", static = "arflags", shared = "shflags"}
+--
+function _instance:targetflags()
+
+ -- get it
+ return self._INFO.targetflags
+end
+
-- get the named flags
function _instance:namedflags()
@@ -234,6 +245,7 @@ function language._interpreter()
, "language.set_sourcekinds"
, "language.set_sourceflags"
, "language.set_targetkinds"
+ , "language.set_targetflags"
}
}
@@ -542,8 +554,8 @@ function language.sourcekind_of(sourcefile)
return sourcekind
end
--- get linker kind of the target kind and the source kinds
-function language.linkerkind_of(targetkind, sourcekinds)
+-- get linker info(kind and flag) of the target kind and the source kinds
+function language.linkerinfo_of(targetkind, sourcekinds)
-- load linkerkinds
local linkerkinds = language._LINKERKINDS
@@ -559,9 +571,19 @@ function language.linkerkind_of(targetkind, sourcekinds)
linkerkinds = {}
for name, instance in pairs(languages) do
for sourcekind, _ in pairs(instance:sourcekinds()) do
+ local targetflags = instance:targetflags()
for _targetkind, linkerkind in pairs(instance:targetkinds()) do
+
+ -- make linker info
+ local linkerinfo = {kind = linkerkind}
+ local linkerflag = targetflags[_targetkind]
+ if linkerflag then
+ linkerinfo.flag = linkerflag
+ end
+
+ -- save linker info
linkerkinds[_targetkind] = linkerkinds[_targetkind] or {}
- linkerkinds[_targetkind][sourcekind] = linkerkind
+ linkerkinds[_targetkind][sourcekind] = linkerinfo
end
end
end
@@ -573,16 +595,18 @@ function language.linkerkind_of(targetkind, sourcekinds)
-- compute the scores of the linker kinds
local linkerscores = {}
for _, sourcekind in ipairs(sourcekinds) do
- local linkerkind = linkerkinds[targetkind][sourcekind]
- if linkerkind then
- linkerscores[linkerkind] = (linkerscores[linkerkind] or 0) + 1
+ local linkerinfo = linkerkinds[targetkind][sourcekind]
+ if linkerinfo then
+ local key = linkerinfo.kind .. (linkerinfo.flag or "")
+ linkerscores[key] = linkerscores[key] or {score = 0, info = linkerinfo}
+ linkerscores[key].score = linkerscores[key].score + 1
end
end
-- select the suitable linker kind
- for linkerkind, linkerscore in pairs(linkerscores) do
- if #sourcekinds == linkerscore then
- return linkerkind
+ for _, linkerscore in pairs(linkerscores) do
+ if #sourcekinds == linkerscore.score then
+ return linkerscore.info
end
end