summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-05 16:06:45 +0800
committerruki <[email protected]>2015-06-05 16:06:45 +0800
commit411e3138ec53ab99c73f0124ef93ac98d746cdc9 (patch)
treed7e719ea57e12402f630deb1ed998a00304510ff /xmake/scripts
parentfe68854c321f2e586cab55dce6856b89241b4c20 (diff)
join flags for compiler and linker
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/base/compiler.lua44
-rw-r--r--xmake/scripts/base/linker.lua23
-rw-r--r--xmake/scripts/platform/windows/tools/cl.lua4
-rw-r--r--xmake/scripts/platform/windows/tools/link.lua11
-rw-r--r--xmake/scripts/tools/ar.lua2
-rw-r--r--xmake/scripts/tools/clang.lua24
6 files changed, 41 insertions, 67 deletions
diff --git a/xmake/scripts/base/compiler.lua b/xmake/scripts/base/compiler.lua
index 101347c19..3db08581a 100644
--- a/xmake/scripts/base/compiler.lua
+++ b/xmake/scripts/base/compiler.lua
@@ -26,6 +26,7 @@ local compiler = compiler or {}
-- load modules
local path = require("base/path")
local utils = require("base/utils")
+local table = require("base/table")
local string = require("base/string")
local config = require("base/config")
local tools = require("tools/tools")
@@ -129,32 +130,21 @@ function compiler.make(module, target, srcfile, objfile)
end
-- get the common flags from the current compiler
- local flags_common = ""
+ local flags = {}
for _, flag_name in ipairs(flag_names) do
- flags_common = flags_common:append(module[flag_name], " ")
+ table.join2(flags, module[flag_name])
end
-- get the target flags from the current project
- local flags_target = ""
for _, flag_name in ipairs(flag_names) do
-
- -- get flags
- local flags = table.concat(compiler._mapflags(module, utils.wrap(target[flag_name])), " ")
-
- -- trim the spaces
- flags = flags:trim()
-
- -- append flags
- if flags and #flags ~= 0 then
- flags_target = flags_target:append(flags, " ")
- end
+ table.join2(flags, compiler._mapflags(module, utils.wrap(target[flag_name])))
end
-- get the includedirs flags from the current project
if module._make_includedir then
local includedirs = utils.wrap(target.includedirs)
for _, includedir in ipairs(includedirs) do
- flags_target = flags_target:append(module.flag_includedir(includedir), " ")
+ table.join2(flags, module.flag_includedir(includedir))
end
end
@@ -162,35 +152,17 @@ function compiler.make(module, target, srcfile, objfile)
if module._make_define then
local defines = utils.wrap(target.defines)
for _, define in ipairs(defines) do
- flags_target = flags_target:append(module.flag_define(define), " ")
+ table.join2(flags, module.flag_define(define))
end
end
-- get the config flags
- local flags_config = ""
for _, flag_name in ipairs(flag_names) do
-
- -- get flags
- local flags = table.concat(compiler._mapflags(module, utils.wrap(config.get(flag_name))), " ")
-
- -- trim the spaces
- flags = flags:trim()
-
- -- append flags
- if flags and #flags ~= 0 then
- flags_config = flags_config:append(flags, " ")
- end
+ table.join2(flags, compiler._mapflags(module, utils.wrap(config.get(flag_name))))
end
- -- make the flags string
- local flags = ""
- flags = flags:append(flags_common, " ")
- flags = flags:append(flags_target, " ")
- flags = flags:append(flags_config, " ")
- flags = flags:trim()
-
-- make the compile command
- return module.command_compile(srcfile, objfile, flags)
+ return module.command_compile(srcfile, objfile, table.concat(flags, " "):trim())
end
-- return module: compiler
diff --git a/xmake/scripts/base/linker.lua b/xmake/scripts/base/linker.lua
index 2516bbd29..6f3e7c972 100644
--- a/xmake/scripts/base/linker.lua
+++ b/xmake/scripts/base/linker.lua
@@ -25,6 +25,7 @@ local linker = linker or {}
-- load modules
local utils = require("base/utils")
+local table = require("base/table")
local string = require("base/string")
local config = require("base/config")
local tools = require("tools/tools")
@@ -75,17 +76,17 @@ function linker.make(module, target, objfiles, targetfile)
end
-- get the common flags from the current linker
- local flags_common = module[flag_name] or ""
+ local flags = {}
+ table.join2(flags, module[flag_name])
-- get the target flags from the current project
- local flags_target = table.concat(linker._mapflags(module, utils.wrap(target[flag_name])), " ")
- assert(flags_target)
+ table.join2(flags, linker._mapflags(module, utils.wrap(target[flag_name])))
-- get the linkdirs flags from the current project
if module._make_linkdir then
local linkdirs = utils.wrap(target.linkdirs)
for _, linkdir in ipairs(linkdirs) do
- flags_target = flags_target:append(module.flag_linkdir(linkdir), " ")
+ table.join2(flags, module.flag_linkdir(linkdir))
end
end
@@ -93,23 +94,15 @@ function linker.make(module, target, objfiles, targetfile)
if module._make_link then
local links = utils.wrap(target.links)
for _, link in ipairs(links) do
- flags_target = flags_target:append(module.flag_link(link), " ")
+ table.join2(flags, module.flag_link(link))
end
end
-- get the config flags
- local flags_config = table.concat(linker._mapflags(module, utils.wrap(config.get(flag_name))), " ")
- assert(flags_config)
-
- -- make the flags string
- local flags = ""
- flags = flags:append(flags_common, " ")
- flags = flags:append(flags_target, " ")
- flags = flags:append(flags_config, " ")
- flags = flags:trim()
+ table.join2(flags, linker._mapflags(module, utils.wrap(config.get(flag_name))))
-- make the link command
- return module.command_link(table.concat(objfiles, " "), targetfile, flags)
+ return module.command_link(table.concat(objfiles, " "), targetfile, table.concat(flags, " "):trim())
end
-- get the linker from the given kind
diff --git a/xmake/scripts/platform/windows/tools/cl.lua b/xmake/scripts/platform/windows/tools/cl.lua
index a8ab807a7..24c45bec3 100644
--- a/xmake/scripts/platform/windows/tools/cl.lua
+++ b/xmake/scripts/platform/windows/tools/cl.lua
@@ -32,10 +32,10 @@ local config = require("base/config")
function cl.init(name)
-- init cflags
- cl.cflags = "-nologo"
+ cl.cflags = { "-nologo" }
-- init cxxflags
- cl.cxxflags = "-nologo"
+ cl.cxxflags = { "-nologo" }
end
diff --git a/xmake/scripts/platform/windows/tools/link.lua b/xmake/scripts/platform/windows/tools/link.lua
index 52528ca6c..5ccd8945e 100644
--- a/xmake/scripts/platform/windows/tools/link.lua
+++ b/xmake/scripts/platform/windows/tools/link.lua
@@ -42,13 +42,18 @@ function link.init(name)
end
-- init ldflags
- link.ldflags = "-nologo -dynamicbase -nxcompat -manifest -manifestuac:\"level='asInvoker' uiAccess='false'\" " .. flags_arch
+ link.ldflags = { "-nologo"
+ , "-dynamicbase"
+ , "-nxcompat"
+ , "-manifest"
+ , "-manifestuac:\"level='asInvoker' uiAccess='false'\""
+ , flags_arch}
-- init arflags
- link.arflags = "-lib -nologo " .. flags_arch
+ link.arflags = {"-lib", "-nologo", flags_arch}
-- init shflags
- link.shflags = "-dll -nologo " .. flags_arch
+ link.shflags = {"-dll", "-nologo", flags_arch}
end
-- make the linker command
diff --git a/xmake/scripts/tools/ar.lua b/xmake/scripts/tools/ar.lua
index e39967117..008aba7b6 100644
--- a/xmake/scripts/tools/ar.lua
+++ b/xmake/scripts/tools/ar.lua
@@ -35,7 +35,7 @@ function ar.init(name)
ar.name = name or "ar"
-- init arflags
- ar.arflags = "-crs"
+ ar.arflags = { "-crs" }
end
diff --git a/xmake/scripts/tools/clang.lua b/xmake/scripts/tools/clang.lua
index 0e2ac3dbd..d8fdbaf4b 100644
--- a/xmake/scripts/tools/clang.lua
+++ b/xmake/scripts/tools/clang.lua
@@ -22,6 +22,7 @@
-- load modules
local utils = require("base/utils")
+local table = require("base/table")
local string = require("base/string")
local config = require("base/config")
@@ -46,28 +47,31 @@ function clang.init(name)
end
-- init cxflags
- clang.cxflags = flags_arch
+ clang.cxflags = { flags_arch }
-- init mxflags
- clang.mxflags = flags_arch .. " -fmessage-length=0 -pipe -fpascal-strings"
- .. " \"-DIBOutlet=__attribute__((iboutlet))\""
- .. " \"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))\""
- .. " \"-DIBAction=void)__attribute__((ibaction)\""
+ clang.mxflags = { flags_arch
+ , "-fmessage-length=0"
+ , "-pipe"
+ , "-fpascal-strings"
+ , "\"-DIBOutlet=__attribute__((iboutlet))\""
+ , "\"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))\""
+ , "\"-DIBAction=void)__attribute__((ibaction)\""}
-- init asflags
- clang.asflags = flags_arch
+ clang.asflags = { flags_arch }
-- init ldflags
- clang.ldflags = flags_arch
+ clang.ldflags = { flags_arch }
-- init shflags
- clang.shflags = flags_arch .. " -dynamiclib"
+ clang.shflags = { flags_arch, "-dynamiclib" }
-- suppress warning for the ccache bug
local ccache = config.get("ccache")
if ccache and ccache == "y" then
- clang.cxflags = clang.cxflags:append("-Qunused-arguments", " ")
- clang.mxflags = clang.mxflags:append("-Qunused-arguments", " ")
+ table.join2(clang.cxflags, "-Qunused-arguments")
+ table.join2(clang.mxflags, "-Qunused-arguments")
end
end