summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-02-06 21:56:55 +0800
committerruki <[email protected]>2017-02-06 21:56:55 +0800
commite9aa23db2437faf17ca097e891ec5a1e628865f3 (patch)
tree9c6aa8f108f84ba07e5016796a28b7b8401e0ad8
parent2c125229b2da9e9d854275ae08cd29ecf57a447d (diff)
modify linker script
-rwxr-xr-xdocs/zh/manual.md15
-rw-r--r--xmake/core/language/language.lua18
-rw-r--r--xmake/core/tool/archiver.lua18
-rw-r--r--xmake/core/tool/builder.lua14
-rw-r--r--xmake/core/tool/compiler.lua4
-rw-r--r--xmake/core/tool/linker.lua135
-rwxr-xr-xxmake/languages/asm/xmake.lua4
-rwxr-xr-xxmake/languages/c++/xmake.lua4
-rwxr-xr-xxmake/languages/golang/xmake.lua4
-rwxr-xr-xxmake/languages/objc++/xmake.lua4
-rwxr-xr-xxmake/languages/swift/xmake.lua4
-rwxr-xr-xxmake/tools/cl.lua20
-rwxr-xr-xxmake/tools/clang.lua2
-rwxr-xr-xxmake/tools/gcc.lua24
-rwxr-xr-xxmake/tools/go.lua24
-rwxr-xr-xxmake/tools/link.lua10
-rwxr-xr-xxmake/tools/ml.lua16
-rw-r--r--xmake/tools/swiftc.lua54
18 files changed, 152 insertions, 222 deletions
diff --git a/docs/zh/manual.md b/docs/zh/manual.md
index 402fb59a1..d847e99ca 100755
--- a/docs/zh/manual.md
+++ b/docs/zh/manual.md
@@ -1445,6 +1445,21 @@ add_vectorexts("sse", "sse2", "sse3", "ssse3")
##### option
+
+###### 定义选项
+
+定义和设置选项开关,可用于自定义编译配置选项、开关设置。
+
+例如,定义一个是否启用test的选项:
+
+```lua
+option("enable_test")
+ set_default(false)
+ set_showmenu(true)
+ add_defines("-DTEST")
+```
+
+
##### set_default
##### set_showmenu
##### set_category
diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua
index 0aa61c116..c4d19c5b3 100644
--- a/xmake/core/language/language.lua
+++ b/xmake/core/language/language.lua
@@ -153,21 +153,21 @@ function _instance:targetflags()
return self._INFO.targetflags
end
--- get the named flags
-function _instance:namedflags()
+-- get the name flags
+function _instance:nameflags()
-- attempt to get it from cache first
- if self._NAMEDFLAGS then
- return self._NAMEDFLAGS
+ if self._NAMEFLAGS then
+ return self._NAMEFLAGS
end
- -- get namedflags
+ -- get nameflags
local results = {}
- for toolkind, namedflags in pairs(table.wrap(self._INFO.namedflags)) do
+ for toolkind, nameflags in pairs(table.wrap(self._INFO.nameflags)) do
-- make tool info
local toolinfo = results[toolkind] or {}
- for _, namedflag in ipairs(namedflags) do
+ for _, namedflag in ipairs(nameflags) do
-- split it by '.'
local splitinfo = namedflag:split('.')
@@ -199,7 +199,7 @@ function _instance:namedflags()
end
-- cache this results
- self._NAMEDFLAGS = results
+ self._NAMEFLAGS = results
-- ok?
return results
@@ -241,7 +241,7 @@ function language._interpreter()
, dictionary =
{
-- language.set_xxx
- "language.set_namedflags"
+ "language.set_nameflags"
, "language.set_sourcekinds"
, "language.set_sourceflags"
, "language.set_targetkinds"
diff --git a/xmake/core/tool/archiver.lua b/xmake/core/tool/archiver.lua
index 3bc45d5d3..1b2f6dbc2 100644
--- a/xmake/core/tool/archiver.lua
+++ b/xmake/core/tool/archiver.lua
@@ -133,9 +133,9 @@ function archiver.load(sourcekinds)
end
instance._TOOL = result
- -- load the named flags of archiver
- local namedflags = {}
- local namedflags_exists = {}
+ -- load the name flags of archiver
+ local nameflags = {}
+ local nameflags_exists = {}
for _, sourcekind in ipairs(sourcekinds) do
-- load language
@@ -144,16 +144,16 @@ function archiver.load(sourcekinds)
return nil, errors
end
- -- merge named flags
- for _, flaginfo in ipairs(table.wrap(result:namedflags()["archiver"])) do
+ -- merge name flags
+ for _, flaginfo in ipairs(table.wrap(result:nameflags()["archiver"])) do
local key = flaginfo[1] .. flaginfo[2]
- if not namedflags_exists[key] then
- table.insert(namedflags, flaginfo)
- namedflags_exists[key] = flaginfo
+ if not nameflags_exists[key] then
+ table.insert(nameflags, flaginfo)
+ nameflags_exists[key] = flaginfo
end
end
end
- instance._NAMEDFLAGS = namedflags
+ instance._NAMEFLAGS = nameflags
-- init flag name
instance._FLAGNAME = "arflags"
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index e3955756b..c529d2327 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -45,11 +45,11 @@ function builder:_tool()
return self._TOOL
end
--- get the named flags
-function builder:_namedflags()
+-- get the name flags
+function builder:_nameflags()
-- get it
- return self._NAMEDFLAGS
+ return self._NAMEFLAGS
end
-- map gcc flag to the given builder flag
@@ -131,8 +131,8 @@ function builder:_addflags_from_language(flags, target)
end
}
- -- get named flags for builder
- for _, flaginfo in ipairs(self:_namedflags()) do
+ -- get name flags for builder
+ for _, flaginfo in ipairs(self:_nameflags()) do
-- get flag info
local flagscope = flaginfo[1]
@@ -156,8 +156,8 @@ function builder:_addflags_from_language(flags, target)
apiname = apiname:sub(1, #apiname - 1)
end
- -- map named flag to real flag
- local mapper = self:_tool()[apiname]
+ -- map name flag to real flag
+ local mapper = self:_tool()["nf_" .. apiname]
if mapper then
-- add the flags
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua
index 6e7e5d8e6..61cfd2114 100644
--- a/xmake/core/tool/compiler.lua
+++ b/xmake/core/tool/compiler.lua
@@ -136,8 +136,8 @@ function compiler.load(sourcekind)
end
instance._LANGUAGE = result
- -- init named flags
- instance._NAMEDFLAGS = result:namedflags()["compiler"]
+ -- init name flags
+ instance._NAMEFLAGS = result:nameflags()["compiler"]
-- init source flags
instance._SOURCEFLAGS = table.wrap(result:sourceflags()[sourcekind])
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua
index fe221c662..e925efa81 100644
--- a/xmake/core/tool/linker.lua
+++ b/xmake/core/tool/linker.lua
@@ -52,11 +52,6 @@ function linker:_addflags_from_config(flags)
-- done
table.join2(flags, config.get(self:_flagname()))
-
- -- add the linkdirs flags
- for _, linkdir in ipairs(table.wrap(config.get("linkdirs"))) do
- table.join2(flags, self:linkdir(linkdir))
- end
end
-- add flags from the target
@@ -65,11 +60,6 @@ function linker:_addflags_from_target(flags, target)
-- add the target flags
table.join2(flags, self:_mapflags(target:get(self:_flagname())))
- -- add the linkdirs flags
- for _, linkdir in ipairs(table.wrap(target:get("linkdirs"))) do
- table.join2(flags, self:linkdir(linkdir))
- end
-
-- for target options?
if target.options then
@@ -78,24 +68,6 @@ function linker:_addflags_from_target(flags, target)
-- add the flags from the option
table.join2(flags, self:_mapflags(opt:get(self:_flagname())))
-
- -- add the linkdirs flags from the option
- for _, linkdir in ipairs(table.wrap(opt:get("linkdirs"))) do
- table.join2(flags, self:linkdir(linkdir))
- end
- end
- end
-
- -- add the strip flags
- for _, strip in ipairs(table.wrap(target:get("strip"))) do
- table.join2(flags, self:strip(strip))
- end
-
- -- add the symbol flags
- if target.symbolfile then
- local symbolfile = target:symbolfile()
- for _, symbol in ipairs(table.wrap(target:get("symbols"))) do
- table.join2(flags, self:symbol(symbol, symbolfile))
end
end
end
@@ -105,11 +77,6 @@ function linker:_addflags_from_platform(flags)
-- add flags
table.join2(flags, platform.get(self:_flagname()))
-
- -- add the linkdirs flags
- for _, linkdir in ipairs(table.wrap(platform.get("linkdirs"))) do
- table.join2(flags, self:linkdir(linkdir))
- end
end
-- add flags from the compiler
@@ -137,46 +104,6 @@ function linker:_addflags_from_linker(flags)
table.join2(flags, self:get(self:_flagname()))
end
--- add links from the configure
-function linker:_addlinks_from_config(flags)
-
- -- add the links flags
- for _, link in ipairs(table.wrap(config.get("links"))) do
- table.join2(flags, self:linklib(link))
- end
-end
-
--- add links from the target
-function linker:_addlinks_from_target(flags, target)
-
- -- add the links flags
- for _, link in ipairs(table.wrap(target:get("links"))) do
- table.join2(flags, self:linklib(link))
- end
-
- -- for target options?
- if target.options then
-
- -- add the flags for the target options
- for _, opt in ipairs(target:options()) do
-
- -- add the links flags from the option
- for _, link in ipairs(table.wrap(opt:get("links"))) do
- table.join2(flags, self:linklib(link))
- end
- end
- end
-end
-
--- add links from the platform
-function linker:_addlinks_from_platform(flags)
-
- -- add the links flags
- for _, link in ipairs(table.wrap(platform.get("links"))) do
- table.join2(flags, self:linklib(link))
- end
-end
-
-- load the linker from the given target kind
function linker.load(targetkind, sourcekinds)
@@ -201,6 +128,28 @@ function linker.load(targetkind, sourcekinds)
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()["linker"])) 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 name
instance._FLAGNAME = linkerinfo.flag
@@ -251,6 +200,9 @@ function linker:linkflags(target)
-- add flags from the target
self:_addflags_from_target(flags, target)
+ -- add flags (named) from language
+ self:_addflags_from_language(flags, target)
+
-- add flags from the platform
self:_addflags_from_platform(flags)
@@ -260,15 +212,6 @@ function linker:linkflags(target)
-- add flags from the linker
self:_addflags_from_linker(flags)
- -- add links from the target
- self:_addlinks_from_target(flags, target)
-
- -- add flags from the platform
- self:_addlinks_from_platform(flags)
-
- -- add links from the configure
- self:_addlinks_from_config(flags)
-
-- remove repeat
flags = table.unique(flags)
@@ -282,33 +225,5 @@ function linker:linkflags(target)
return flags_str, flags
end
--- make the strip flag
-function linker:strip(level)
-
- -- make it
- return self:_tool().strip(level)
-end
-
--- make the symbol flag
-function linker:symbol(level, symbolfile)
-
- -- make it
- return self:_tool().symbol(level, symbolfile)
-end
-
--- make the linklib flag
-function linker:linklib(lib)
-
- -- make it
- return self:_tool().linklib(lib)
-end
-
--- make the linkdir flag
-function linker:linkdir(dir)
-
- -- make it
- return self:_tool().linkdir(dir)
-end
-
-- return module
return linker
diff --git a/xmake/languages/asm/xmake.lua b/xmake/languages/asm/xmake.lua
index 7dc9110a0..8cda73bde 100755
--- a/xmake/languages/asm/xmake.lua
+++ b/xmake/languages/asm/xmake.lua
@@ -40,8 +40,8 @@ language("asm")
-- on load
on_load("load")
- -- set named flags
- set_namedflags
+ -- set name flags
+ set_nameflags
{
compiler =
{
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua
index 01e9a920e..0678cbe71 100755
--- a/xmake/languages/c++/xmake.lua
+++ b/xmake/languages/c++/xmake.lua
@@ -43,8 +43,8 @@ language("c++")
-- on check_main
on_check_main("check_main")
- -- set named flags
- set_namedflags
+ -- set name flags
+ set_nameflags
{
compiler =
{
diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua
index 980bb141d..8ae77c1f4 100755
--- a/xmake/languages/golang/xmake.lua
+++ b/xmake/languages/golang/xmake.lua
@@ -43,8 +43,8 @@ language("golang")
-- on check_main
on_check_main("check_main")
- -- set named flags
- set_namedflags
+ -- set name flags
+ set_nameflags
{
compiler =
{
diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua
index b247a9b1b..1557630ad 100755
--- a/xmake/languages/objc++/xmake.lua
+++ b/xmake/languages/objc++/xmake.lua
@@ -43,8 +43,8 @@ language("objc++")
-- on check_main
on_check_main("check_main")
- -- set named flags
- set_namedflags
+ -- set name flags
+ set_nameflags
{
compiler =
{
diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua
index eda43752c..1a4409bd2 100755
--- a/xmake/languages/swift/xmake.lua
+++ b/xmake/languages/swift/xmake.lua
@@ -40,8 +40,8 @@ language("swift")
-- on load
on_load("load")
- -- set named flags
- set_namedflags
+ -- set name flags
+ set_nameflags
{
compiler =
{
diff --git a/xmake/tools/cl.lua b/xmake/tools/cl.lua
index e659fc686..963bf3447 100755
--- a/xmake/tools/cl.lua
+++ b/xmake/tools/cl.lua
@@ -89,7 +89,7 @@ function get(name)
end
-- make the symbol flag
-function symbol(level, symbolfile)
+function nf_symbol(level, target)
-- check -FS flags
if _g._FS == nil then
@@ -108,8 +108,8 @@ function symbol(level, symbolfile)
-- debug? generate *.pdb file
local flags = ""
if level == "debug" then
- if symbolfile then
- flags = "-ZI -Fd" .. symbolfile
+ if target and target.symbolfile then
+ flags = "-ZI -Fd" .. target:symbolfile()
if _g._FS then
flags = "-FS " .. flags
end
@@ -123,7 +123,7 @@ function symbol(level, symbolfile)
end
-- make the warning flag
-function warning(level)
+function nf_warning(level)
-- the maps
local maps =
@@ -140,7 +140,7 @@ function warning(level)
end
-- make the optimize flag
-function optimize(level)
+function nf_optimize(level)
-- the maps
local maps =
@@ -158,7 +158,7 @@ function optimize(level)
end
-- make the vector extension flag
-function vectorext(extension)
+function nf_vectorext(extension)
-- the maps
local maps =
@@ -174,7 +174,7 @@ function vectorext(extension)
end
-- make the language flag
-function language(stdname)
+function nf_language(stdname)
-- the stdc maps
local cmaps =
@@ -197,21 +197,21 @@ function language(stdname)
end
-- make the define flag
-function define(macro)
+function nf_define(macro)
-- make it
return "-D" .. macro:gsub("\"", "\\\"")
end
-- make the undefine flag
-function undefine(macro)
+function nf_undefine(macro)
-- make it
return "-U" .. macro
end
-- make the includedir flag
-function includedir(dir)
+function nf_includedir(dir)
-- make it
return "-I" .. dir
diff --git a/xmake/tools/clang.lua b/xmake/tools/clang.lua
index 2f5ac1a72..eb7c4b058 100755
--- a/xmake/tools/clang.lua
+++ b/xmake/tools/clang.lua
@@ -46,7 +46,7 @@ function init(shellname, kind)
end
-- make the strip flag
-function strip(level)
+function nf_strip(level)
-- the maps
local maps =
diff --git a/xmake/tools/gcc.lua b/xmake/tools/gcc.lua
index 5e2fc3712..47832580f 100755
--- a/xmake/tools/gcc.lua
+++ b/xmake/tools/gcc.lua
@@ -75,7 +75,7 @@ function get(name)
end
-- make the strip flag
-function strip(level)
+function nf_strip(level)
-- the maps
local maps =
@@ -89,7 +89,7 @@ function strip(level)
end
-- make the symbol flag
-function symbol(level)
+function nf_symbol(level)
-- the maps
local maps =
@@ -103,7 +103,7 @@ function symbol(level)
end
-- make the warning flag
-function warning(level)
+function nf_warning(level)
-- the maps
local maps =
@@ -120,7 +120,7 @@ function warning(level)
end
-- make the optimize flag
-function optimize(level)
+function nf_optimize(level)
-- the maps
local maps =
@@ -138,7 +138,7 @@ function optimize(level)
end
-- make the vector extension flag
-function vectorext(extension)
+function nf_vectorext(extension)
-- the maps
local maps =
@@ -158,7 +158,7 @@ function vectorext(extension)
end
-- make the language flag
-function language(stdname)
+function nf_language(stdname)
-- the stdc maps
local cmaps =
@@ -197,35 +197,35 @@ function language(stdname)
end
-- make the define flag
-function define(macro)
+function nf_define(macro)
-- make it
return "-D" .. macro:gsub("\"", "\\\"")
end
-- make the undefine flag
-function undefine(macro)
+function nf_undefine(macro)
-- make it
return "-U" .. macro
end
-- make the includedir flag
-function includedir(dir)
+function nf_includedir(dir)
-- make it
return "-I" .. dir
end
--- make the linklib flag
-function linklib(lib)
+-- make the link flag
+function nf_link(lib)
-- make it
return "-l" .. lib
end
-- make the linkdir flag
-function linkdir(dir)
+function nf_linkdir(dir)
-- make it
return "-L" .. dir
diff --git a/xmake/tools/go.lua b/xmake/tools/go.lua
index 67450cf53..cb14e931b 100755
--- a/xmake/tools/go.lua
+++ b/xmake/tools/go.lua
@@ -47,57 +47,57 @@ function get(name)
end
-- make the strip flag
-function strip(level)
+function nf_strip(level)
return ""
end
-- make the symbol flag
-function symbol(level)
+function nf_symbol(level)
return ""
end
-- make the warning flag
-function warning(level)
+function nf_warning(level)
return ""
end
-- make the optimize flag
-function optimize(level)
+function nf_optimize(level)
return ""
end
-- make the vector extension flag
-function vectorext(extension)
+function nf_vectorext(extension)
return ""
end
-- make the language flag
-function language(stdname)
+function nf_language(stdname)
return ""
end
-- make the define flag
-function define(macro)
+function nf_define(macro)
return ""
end
-- make the undefine flag
-function undefine(macro)
+function nf_undefine(macro)
return ""
end
-- make the includedir flag
-function includedir(dir)
+function nf_includedir(dir)
return ""
end
--- make the linklib flag
-function linklib(lib)
+-- make the link flag
+function nf_link(lib)
return ""
end
-- make the linkdir flag
-function linkdir(dir)
+function nf_linkdir(dir)
return ""
end
diff --git a/xmake/tools/link.lua b/xmake/tools/link.lua
index caea45029..c7e9096bf 100755
--- a/xmake/tools/link.lua
+++ b/xmake/tools/link.lua
@@ -72,12 +72,12 @@ function get(name)
end
-- make the strip flag
-function strip(level)
+function nf_strip(level)
return ""
end
-- make the symbol flag
-function symbol(level, target)
+function nf_symbol(level, target)
-- debug? generate *.pdb file
local flags = ""
@@ -93,15 +93,15 @@ function symbol(level, target)
return flags
end
--- make the linklib flag
-function linklib(lib)
+-- make the link flag
+function nf_link(lib)
-- make it
return lib .. ".lib"
end
-- make the linkdir flag
-function linkdir(dir)
+function nf_linkdir(dir)
-- make it
return "-libpath:" .. dir
diff --git a/xmake/tools/ml.lua b/xmake/tools/ml.lua
index 0eef34d4e..f32b5b361 100755
--- a/xmake/tools/ml.lua
+++ b/xmake/tools/ml.lua
@@ -65,12 +65,12 @@ function get(name)
end
-- make the symbol flag
-function symbol(level, symbolfile)
+function nf_symbol(level)
return ""
end
-- make the warning flag
-function warning(level)
+function nf_warning(level)
-- the maps
local maps =
@@ -87,36 +87,36 @@ function warning(level)
end
-- make the optimize flag
-function optimize(level)
+function nf_optimize(level)
return ""
end
-- make the vector extension flag
-function vectorext(extension)
+function nf_vectorext(extension)
return ""
end
-- make the language flag
-function language(stdname)
+function nf_language(stdname)
return ""
end
-- make the define flag
-function define(macro)
+function nf_define(macro)
-- make it
return "-D" .. macro:gsub("\"", "\\\"")
end
-- make the undefine flag
-function undefine(macro)
+function nf_undefine(macro)
-- make it
return "-U" .. macro
end
-- make the includedir flag
-function includedir(dir)
+function nf_includedir(dir)
-- make it
return "-I" .. dir
diff --git a/xmake/tools/swiftc.lua b/xmake/tools/swiftc.lua
index d3808e261..4fdca0f18 100644
--- a/xmake/tools/swiftc.lua
+++ b/xmake/tools/swiftc.lua
@@ -77,12 +77,12 @@ function get(name)
end
-- make the symbol flag
-function symbol(level, symbolfile)
+function nf_symbol(level)
-- the maps
local maps =
{
- debug = "-g"
+ debug = "-g"
}
-- make it
@@ -90,7 +90,7 @@ function symbol(level, symbolfile)
end
-- make the warning flag
-function warning(level)
+function nf_warning(level)
-- the maps
local maps =
@@ -107,7 +107,7 @@ function warning(level)
end
-- make the optimize flag
-function optimize(level)
+function nf_optimize(level)
-- the maps
local maps =
@@ -125,7 +125,7 @@ function optimize(level)
end
-- make the vector extension flag
-function vectorext(extension)
+function nf_vectorext(extension)
-- the maps
local maps =
@@ -145,10 +145,31 @@ function vectorext(extension)
end
-- make the language flag
-function language(stdname)
+function nf_language(stdname)
return ""
end
+-- make the includedir flag
+function nf_includedir(dir)
+
+ -- make it
+ return "-Xcc -I" .. dir
+end
+
+-- make the define flag
+function nf_define(macro)
+
+ -- make it
+ return "-Xcc -D" .. macro:gsub("\"", "\\\"")
+end
+
+-- make the undefine flag
+function nf_undefine(macro)
+
+ -- make it
+ return "-Xcc -U" .. macro
+end
+
-- make the compile command
function compcmd(sourcefile, objectfile, flags)
@@ -178,27 +199,6 @@ function compile(sourcefile, objectfile, incdepfile, flags)
os.run(compcmd(sourcefile, objectfile, flags))
end
--- make the includedir flag
-function includedir(dir)
-
- -- make it
- return "-Xcc -I" .. dir
-end
-
--- make the define flag
-function define(macro)
-
- -- make it
- return "-Xcc -D" .. macro:gsub("\"", "\\\"")
-end
-
--- make the undefine flag
-function undefine(macro)
-
- -- make it
- return "-Xcc -U" .. macro
-end
-
-- check the given flags
function check(flags)