summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-02-03 22:26:58 +0800
committerruki <[email protected]>2017-02-03 22:26:58 +0800
commitcf41edd24d67f3b7de3edec43a0ab667bfb145f1 (patch)
tree920ae7db8f383e71afec187940a0859c91ee1bf5
parentca3f925d00366c8b478d63886245307567682aaa (diff)
add linkerkinds for language
-rw-r--r--xmake/core/language/language.lua90
-rw-r--r--xmake/core/sandbox/modules/import/core/language/language.lua20
-rwxr-xr-xxmake/languages/asm/xmake.lua3
-rwxr-xr-xxmake/languages/c++/xmake.lua3
-rwxr-xr-xxmake/languages/golang/xmake.lua3
-rwxr-xr-xxmake/languages/objc++/xmake.lua3
-rwxr-xr-xxmake/languages/swift/xmake.lua3
7 files changed, 125 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
diff --git a/xmake/core/sandbox/modules/import/core/language/language.lua b/xmake/core/sandbox/modules/import/core/language/language.lua
index e00fc7365..6b50f8830 100644
--- a/xmake/core/sandbox/modules/import/core/language/language.lua
+++ b/xmake/core/sandbox/modules/import/core/language/language.lua
@@ -50,6 +50,13 @@ function sandbox_core_language.sourceflags()
return language.sourceflags()
end
+-- get the linker kinds of all languages
+function sandbox_core_language.linkerkinds()
+
+ -- get it
+ return language.linkerkinds()
+end
+
-- load the language from the given name (c++, objc++, swift, golang, asm, ...)
function sandbox_core_language.load(name)
@@ -102,5 +109,18 @@ function sandbox_core_language.sourcekind_of(sourcefile)
return sourcekind
end
+-- get linker kind of the source kinds
+function sandbox_core_language.linkerkind_of(sourcekinds)
+
+ -- get it
+ local linkerkind, errors = language.linkerkind_of(sourcekinds)
+ if not linkerkind then
+ raise(errors)
+ end
+
+ -- ok
+ return linkerkind
+end
+
-- return module
return sandbox_core_language
diff --git a/xmake/languages/asm/xmake.lua b/xmake/languages/asm/xmake.lua
index 1cee85852..c614b2d55 100755
--- a/xmake/languages/asm/xmake.lua
+++ b/xmake/languages/asm/xmake.lua
@@ -31,6 +31,9 @@ language("asm")
-- set source file flags
set_sourceflags {as = "asflags"}
+ -- set linker kinds (linker => source kinds)
+ set_linkerkinds {ld = {"as"}}
+
-- set target kinds
set_targetkinds("binary", "static", "shared")
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua
index a756de4df..3680d5c65 100755
--- a/xmake/languages/c++/xmake.lua
+++ b/xmake/languages/c++/xmake.lua
@@ -31,6 +31,9 @@ language("c++")
-- set source file flags
set_sourceflags {cc = {"cflags", "cxflags"}, cxx = {"cxxflags", "cxflags"}}
+ -- set linker kinds (linker => source kinds)
+ set_linkerkinds {ld = {"cc", "cxx"}}
+
-- set target kinds
set_targetkinds("binary", "static", "shared")
diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua
index da52c2d76..be74d6c11 100755
--- a/xmake/languages/golang/xmake.lua
+++ b/xmake/languages/golang/xmake.lua
@@ -31,6 +31,9 @@ language("golang")
-- set source file flags
set_sourceflags {go = "goflags"}
+ -- set linker kinds (linker => source kinds)
+ set_linkerkinds {go = {"go", "cc", "cxx", "as"}}
+
-- set target kinds
set_targetkinds("binary", "static", "shared")
diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua
index 59d0ba0cc..6fd6a1144 100755
--- a/xmake/languages/objc++/xmake.lua
+++ b/xmake/languages/objc++/xmake.lua
@@ -31,6 +31,9 @@ language("objc++")
-- set source file flags
set_sourceflags {mm = {"mflags", "mxflags"}, mxx = {"mxxflags", "mxflags"}}
+ -- set linker kinds (linker => source kinds)
+ set_linkerkinds {ld = {"mm", "mxx"}}
+
-- set target kinds
set_targetkinds("binary", "static", "shared")
diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua
index 97e84326d..85ff05f46 100755
--- a/xmake/languages/swift/xmake.lua
+++ b/xmake/languages/swift/xmake.lua
@@ -31,6 +31,9 @@ language("swift")
-- set source file flags
set_sourceflags {sc = "scflags"}
+ -- set linker kinds (linker => source kinds)
+ set_linkerkinds {ld = {"sc"}}
+
-- set target kinds
set_targetkinds("binary")