summaryrefslogtreecommitdiff
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
parent5ec9b3343cb391979d96201423d1e23fde2f9a85 (diff)
get linker info for language and improve docs
-rw-r--r--docs/config.js10
-rwxr-xr-xdocs/zh/manual.md89
-rw-r--r--xmake/core/language/language.lua42
-rw-r--r--xmake/core/sandbox/modules/import/core/language/language.lua10
-rw-r--r--xmake/core/tool/linker.lua29
-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
10 files changed, 159 insertions, 36 deletions
diff --git a/docs/config.js b/docs/config.js
index fa1626c9d..b1c2ca110 100644
--- a/docs/config.js
+++ b/docs/config.js
@@ -21,7 +21,10 @@ self.$config = {
title: 'Manual', path: '/manual'
},
{
- title: 'Blog', path: 'http://www.tboox.org'
+ title: 'Articles', path: 'http://www.tboox.org/category/#xmake'
+ },
+ {
+ title: 'Feedback', path: 'https://github.com/tboox/xmake/issues'
},
{
title: 'Community', path: 'http://www.tboox.org/forum'
@@ -41,7 +44,10 @@ self.$config = {
title: '手册', path: '/zh/manual'
},
{
- title: '博客', path: 'http://www.tboox.org/cn'
+ title: '文章', path: 'http://www.tboox.org/cn/category/#xmake'
+ },
+ {
+ title: '反馈', path: 'https://github.com/tboox/xmake/issues'
},
{
title: '社区', path: 'http://www.tboox.org/forum'
diff --git a/docs/zh/manual.md b/docs/zh/manual.md
index cfd79ef01..143bda22d 100755
--- a/docs/zh/manual.md
+++ b/docs/zh/manual.md
@@ -1348,9 +1348,45 @@ add_shflags("xxx")
这个接口跟[set_options](#set_options)类似,唯一的区别就是,此处是追加选项,而[set_options](#set_options)每次设置会覆盖先前的设置。
##### add_packages
+
+###### 添加包依赖
+
+在target作用域中,添加集成包依赖,例如:
+
+```lua
+target("test")
+ add_packages("zlib", "polarssl", "pcre", "mysql")
+```
+
+这样,在编译test目标时,如果这个包存在的,将会自动追加包里面的宏定义、头文件搜索路径、链接库目录,也会自动链接包中所有库。
+
+用户不再需要自己单独调用[add_links](#add_links),[add_includedirs](#add_includedirs), [add_ldflags](#add_ldflags)等接口,来配置依赖库链接了。
+
+对于如何设置包搜索目录,可参考:[add_packagedirs](#add_packagedirs) 接口
+
##### add_languages
+
+###### 添加语言标准
+
+与[set_languages](#set_languages)类似,唯一区别是这个接口不会覆盖掉之前的设置,而是追加设置。
+
##### add_vectorexts
+###### 添加向量扩展指令
+
+添加扩展指令优化选项,目前支持以下几种扩展指令集:
+
+```lua
+add_vectorexts("mmx")
+add_vectorexts("neon")
+add_vectorexts("avx", "avx2")
+add_vectorexts("sse", "sse2", "sse3", "ssse3")
+```
+
+<p class="tip">
+如果当前设置的指令集编译器不支持,xmake会自动忽略掉,所以不需要用户手动去判断维护,只需要将你需要的指令集全部设置上就行了。
+</p>
+
#### 选项定义
##### option
@@ -1410,3 +1446,56 @@ add_shflags("xxx")
##### add_macros
##### add_macrofiles
+#### 内置模块
+
+##### import
+##### inherit
+##### ifelse
+##### try-catch-finally
+##### pairs
+##### ipairs
+##### print
+##### printf
+##### cprint
+##### cprintf
+##### raise
+
+##### table
+
+###### insert
+###### join
+###### join2
+###### concat
+###### dump
+
+##### path
+
+###### join
+###### basename
+###### filename
+###### directory
+###### relative
+###### absolute
+###### is_absolute
+
+##### io
+##### os
+##### string
+##### process
+##### coroutine
+
+#### 扩展模块
+
+##### core.base.option
+##### core.tool.tool
+##### core.tool.linker
+##### core.tool.compiler
+##### core.project.config
+##### core.project.global
+##### core.project.target
+##### core.project.task
+##### core.project.cache
+##### core.project.project
+##### core.language.language
+##### core.platform.platform
+##### core.platform.environment
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
diff --git a/xmake/core/sandbox/modules/import/core/language/language.lua b/xmake/core/sandbox/modules/import/core/language/language.lua
index 05ec75f46..c65516661 100644
--- a/xmake/core/sandbox/modules/import/core/language/language.lua
+++ b/xmake/core/sandbox/modules/import/core/language/language.lua
@@ -109,17 +109,17 @@ function sandbox_core_language.sourcekind_of(sourcefile)
return sourcekind
end
--- get linker kind of the source kinds
-function sandbox_core_language.linkerkind_of(targetkind, sourcekinds)
+-- get linker info (kind and flag) of the source kinds
+function sandbox_core_language.linkerinfo_of(targetkind, sourcekinds)
-- get it
- local linkerkind, errors = language.linkerkind_of(targetkind, sourcekinds)
- if not linkerkind then
+ local linkerinfo, errors = language.linkerinfo_of(targetkind, sourcekinds)
+ if not linkerinfo then
raise(errors)
end
-- ok
- return linkerkind
+ return linkerinfo
end
-- return module
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua
index b7d1d48f3..fe221c662 100644
--- a/xmake/core/tool/linker.lua
+++ b/xmake/core/tool/linker.lua
@@ -180,44 +180,33 @@ end
-- load the linker from the given target kind
function linker.load(targetkind, sourcekinds)
- -- get the linker kind
- local linkerkind, errors = language.linkerkind_of(targetkind, sourcekinds)
- if not linkerkind then
+ -- 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
linker._INSTANCES = linker._INSTANCES or {}
- if linker._INSTANCES[linkerkind] then
- return linker._INSTANCES[linkerkind]
+ if linker._INSTANCES[linkerinfo.kind] then
+ return linker._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(linkerkind)
+ local result, errors = tool.load(linkerinfo.kind)
if not result then
return nil, errors
end
instance._TOOL = result
- -- save flagname
- local flagname =
- {
- ld = "ldflags"
- , sh = "shflags"
- , go = "goflags"
- }
- instance._FLAGNAME = flagname[linkerkind]
-
- -- check
- if not instance._FLAGNAME then
- return nil, string.format("unknown linker for kind: %s", linkerkind)
- end
+ -- init flag name
+ instance._FLAGNAME = linkerinfo.flag
-- save this instance
- linker._INSTANCES[linkerkind] = instance
+ linker._INSTANCES[linkerinfo.kind] = instance
-- ok
return instance
diff --git a/xmake/languages/asm/xmake.lua b/xmake/languages/asm/xmake.lua
index 36a54c271..7dc9110a0 100755
--- a/xmake/languages/asm/xmake.lua
+++ b/xmake/languages/asm/xmake.lua
@@ -34,6 +34,9 @@ language("asm")
-- set target kinds
set_targetkinds {binary = "ld", static = "ar", shared = "sh"}
+ -- set target flags
+ set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"}
+
-- on load
on_load("load")
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua
index d31fc1bc2..01e9a920e 100755
--- a/xmake/languages/c++/xmake.lua
+++ b/xmake/languages/c++/xmake.lua
@@ -34,6 +34,9 @@ language("c++")
-- set target kinds
set_targetkinds {binary = "ld", static = "ar", shared = "sh"}
+ -- set target flags
+ set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"}
+
-- on load
on_load("load")
diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua
index 706ad2df0..980bb141d 100755
--- a/xmake/languages/golang/xmake.lua
+++ b/xmake/languages/golang/xmake.lua
@@ -34,6 +34,9 @@ language("golang")
-- set target kinds
set_targetkinds {binary = "go", static = "go", shared = "go"}
+ -- set target flags
+ set_targetflags {binary = "goflags", static = "goflags", shared = "goflags"}
+
-- on load
on_load("load")
diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua
index ab1e2f80e..b247a9b1b 100755
--- a/xmake/languages/objc++/xmake.lua
+++ b/xmake/languages/objc++/xmake.lua
@@ -34,6 +34,9 @@ language("objc++")
-- set target kinds
set_targetkinds {binary = "ld", static = "ar", shared = "sh"}
+ -- set target flags
+ set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"}
+
-- on load
on_load("load")
diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua
index 484bb46f2..eda43752c 100755
--- a/xmake/languages/swift/xmake.lua
+++ b/xmake/languages/swift/xmake.lua
@@ -34,6 +34,9 @@ language("swift")
-- set target kinds
set_targetkinds {binary = "ld", static = "ar", shared = "sh"}
+ -- set target flags
+ set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"}
+
-- on load
on_load("load")