summaryrefslogtreecommitdiff
path: root/xmake/core/tool
diff options
context:
space:
mode:
authorruki <[email protected]>2020-05-26 22:36:59 +0800
committerruki <[email protected]>2020-05-26 09:41:58 +0800
commit11c655cdde82b1c82c25ea29227e90cea658ba35 (patch)
tree60dae7766ac0c43c891c3c77873e1a60db90266c /xmake/core/tool
parent5c8d2277d8a3500a2078cf488c49c3c167349717 (diff)
add target:toolconfig
Diffstat (limited to 'xmake/core/tool')
-rw-r--r--xmake/core/tool/builder.lua8
-rw-r--r--xmake/core/tool/compiler.lua37
-rw-r--r--xmake/core/tool/linker.lua41
3 files changed, 56 insertions, 30 deletions
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index 042aa5001..03a9f34ed 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -263,7 +263,13 @@ function builder:_add_flags_from_language(flags, target, getters)
end
return values
end
- , platform = platform.toolconfig
+ , toolchain = function (name)
+ if target and target:type() == "target" then
+ return target:toolconfig(name)
+ else
+ return platform.toolconfig(name)
+ end
+ end
, target = function (name)
-- only for target
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua
index 8d6db1da8..b99bfdfca 100644
--- a/xmake/core/tool/compiler.lua
+++ b/xmake/core/tool/compiler.lua
@@ -40,15 +40,22 @@ function compiler:_language()
return self._LANGUAGE
end
--- add flags from the platform
-function compiler:_add_flags_from_platform(flags, targetkind)
+-- add flags from the toolchains
+function compiler:_add_flags_from_toolchains(flags, targetkind, target)
-- add flags for platform with the given target kind, e.g. binary.gcc.cxflags or binary.cxflags
if targetkind then
local toolname = self:name()
- for _, flagkind in ipairs(self:_flagkinds()) do
- local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind)
- table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. flagkind))
+ if target and target:type() == "target" then
+ for _, flagkind in ipairs(self:_flagkinds()) do
+ local toolflags = target:toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind)
+ table.join2(flags, toolflags or target:toolconfig(targetkind .. '.' .. flagkind))
+ end
+ else
+ for _, flagkind in ipairs(self:_flagkinds()) do
+ local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind)
+ table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. flagkind))
+ end
end
end
end
@@ -129,15 +136,17 @@ function compiler.load(sourcekind, target)
-- save this instance
compiler._INSTANCES[cachekey] = instance
- -- add platform flags to the compiler tool
+ -- add toolchains flags to the compiler tool, e.g. gcc.cxflags or cxflags
local toolname = compiler_tool:name()
- for _, flagkind in ipairs(instance:_flagkinds()) do
-
- -- add flags for platform, e.g. gcc.cxflags or cxflags
- compiler_tool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind))
+ if target and target:type() == "target" then
+ for _, flagkind in ipairs(instance:_flagkinds()) do
+ compiler_tool:add(flagkind, target:toolconfig(toolname .. '.' .. flagkind) or target:toolconfig(flagkind))
+ end
+ else
+ for _, flagkind in ipairs(instance:_flagkinds()) do
+ compiler_tool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind))
+ end
end
-
- -- ok
return instance
end
@@ -312,8 +321,8 @@ function compiler:compflags(opt)
self:_add_flags_from_argument(flags, target, configs)
end
- -- add flags from the platform
- self:_add_flags_from_platform(flags, targetkind)
+ -- add flags from the toolchains
+ self:_add_flags_from_toolchains(flags, targetkind, target)
-- add flags from the compiler
self:_add_flags_from_compiler(flags, targetkind)
diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua
index 9a6141f03..baafde7ae 100644
--- a/xmake/core/tool/linker.lua
+++ b/xmake/core/tool/linker.lua
@@ -36,16 +36,23 @@ local tool = require("tool/tool")
local builder = require("tool/builder")
local compiler = require("tool/compiler")
--- add flags from the platform
-function linker:_add_flags_from_platform(flags, targetkind)
+-- add flags from the toolchains
+function linker:_add_flags_from_toolchains(flags, targetkind, target)
-- attempt to add special lanugage flags first for target kind, e.g. binary.go.gcldflags, static.dcarflags
if targetkind then
local toolkind = self:kind()
local toolname = self:name()
- for _, flagkind in ipairs(self:_flagkinds()) do
- local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind)
- table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. flagkind))
+ if target and target:type() == "target" then
+ for _, flagkind in ipairs(self:_flagkinds()) do
+ local toolflags = target:toolconfig(targetkind .. '.' .. toolname .. '.' .. toolkind .. 'flags') or target:toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind)
+ table.join2(flags, toolflags or target:toolconfig(targetkind .. '.' .. toolkind .. 'flags') or target:toolconfig(targetkind .. '.' .. flagkind))
+ end
+ else
+ for _, flagkind in ipairs(self:_flagkinds()) do
+ local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind)
+ table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. flagkind))
+ end
end
end
end
@@ -174,17 +181,21 @@ function linker.load(targetkind, sourcekinds, target)
-- save this instance
builder._INSTANCES[cachekey] = instance
- -- add platform flags to the linker tool
+ -- add toolchains flags to the linker tool
+ -- add special lanugage flags first, e.g. go.gcldflags or gcc.ldflags or gcldflags or ldflags
local toolkind = linkertool:kind()
local toolname = linkertool:name()
- for _, flagkind in ipairs(instance:_flagkinds()) do
-
- -- add special lanugage flags first, e.g. go.gcldflags or gcc.ldflags or gcldflags or ldflags
- linkertool:add(toolkind .. 'flags', platform.toolconfig(toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(toolkind .. 'flags'))
- linkertool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind))
+ if target and target:type() == "target" then
+ for _, flagkind in ipairs(instance:_flagkinds()) do
+ linkertool:add(toolkind .. 'flags', target:toolconfig(toolname .. '.' .. toolkind .. 'flags') or target:toolconfig(toolkind .. 'flags'))
+ linkertool:add(flagkind, target:toolconfig(toolname .. '.' .. flagkind) or target:toolconfig(flagkind))
+ end
+ else
+ for _, flagkind in ipairs(instance:_flagkinds()) do
+ linkertool:add(toolkind .. 'flags', platform.toolconfig(toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(toolkind .. 'flags'))
+ linkertool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind))
+ end
end
-
- -- ok
return instance
end
@@ -236,8 +247,8 @@ function linker:linkflags(opt)
self:_add_flags_from_argument(flags, target, configs)
end
- -- add flags from the platform
- self:_add_flags_from_platform(flags, targetkind)
+ -- add flags from the toolchains
+ self:_add_flags_from_toolchains(flags, targetkind, target)
-- add flags from the linker
self:_add_flags_from_linker(flags)