summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-01-26 13:55:23 +0800
committerruki <[email protected]>2017-01-26 13:55:23 +0800
commitca3f925d00366c8b478d63886245307567682aaa (patch)
tree1436434640fc1876996e8fbe9d0caf6c81f247a3
parentb9685215fcd76bc92a20f0d534f65fa692a599ec (diff)
rewrite named flags for compiler
-rw-r--r--xmake/core/language/language.lua2
-rw-r--r--xmake/core/tool/compiler.lua210
-rwxr-xr-xxmake/languages/asm/xmake.lua14
-rwxr-xr-xxmake/languages/c++/xmake.lua10
-rwxr-xr-xxmake/languages/objc++/xmake.lua10
-rwxr-xr-xxmake/languages/swift/xmake.lua14
-rwxr-xr-xxmake/tools/gcc.lua2
-rwxr-xr-xxmake/tools/go.lua2
-rwxr-xr-xxmake/tools/link.lua8
9 files changed, 122 insertions, 150 deletions
diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua
index bf2a8517f..bf33b211a 100644
--- a/xmake/core/language/language.lua
+++ b/xmake/core/language/language.lua
@@ -176,7 +176,7 @@ function _instance:namedflags()
end
-- insert this flag info
- table.insert(toolinfo, {flagname, checkstate})
+ table.insert(toolinfo, {flagscope, flagname, checkstate})
end
-- save this tool info
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua
index 16720a936..e28509384 100644
--- a/xmake/core/tool/compiler.lua
+++ b/xmake/core/tool/compiler.lua
@@ -123,11 +123,6 @@ function compiler:_addflags_from_config(flags)
for _, sourceflag in ipairs(self:_sourceflags()) do
table.join2(flags, config.get(sourceflag))
end
-
- -- add the includedirs flags
- for _, includedir in ipairs(table.wrap(config.get("includedirs"))) do
- table.join2(flags, self:includedir(includedir))
- end
end
-- add flags from the target
@@ -138,47 +133,6 @@ function compiler:_addflags_from_target(flags, target)
table.join2(flags, self:_mapflags(target:get(sourceflag)))
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
-
- -- add the warning flags
- for _, warning in ipairs(table.wrap(target:get("warnings"))) do
- table.join2(flags, self:warning(warning))
- end
-
- -- add the optimize flags
- table.join2(flags, self:optimize(target:get("optimize") or ""))
-
- -- add the vector extensions flags
- for _, vectorext in ipairs(table.wrap(target:get("vectorexts"))) do
- table.join2(flags, self:vectorext(vectorext))
- end
-
- -- add the language flags
- for _, language in ipairs(table.wrap(target:get("languages"))) do
- table.join2(flags, self:language(language))
- end
-
- -- add the includedirs flags
- for _, includedir in ipairs(table.wrap(target:get("includedirs"))) do
- table.join2(flags, self:includedir(includedir))
- end
-
- -- add the defines flags
- for _, define in ipairs(table.wrap(target:get("defines"))) do
- table.join2(flags, self:define(define))
- end
-
- -- append the undefines flags
- for _, undefine in ipairs(table.wrap(target:get("undefines"))) do
- table.join2(flags, self:undefine(undefine))
- end
-
-- for target options?
if target.options then
@@ -187,16 +141,6 @@ function compiler:_addflags_from_target(flags, target)
-- add the flags from the option
self:_addflags_from_target(flags, opt)
-
- -- append the defines flags
- for _, define in ipairs(table.wrap(opt:get("defines_if_ok"))) do
- table.join2(flags, self:define(define))
- end
-
- -- append the undefines flags
- for _, undefine in ipairs(table.wrap(opt:get("undefines_if_ok"))) do
- table.join2(flags, self:undefine(undefine))
- end
end
end
end
@@ -208,21 +152,6 @@ function compiler:_addflags_from_platform(flags)
for _, sourceflag in ipairs(self:_sourceflags()) do
table.join2(flags, platform.get(sourceflag))
end
-
- -- add the includedirs flags
- for _, includedir in ipairs(table.wrap(platform.get("includedirs"))) do
- table.join2(flags, self:includedir(includedir))
- end
-
- -- add the defines flags
- for _, define in ipairs(table.wrap(platform.get("defines"))) do
- table.join2(flags, self:define(define))
- end
-
- -- append the undefines flags
- for _, undefine in ipairs(table.wrap(platform.get("undefines"))) do
- table.join2(flags, self:undefine(undefine))
- end
end
-- add flags from the compiler
@@ -241,6 +170,70 @@ function compiler:_addflags_from_compiler(flags, kind)
end
end
+-- add flags (named) from the language
+function compiler:_addflags_from_language(flags, target)
+
+ -- init getters
+ local getters =
+ {
+ config = config.get
+ , platform = platform.get
+ , target = function (name) return target:get(name) end
+ , option = function (name)
+
+ -- only for target (exclude option)
+ if target.options then
+ local results = {}
+ for _, opt in ipairs(target:options()) do
+ table.join2(results, table.wrap(opt:get(name)))
+ end
+ return results
+ end
+ end
+ }
+
+ -- get named flags for compiler
+ for _, flaginfo in ipairs(self:_language():namedflags()["compiler"]) do
+
+ -- get flag info
+ local flagscope = flaginfo[1]
+ local flagname = flaginfo[2]
+ local checkstate = flaginfo[3]
+
+ -- get getter
+ local getter = getters[flagscope]
+ assert(getter)
+
+ -- get api name of tool
+ --
+ -- .e.g
+ --
+ -- defines => define
+ -- defines_if_ok => define
+ -- ...
+ --
+ local apiname = flagname:split('_')[1]
+ if apiname:endswith("s") then
+ apiname = apiname:sub(1, #apiname - 1)
+ end
+
+ -- map named flag to real flag
+ local mapper = self:_tool()[apiname]
+ if mapper then
+
+ -- add the flags
+ for _, flagvalue in ipairs(table.wrap(getter(flagname))) do
+
+ -- map and check flag
+ local flag = mapper(flagvalue, target)
+ if flag and flag ~= "" and (not checkstate or self:check(flag)) then
+ table.join2(flags, flag)
+ end
+ end
+ end
+ end
+end
+
-- load the compiler from the given source kind
function compiler.load(sourcekind)
@@ -326,6 +319,9 @@ function compiler:compflags(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)
@@ -345,78 +341,6 @@ function compiler:compflags(target)
return flags_str, flags
end
--- make the symbol flag
-function compiler:symbol(level, symbolfile)
-
- -- make it
- return self:_tool().symbol(level, symbolfile)
-end
-
--- make the language flag
-function compiler:language(stdname)
-
- -- make it
- local flags = self:_tool().language(stdname)
-
- -- check it
- if self:check(flags) then
- return flags
- end
-
- -- not support
- return ""
-end
-
--- make the vector extension flag
-function compiler:vectorext(extension)
-
- -- make it
- local flags = self:_tool().vectorext(extension)
-
- -- check it
- if self:check(flags) then
- return flags
- end
-
- -- not support
- return ""
-end
-
--- make the optimize flag
-function compiler:optimize(level)
-
- -- make it
- return self:_tool().optimize(level)
-end
-
--- make the warning flag
-function compiler:warning(level)
-
- -- make it
- return self:_tool().warning(level)
-end
-
--- make the define flag
-function compiler:define(macro)
-
- -- make it
- return self:_tool().define(macro)
-end
-
--- make the undefine flag
-function compiler:undefine(macro)
-
- -- make it
- return self:_tool().undefine(macro)
-end
-
--- make the includedir flag
-function compiler:includedir(dir)
-
- -- make it
- return self:_tool().includedir(dir)
-end
-
-- check the given flags
function compiler:check(flags)
diff --git a/xmake/languages/asm/xmake.lua b/xmake/languages/asm/xmake.lua
index fa829df90..1cee85852 100755
--- a/xmake/languages/asm/xmake.lua
+++ b/xmake/languages/asm/xmake.lua
@@ -47,8 +47,20 @@ language("asm")
, "target.warnings"
, "target.optimize:check"
, "target.vectorexts:check"
+ , "target.languages"
+ , "target.includedirs"
, "target.defines"
, "target.undefines"
+ , "option.symbols"
+ , "option.warnings"
+ , "option.optimize:check"
+ , "option.vectorexts:check"
+ , "option.languages"
+ , "option.includedirs"
+ , "option.defines"
+ , "option.undefines"
+ , "option.defines_if_ok"
+ , "option.undefines_if_ok"
, "platform.includedirs"
, "platform.defines"
, "platform.undefines"
@@ -59,6 +71,8 @@ language("asm")
, "target.linkdirs"
, "target.strip"
, "target.symbols"
+ , "option.strip"
+ , "option.symbols"
, "option.linkdirs"
, "platform.linkdirs"
, "config.links"
diff --git a/xmake/languages/c++/xmake.lua b/xmake/languages/c++/xmake.lua
index 0f32ea204..a756de4df 100755
--- a/xmake/languages/c++/xmake.lua
+++ b/xmake/languages/c++/xmake.lua
@@ -54,6 +54,14 @@ language("c++")
, "target.includedirs"
, "target.defines"
, "target.undefines"
+ , "option.symbols"
+ , "option.warnings"
+ , "option.optimize:check"
+ , "option.vectorexts:check"
+ , "option.languages"
+ , "option.includedirs"
+ , "option.defines"
+ , "option.undefines"
, "option.defines_if_ok"
, "option.undefines_if_ok"
, "platform.includedirs"
@@ -66,6 +74,8 @@ language("c++")
, "target.linkdirs"
, "target.strip"
, "target.symbols"
+ , "option.strip"
+ , "option.symbols"
, "option.linkdirs"
, "platform.linkdirs"
, "config.links"
diff --git a/xmake/languages/objc++/xmake.lua b/xmake/languages/objc++/xmake.lua
index ee5e986ed..59d0ba0cc 100755
--- a/xmake/languages/objc++/xmake.lua
+++ b/xmake/languages/objc++/xmake.lua
@@ -54,6 +54,14 @@ language("objc++")
, "target.includedirs"
, "target.defines"
, "target.undefines"
+ , "option.symbols"
+ , "option.warnings"
+ , "option.optimize:check"
+ , "option.vectorexts:check"
+ , "option.languages"
+ , "option.includedirs"
+ , "option.defines"
+ , "option.undefines"
, "option.defines_if_ok"
, "option.undefines_if_ok"
, "platform.includedirs"
@@ -66,6 +74,8 @@ language("objc++")
, "target.linkdirs"
, "target.strip"
, "target.symbols"
+ , "option.strip"
+ , "option.symbols"
, "option.linkdirs"
, "platform.linkdirs"
, "config.links"
diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua
index 13aea0f27..97e84326d 100755
--- a/xmake/languages/swift/xmake.lua
+++ b/xmake/languages/swift/xmake.lua
@@ -47,8 +47,20 @@ language("swift")
, "target.warnings"
, "target.optimize:check"
, "target.vectorexts:check"
+ , "target.languages"
+ , "target.includedirs"
, "target.defines"
, "target.undefines"
+ , "option.symbols"
+ , "option.warnings"
+ , "option.optimize:check"
+ , "option.vectorexts:check"
+ , "option.languages"
+ , "option.includedirs"
+ , "option.defines"
+ , "option.undefines"
+ , "option.defines_if_ok"
+ , "option.undefines_if_ok"
, "platform.includedirs"
, "platform.defines"
, "platform.undefines"
@@ -59,6 +71,8 @@ language("swift")
, "target.linkdirs"
, "target.strip"
, "target.symbols"
+ , "option.strip"
+ , "option.symbols"
, "option.linkdirs"
, "platform.linkdirs"
, "config.links"
diff --git a/xmake/tools/gcc.lua b/xmake/tools/gcc.lua
index 478529089..5e2fc3712 100755
--- a/xmake/tools/gcc.lua
+++ b/xmake/tools/gcc.lua
@@ -89,7 +89,7 @@ function strip(level)
end
-- make the symbol flag
-function symbol(level, symbolfile)
+function symbol(level)
-- the maps
local maps =
diff --git a/xmake/tools/go.lua b/xmake/tools/go.lua
index 3d5a62131..67450cf53 100755
--- a/xmake/tools/go.lua
+++ b/xmake/tools/go.lua
@@ -52,7 +52,7 @@ function strip(level)
end
-- make the symbol flag
-function symbol(level, symbolfile)
+function symbol(level)
return ""
end
diff --git a/xmake/tools/link.lua b/xmake/tools/link.lua
index 197597711..caea45029 100755
--- a/xmake/tools/link.lua
+++ b/xmake/tools/link.lua
@@ -77,13 +77,13 @@ function strip(level)
end
-- make the symbol flag
-function symbol(level, symbolfile)
-
+function symbol(level, target)
+
-- debug? generate *.pdb file
local flags = ""
if level == "debug" then
- if symbolfile then
- flags = "-debug -pdb:" .. symbolfile
+ if target and target.symbolfile then
+ flags = "-debug -pdb:" .. target:symbolfile()
else
flags = "-debug"
end