diff options
| author | ruki <[email protected]> | 2017-07-11 14:51:52 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-07-11 14:51:52 +0800 |
| commit | 410a36dad68dc1f0b2ac9c12d861af7ab8d0b1d6 (patch) | |
| tree | e33e94caea84d3a170f6dd86c36ac2e4adbd6687 | |
| parent | 03420ca44581f299a48935ca60af4824575cd9c1 (diff) | |
rename has_flag to has_flags
36 files changed, 395 insertions, 395 deletions
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index b3f58c512..d98ae5212 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -247,8 +247,8 @@ function compiler:compflags(opt) -- remove repeat flags = table.unique(flags) - -- concat - local flags_str = table.concat(flags, " "):trim() + -- make flags string + local flags_str = table.concat(flags, " "):trim():gsub("\"", "\\\"") -- save flags if key then diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index 133620d3d..9d055bbf0 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -254,8 +254,8 @@ function linker:linkflags(opt) -- remove repeat flags = table.unique(flags) - -- merge flags - local flags_str = table.concat(flags, " "):trim() + -- make flags string + local flags_str = table.concat(flags, " "):trim():gsub("\"", "\\\"") -- save flags if key then diff --git a/xmake/modules/core/tools/ar.lua b/xmake/modules/core/tools/ar.lua index 9d7ddabeb..bce088fc3 100644 --- a/xmake/modules/core/tools/ar.lua +++ b/xmake/modules/core/tools/ar.lua @@ -27,15 +27,11 @@ import("core.tool.compiler") -- init it function init(self) - - -- init arflags _g.arflags = { "-cr" } end -- get the property function get(self, name) - - -- get it return _g[name] end @@ -45,12 +41,12 @@ function strip(self, level) -- the maps local maps = { - debug = "-S" - , all = "-s" + debug = "-S" + , all = "-s" } -- make it - return maps[level] or "" + return maps[level] end -- make the link command diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index b55948ecd..a28e08589 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -188,7 +188,7 @@ end -- make the define flag function nf_define(self, macro) - return "-D" .. macro:gsub("\"", "\\\"") + return "-D" .. macro end -- make the undefine flag diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua index f391b101e..7da8dd858 100644 --- a/xmake/modules/core/tools/clang.lua +++ b/xmake/modules/core/tools/clang.lua @@ -48,12 +48,12 @@ end function nf_strip(self, level) -- the maps - local maps = + local maps = { - debug = "-Wl,-S" - , all = "-Wl,-S" + debug = "-Wl,-S" + , all = "-Wl,-S" } -- make it - return maps[level] or "" + return maps[level] end diff --git a/xmake/modules/core/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua index 02178577e..45f915afc 100644 --- a/xmake/modules/core/tools/dmd.lua +++ b/xmake/modules/core/tools/dmd.lua @@ -58,16 +58,15 @@ function nf_optimize(self, level) -- the maps local maps = { - none = "" - , fast = "-O" - , faster = "-O -release" - , fastest = "-O -release -inline -boundscheck=off" - , smallest = "-O -release -boundscheck=off" - , aggressive = "-O -release -inline -boundscheck=off" + , fast = {"-O"} + , faster = {"-O", "-release"} + , fastest = {"-O", "-release", "-inline", "-boundscheck=off"} + , smallest = {"-O", "-release", "-boundscheck=off"} + , aggressive = {"-O", "-release", "-inline", "-boundscheck=off"} } -- make it - return maps[level] or "" + return maps[level] end -- make the strip flag @@ -81,7 +80,7 @@ function nf_strip(self, level) } -- make it - return maps[level] or "" + return maps[level] end -- make the symbol flag @@ -90,12 +89,11 @@ function nf_symbol(self, level) -- the maps local maps = { - debug = "-g -debug" - , hidden = "" + debug = {"-g", "-debug"} } -- make it - return maps[level] or "" + return maps[level] end -- make the warning flag @@ -106,13 +104,13 @@ function nf_warning(self, level) { none = "-d" , less = "-w" - , more = "-w -wi" - , all = "-w -wi" + , more = {"-w", "-wi"} + , all = {"-w", "-wi"} , error = "-de" } -- make it - return maps[level] or "" + return maps[level] end -- make the vector extension flag @@ -126,7 +124,7 @@ function nf_vectorext(self, extension) } -- make it - return maps[extension] or "" + return maps[extension] end -- make the includedir flag diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 1bfcb6db9..62d41abc3 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -35,9 +35,9 @@ function init(self) _g.mxflags = { "-fmessage-length=0" , "-pipe" , "-fpascal-strings" - , "\"-DIBOutlet=__attribute__((iboutlet))\"" - , "\"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))\"" - , "\"-DIBAction=void)__attribute__((ibaction)\""} + , "-DIBOutlet=__attribute__((iboutlet))" + , "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" + , "-DIBAction=void)__attribute__((ibaction)"} -- init shflags _g.shflags = { "-shared", "-fPIC" } @@ -86,12 +86,12 @@ function nf_strip(self, level) -- the maps local maps = { - debug = "-S" - , all = "-s" + debug = "-S" + , all = "-s" } -- make it - return maps[level] or "" + return maps[level] end -- make the symbol flag @@ -100,12 +100,12 @@ function nf_symbol(self, level) -- the maps local maps = { - debug = "-g" - , hidden = "-fvisibility=hidden" + debug = "-g" + , hidden = "-fvisibility=hidden" } -- make it - return maps[level] or "" + return maps[level] end -- make the warning flag @@ -114,15 +114,15 @@ function nf_warning(self, level) -- the maps local maps = { - none = "-w" - , less = "-W1" - , more = "-W3" - , all = "-Wall" - , error = "-Werror" + none = "-w" + , less = "-W1" + , more = "-W3" + , all = "-Wall" + , error = "-Werror" } -- make it - return maps[level] or "" + return maps[level] end -- make the optimize flag @@ -131,16 +131,16 @@ function nf_optimize(self, level) -- the maps local maps = { - none = "-O0" - , fast = "-O1" - , faster = "-O2" - , fastest = "-O3" - , smallest = "-Os" - , aggressive = "-Ofast" + none = "-O0" + , fast = "-O1" + , faster = "-O2" + , fastest = "-O3" + , smallest = "-Os" + , aggressive = "-Ofast" } -- make it - return maps[level] or "" + return maps[level] end -- make the vector extension flag @@ -149,18 +149,18 @@ function nf_vectorext(self, extension) -- the maps local maps = { - mmx = "-mmmx" - , sse = "-msse" - , sse2 = "-msse2" - , sse3 = "-msse3" - , ssse3 = "-mssse3" - , avx = "-mavx" - , avx2 = "-mavx2" - , neon = "-mfpu=neon" + mmx = "-mmmx" + , sse = "-msse" + , sse2 = "-msse2" + , sse3 = "-msse3" + , ssse3 = "-mssse3" + , avx = "-mavx" + , avx2 = "-mavx2" + , neon = "-mfpu=neon" } -- make it - return maps[extension] or "" + return maps[extension] end -- make the language flag @@ -203,12 +203,12 @@ function nf_language(self, stdname) end -- make it - return maps[stdname] or "" + return maps[stdname] end -- make the define flag function nf_define(self, macro) - return "-D" .. macro:gsub("\"", "\\\"") + return "-D" .. macro end -- make the undefine flag @@ -240,7 +240,7 @@ end -- make the framework flag function nf_framework(self, framework) - return "-framework " .. framework + return {"-framework", framework} end -- make the link command diff --git a/xmake/modules/core/tools/go.lua b/xmake/modules/core/tools/go.lua index a3b49c8c4..46b434e58 100644 --- a/xmake/modules/core/tools/go.lua +++ b/xmake/modules/core/tools/go.lua @@ -55,16 +55,11 @@ function nf_optimize(self, level) -- the maps local maps = { - none = "-N" - , fast = "" - , faster = "" - , fastest = "" - , smallest = "" - , aggressive = "" + none = "-N" } -- make it - return maps[level] or "" + return maps[level] end -- make the symbol flag @@ -72,18 +67,17 @@ function nf_symbol(self, level, target, mapkind) -- only for compiler if mapkind ~= "object" then - return "" + return end -- the maps local maps = { - debug = "-E" - , hidden = "" + debug = "-E" } -- make it - return maps[level] or "" + return maps[level] end -- make the strip flag @@ -92,22 +86,22 @@ function nf_strip(self, level) -- the maps local maps = { - debug = "-s" - , all = "-s" + debug = "-s" + , all = "-s" } -- make it - return maps[level] or "" + return maps[level] end -- make the includedir flag function nf_includedir(self, dir) - return "-I " .. dir + return {"-I", dir} end -- make the linkdir flag function nf_linkdir(self, dir) - return "-L " .. dir + return {"-L", dir} end -- make the link command diff --git a/xmake/modules/core/tools/lib.lua b/xmake/modules/core/tools/lib.lua index a193b8788..b7d18b024 100644 --- a/xmake/modules/core/tools/lib.lua +++ b/xmake/modules/core/tools/lib.lua @@ -24,8 +24,6 @@ -- get the property function get(self, name) - - -- get it return _g[name] end diff --git a/xmake/modules/core/tools/ml.lua b/xmake/modules/core/tools/ml.lua index 74a8fc364..27343320e 100644 --- a/xmake/modules/core/tools/ml.lua +++ b/xmake/modules/core/tools/ml.lua @@ -70,20 +70,20 @@ function nf_warning(self, level) -- the maps local maps = { - none = "-w" - , less = "-W1" - , more = "-W3" - , all = "-W3" - , error = "-WX" + none = "-w" + , less = "-W1" + , more = "-W3" + , all = "-W3" + , error = "-WX" } -- make it - return maps[level] or "" + return maps[level] end -- make the define flag function nf_define(self, macro) - return "-D" .. macro:gsub("\"", "\\\"") + return "-D" .. macro end -- make the undefine flag diff --git a/xmake/modules/core/tools/rc.lua b/xmake/modules/core/tools/rc.lua index a76d7493d..75a679ddd 100644 --- a/xmake/modules/core/tools/rc.lua +++ b/xmake/modules/core/tools/rc.lua @@ -43,7 +43,7 @@ end -- make the define flag function nf_define(self, macro) - return "-d" .. macro:gsub("\"", "\\\"") + return "-d" .. macro end -- make the undefine flag diff --git a/xmake/modules/core/tools/rustc.lua b/xmake/modules/core/tools/rustc.lua index e480624d9..635d94e9c 100644 --- a/xmake/modules/core/tools/rustc.lua +++ b/xmake/modules/core/tools/rustc.lua @@ -64,16 +64,16 @@ function nf_optimize(self, level) -- the maps local maps = { - none = "-C opt-level=0" - , fast = "-C opt-level=1" - , faster = "-C opt-level=2" - , fastest = "-C opt-level=3" - , smallest = "-C opt-level=s" - , aggressive = "-C opt-level=z" + none = {"-C", "opt-level=0"} + , fast = {"-C", "opt-level=1"} + , faster = {"-C", "opt-level=2"} + , fastest = {"-C", "opt-level=3"} + , smallest = {"-C", "opt-level=s"} + , aggressive = {"-C", "opt-level=z"} } -- make it - return maps[level] or "" + return maps[level] end -- make the symbol flag @@ -82,17 +82,16 @@ function nf_symbol(self, level) -- the maps local maps = { - debug = "-C debuginfo=2" - , hidden = "" + debug = {"-C", "debuginfo=2"} } -- make it - return maps[level] or "" + return maps[level] end -- make the linkdir flag function nf_linkdir(self, dir) - return "-L " .. dir + return {"-L", dir} end -- make the build command diff --git a/xmake/modules/core/tools/swiftc.lua b/xmake/modules/core/tools/swiftc.lua index e1c18934e..c1b9aad93 100644 --- a/xmake/modules/core/tools/swiftc.lua +++ b/xmake/modules/core/tools/swiftc.lua @@ -152,22 +152,22 @@ end -- make the includedir flag function nf_includedir(self, dir) - return "-Xcc -I" .. dir + return {"-Xcc", "-I" .. dir} end -- make the define flag function nf_define(self, macro) - return "-Xcc -D" .. macro:gsub("\"", "\\\"") + return {"-Xcc", "-D" .. macro} end -- make the undefine flag function nf_undefine(self, macro) - return "-Xcc -U" .. macro + return {"-Xcc", "-U" .. macro} end -- make the framework flag function nf_framework(self, framework) - return "-framework" .. framework + return {"-framework", framework} end -- make the link flag diff --git a/xmake/modules/detect/tools/ar/has_flag.lua b/xmake/modules/detect/tools/ar/has_flags.lua index 5358e3e0a..7fcccb25a 100644 --- a/xmake/modules/detect/tools/ar/has_flag.lua +++ b/xmake/modules/detect/tools/ar/has_flags.lua @@ -19,30 +19,35 @@ -- Copyright (C) 2015 - 2017, TBOOX Open Source Group. -- -- @author ruki --- @file has_flag.lua +-- @file has_flags.lua -- -- imports import("lib.detect.cache") -- attempt to check it from the argument list -function _check_from_arglist(flag, opt) +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end -- make cache key - local key = "detect.tools.ar.has_flag" + local key = "detect.tools.ar.has_flags" - -- make flags key + -- make allflags key local flagskey = opt.program .. "_" .. (opt.programver or "") -- load cache local cacheinfo = cache.load(key) - -- get all flags from argument list - local flags = cacheinfo[flagskey] - if not flags then + -- get all allflags from argument list + local allflags = cacheinfo[flagskey] + if not allflags then -- get argument list - flags = {} + allflags = {} local arglist = nil try { @@ -55,30 +60,30 @@ function _check_from_arglist(flag, opt) if arglist then local found = false for arg in arglist:gmatch("%-r %[%-(%a+)%]") do - arg:gsub("%a", function (ch) flags["-" .. ch] = true; flags["-r" .. ch] = true; flags["-" .. ch .. "r"] = true end) + arg:gsub("%a", function (ch) allflags["-" .. ch] = true; allflags["-r" .. ch] = true; allflags["-" .. ch .. "r"] = true end) found = true end if found then - flags["-r"] = true + allflags["-r"] = true end end -- save cache - cacheinfo[flagskey] = flags + cacheinfo[flagskey] = allflags cache.save(key, cacheinfo) end -- ok? - return flags[flag] + return allflags[flags[1]] end --- has_flag(flag)? +-- has_flags(flags)? -- -- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} -- -- @return true or false -- -function main(flag, opt) - return _check_from_arglist(flag, opt) +function main(flags, opt) + return _check_from_arglist(flags, opt) end diff --git a/xmake/modules/detect/tools/cl/has_flag.lua b/xmake/modules/detect/tools/cl/has_flags.lua index 1f6e370e3..3e1b98f63 100644 --- a/xmake/modules/detect/tools/cl/has_flag.lua +++ b/xmake/modules/detect/tools/cl/has_flags.lua @@ -19,58 +19,63 @@ -- Copyright (C) 2015 - 2017, TBOOX Open Source Group. -- -- @author ruki --- @file has_flag.lua +-- @file has_flags.lua -- -- imports import("lib.detect.cache") -- attempt to check it from the argument list -function _check_from_arglist(flag, opt) +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end -- make cache key - local key = "detect.tools.cl.has_flag" + local key = "detect.tools.cl.has_flags" - -- make flags key + -- make allflags key local flagskey = opt.program .. "_" .. (opt.programver or "") -- load cache local cacheinfo = cache.load(key) - -- get all flags from argument list - local flags = cacheinfo[flagskey] - if not flags then + -- get all allflags from argument list + local allflags = cacheinfo[flagskey] + if not allflags then -- get argument list - flags = {} + allflags = {} local arglist = os.iorunv(opt.program, {"-?"}) if arglist then for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do - flags[arg:gsub("/", "-")] = true + allflags[arg:gsub("/", "-")] = true end end -- save cache - cacheinfo[flagskey] = flags + cacheinfo[flagskey] = allflags cache.save(key, cacheinfo) end -- ok? - return flags[flag:gsub("/", "-")] + return allflags[flags[1]:gsub("/", "-")] end --- try running to check flag -function _check_try_running(flag, opt) +-- try running to check flags +function _check_try_running(flags, opt) -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "cl_has_flag.c") + local sourcefile = path.join(os.tmpdir(), "detect", "cl_has_flags.c") if not os.isfile(sourcefile) then io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") end -- check it return try { function () - local _, errors = os.iorunv(opt.program, {"-c", "-nologo", flag, "-Fo" .. os.nuldev(), sourcefile}) + local _, errors = os.iorunv(opt.program, table.join("-c", "-nologo", flags, "-Fo" .. os.nuldev(), sourcefile)) if errors and #errors:trim() > 0 then return false end @@ -79,20 +84,20 @@ function _check_try_running(flag, opt) } end --- has_flag(flag)? +-- has_flags(flags)? -- -- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} -- -- @return true or false -- -function main(flag, opt) +function main(flags, opt) -- attempt to check it from the argument list - if _check_from_arglist(flag, opt) then + if _check_from_arglist(flags, opt) then return true end -- try running to check it - return _check_try_running(flag, opt) + return _check_try_running(flags, opt) end diff --git a/xmake/modules/detect/tools/gdc/has_flag.lua b/xmake/modules/detect/tools/clang/has_flags.lua index 617355673..4afa58610 100644 --- a/xmake/modules/detect/tools/gdc/has_flag.lua +++ b/xmake/modules/detect/tools/clang/has_flags.lua @@ -19,9 +19,9 @@ -- Copyright (C) 2015 - 2017, TBOOX Open Source Group. -- -- @author ruki --- @file has_flag.lua +-- @file has_flags.lua -- -- imports -inherit("detect.tools.dmd.has_flag") +inherit("detect.tools.gcc.has_flags") diff --git a/xmake/modules/detect/tools/clang/has_flag.lua b/xmake/modules/detect/tools/clangxx/has_flags.lua index 0cb83600e..4afa58610 100644 --- a/xmake/modules/detect/tools/clang/has_flag.lua +++ b/xmake/modules/detect/tools/clangxx/has_flags.lua @@ -19,9 +19,9 @@ -- Copyright (C) 2015 - 2017, TBOOX Open Source Group. -- -- @author ruki --- @file has_flag.lua +-- @file has_flags.lua -- -- imports -inherit("detect.tools.gcc.has_flag") +inherit("detect.tools.gcc.has_flags") diff --git a/xmake/modules/detect/tools/dmd/has_flag.lua b/xmake/modules/detect/tools/dmd/has_flags.lua index 719551523..f6ebb2960 100644 --- a/xmake/modules/detect/tools/dmd/has_flag.lua +++ b/xmake/modules/detect/tools/dmd/has_flags.lua @@ -19,17 +19,18 @@ -- Copyright (C) 2015 - 2017, TBOOX Open Source Group. -- -- @author ruki --- @file has_flag.lua +-- @file has_flags.lua -- -- imports import("lib.detect.cache") -- is linker? -function _islinker(flag, opt) +function _islinker(flags, opt) - -- the flag is "-L=<arg>" or "-L<arg>"? - if flag:startswith("-L=") or flag:startswith("-L-") then + -- the flags is "-L=<arg>" or "-L<arg>"? + local flags_str = table.concat(flags, " ") + if flags_str:startswith("-L=") or flags_str:startswith("-L-") then return true end @@ -39,55 +40,55 @@ function _islinker(flag, opt) end -- attempt to check it from the argument list -function _check_from_arglist(flag, opt, islinker) +function _check_from_arglist(flags, opt, islinker) -- only for compiler - if islinker then + if islinker or #flags > 1 then return end -- make cache key - local key = "detect.tools.dmd.has_flag" + local key = "detect.tools.dmd.has_flags" - -- make flags key + -- make allflags key local flagskey = opt.program .. "_" .. (opt.programver or "") -- load cache local cacheinfo = cache.load(key) - -- get all flags from argument list - local flags = cacheinfo[flagskey] - if not flags then + -- get all allflags from argument list + local allflags = cacheinfo[flagskey] + if not allflags then -- get argument list - flags = {} + allflags = {} local arglist = os.iorunv(opt.program, {"--help"}) if arglist then for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - flags[arg] = true + allflags[arg] = true end end -- save cache - cacheinfo[flagskey] = flags + cacheinfo[flagskey] = allflags cache.save(key, cacheinfo) end -- ok? - return flags[flag] + return allflags[flags[1]] end --- try running to check flag -function _check_try_running(flag, opt, islinker) +-- try running to check flags +function _check_try_running(flags, opt, islinker) -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "dmd_has_flag.d") + local sourcefile = path.join(os.tmpdir(), "detect", "dmd_has_flags.d") if not os.isfile(sourcefile) then io.writefile(sourcefile, "void main() {\n}") end -- init argv - local argv = {flag, "-of" .. os.nuldev(), sourcefile} + local argv = table.join(flags, "-of" .. os.nuldev(), sourcefile) if not islinker then table.insert(argv, 1, "-c") end @@ -96,23 +97,23 @@ function _check_try_running(flag, opt, islinker) return try { function () os.runv(opt.program, argv); return true end } end --- has_flag(flag)? +-- has_flags(flags)? -- -- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} -- -- @return true or false -- -function main(flag, opt) +function main(flags, opt) -- is linker? - local islinker = _islinker(flag, opt) + local islinker = _islinker(flags, opt) -- attempt to check it from the argument list - if _check_from_arglist(flag, opt, islinker) then + if _check_from_arglist(flags, opt, islinker) then return true end -- try running to check it - return _check_try_running(flag, opt, islinker) + return _check_try_running(flags, opt, islinker) end diff --git a/xmake/modules/detect/tools/gcc/has_flag.lua b/xmake/modules/detect/tools/gcc/has_flags.lua index a8268f75b..2a02c5424 100644 --- a/xmake/modules/detect/tools/gcc/has_flag.lua +++ b/xmake/modules/detect/tools/gcc/has_flags.lua @@ -19,7 +19,7 @@ -- Copyright (C) 2015 - 2017, TBOOX Open Source Group. -- -- @author ruki --- @file has_flag.lua +-- @file has_flags.lua -- -- imports @@ -27,10 +27,11 @@ import("lib.detect.cache") import("core.language.language") -- is linker? -function _islinker(flag, opt) +function _islinker(flags, opt) - -- the flag is "-Wl,<arg>" or "-Xlinker <arg>"? - if flag:startswith("-Wl,") or flag:startswith("-Xlinker ") then + -- the flags is "-Wl,<arg>" or "-Xlinker <arg>"? + local flags_str = table.concat(flags, " ") + if flags_str:startswith("-Wl,") or flags_str:startswith("-Xlinker ") then return true end @@ -40,15 +41,15 @@ function _islinker(flag, opt) end -- attempt to check it from the argument list -function _check_from_arglist(flag, opt, islinker) +function _check_from_arglist(flags, opt, islinker) -- only for compiler - if islinker then + if islinker or #flags > 1 then return end -- make cache key - local key = "detect.tools.gcc.has_flag" + local key = "detect.tools.gcc.has_flags" -- make flags key local flagskey = opt.program .. "_" .. (opt.programver or "") @@ -57,44 +58,44 @@ function _check_from_arglist(flag, opt, islinker) local cacheinfo = cache.load(key) -- get all flags from argument list - local flags = cacheinfo[flagskey] - if not flags then + local allflags = cacheinfo[flagskey] + if not allflags then -- get argument list - flags = {} + allflags = {} local arglist = os.iorunv(opt.program, {"--help"}) if arglist then for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - flags[arg] = true + allflags[arg] = true end end -- save cache - cacheinfo[flagskey] = flags + cacheinfo[flagskey] = allflags cache.save(key, cacheinfo) end -- ok? - return flags[flag] + return allflags[flags[1]] end --- try running to check flag -function _check_try_running(flag, opt, islinker) +-- try running to check flags +function _check_try_running(flags, opt, islinker) - -- check flag for linker + -- check flags for linker if islinker then -- get extension local extension = table.wrap(language.sourcekinds()[opt.toolkind or "cc"])[1] or ".c" -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "gcc_has_flag" .. extension) + local sourcefile = path.join(os.tmpdir(), "detect", "gcc_has_flags" .. extension) if not os.isfile(sourcefile) then io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") end -- check it - return try { function () os.runv(opt.program, {flag, "-o", os.nuldev(), sourcefile}); return true end } + return try { function () os.runv(opt.program, table.join(flags, "-o", os.nuldev(), sourcefile)); return true end } end -- get language @@ -103,27 +104,27 @@ function _check_try_running(flag, opt, islinker) lang = "c++" end - -- check flag for compiler - return try { function () os.runv(opt.program, {flag, "-S", "-o", os.nuldev(), "-x" .. lang, os.nuldev()}); return true end } + -- check flags for compiler + return try { function () os.runv(opt.program, table.join(flags, "-S", "-o", os.nuldev(), "-x" .. lang, os.nuldev())); return true end } end --- has_flag(flag)? +-- has_flags(flags)? -- -- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"} -- -- @return true or false -- -function main(flag, opt) +function main(flags, opt) -- is linker? - local islinker = _islinker(flag, opt) + local islinker = _islinker(flags, opt) -- attempt to check it from the argument list - if _check_from_arglist(flag, opt, islinker) then + if _check_from_arglist(flags, opt, islinker) then return true end -- try running to check it - return _check_try_running(flag, opt, islinker) + return _check_try_running(flags, opt, islinker) end diff --git a/xmake/modules/detect/tools/clangxx/has_flag.lua b/xmake/modules/detect/tools/gccgo/has_flags.lua index 0cb83600e..4afa58610 100644 --- a/xmake/modules/detect/tools/clangxx/has_flag.lua +++ b/xmake/modules/detect/tools/gccgo/has_flags.lua @@ -19,9 +19,9 @@ -- Copyright (C) 2015 - 2017, TBOOX Open Source Group. -- -- @author ruki --- @file has_flag.lua +-- @file has_flags.lua -- -- imports -inherit("detect.tools.gcc.has_flag") +inherit("detect.tools.gcc.has_flags") diff --git a/xmake/modules/detect/tools/gdc/has_flags.lua b/xmake/modules/detect/tools/gdc/has_flags.lua new file mode 100644 index 000000000..bdc39a1db --- /dev/null +++ b/xmake/modules/detect/tools/gdc/has_flags.lua @@ -0,0 +1,27 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("detect.tools.dmd.has_flags") + diff --git a/xmake/modules/detect/tools/gxx/has_flag.lua b/xmake/modules/detect/tools/gxx/has_flag.lua deleted file mode 100644 index 0cb83600e..000000000 --- a/xmake/modules/detect/tools/gxx/has_flag.lua +++ /dev/null @@ -1,27 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file has_flag.lua --- - --- imports -inherit("detect.tools.gcc.has_flag") - diff --git a/xmake/modules/detect/tools/gxx/has_flags.lua b/xmake/modules/detect/tools/gxx/has_flags.lua new file mode 100644 index 000000000..4afa58610 --- /dev/null +++ b/xmake/modules/detect/tools/gxx/has_flags.lua @@ -0,0 +1,27 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("detect.tools.gcc.has_flags") + diff --git a/xmake/modules/detect/tools/ldc/has_flag.lua b/xmake/modules/detect/tools/ldc/has_flag.lua deleted file mode 100644 index 617355673..000000000 --- a/xmake/modules/detect/tools/ldc/has_flag.lua +++ /dev/null @@ -1,27 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file has_flag.lua --- - --- imports -inherit("detect.tools.dmd.has_flag") - diff --git a/xmake/modules/detect/tools/ldc/has_flags.lua b/xmake/modules/detect/tools/ldc/has_flags.lua new file mode 100644 index 000000000..bdc39a1db --- /dev/null +++ b/xmake/modules/detect/tools/ldc/has_flags.lua @@ -0,0 +1,27 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("detect.tools.dmd.has_flags") + diff --git a/xmake/modules/detect/tools/link/has_flag.lua b/xmake/modules/detect/tools/link/has_flags.lua index 008f28912..01b2ef1dd 100644 --- a/xmake/modules/detect/tools/link/has_flag.lua +++ b/xmake/modules/detect/tools/link/has_flags.lua @@ -19,30 +19,35 @@ -- Copyright (C) 2015 - 2017, TBOOX Open Source Group. -- -- @author ruki --- @file has_flag.lua +-- @file has_flags.lua -- -- imports import("lib.detect.cache") -- attempt to check it from the argument list -function _check_from_arglist(flag, opt) +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end -- make cache key - local key = "detect.tools.link.has_flag" + local key = "detect.tools.link.has_flags" - -- make flags key + -- make allflags key local flagskey = opt.program .. "_" .. (opt.programver or "") -- load cache local cacheinfo = cache.load(key) - -- get all flags from argument list - local flags = cacheinfo[flagskey] - if not flags then + -- get all allflags from argument list + local allflags = cacheinfo[flagskey] + if not allflags then -- get argument list - flags = {} + allflags = {} local arglist = nil try { @@ -54,25 +59,25 @@ function _check_from_arglist(flag, opt) } if arglist then for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do - flags[arg:gsub("/", "-"):lower()] = true + allflags[arg:gsub("/", "-"):lower()] = true end end -- save cache - cacheinfo[flagskey] = flags + cacheinfo[flagskey] = allflags cache.save(key, cacheinfo) end -- ok? - return flags[flag:gsub("/", "-"):lower()] + return allflags[flags[1]:gsub("/", "-"):lower()] end --- try running to check flag -function _check_try_running(flag, opt) +-- try running to check flags +function _check_try_running(flags, opt) -- make an stub source file - local winmain = flag:lower():find("subsystem:windows") - local sourcefile = path.join(os.tmpdir(), "detect", ifelse(winmain, "winmain_", "") .. "link_has_flag.c") + local winmain = flags:lower():find("subsystem:windows") + local sourcefile = path.join(os.tmpdir(), "detect", ifelse(winmain, "winmain_", "") .. "link_has_flags.c") if not os.isfile(sourcefile) then if winmain then io.writefile(sourcefile, "int WinMain(void* instance, void* previnst, char** argv, int argc)\n{return 0;}") @@ -87,7 +92,7 @@ function _check_try_running(flag, opt) os.iorunv("cl", {"-c", "-nologo", "-Fo" .. objectfile, sourcefile}) -- try link it - local ok = try { function () os.execv(opt.program, {flag, "-nologo", "-out:" .. binaryfile, objectfile}); return true end } + local ok = try { function () os.execv(opt.program, table.join(flags, "-nologo", "-out:" .. binaryfile, objectfile)); return true end } -- remove files os.tryrm(objectfile) @@ -97,20 +102,20 @@ function _check_try_running(flag, opt) return ok end --- has_flag(flag)? +-- has_flags(flags)? -- -- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} -- -- @return true or false -- -function main(flag, opt) +function main(flags, opt) -- attempt to check it from the argument list - if _check_from_arglist(flag, opt) then + if _check_from_arglist(flags, opt) then return true end -- try running to check it - return _check_try_running(flag, opt) + return _check_try_running(flags, opt) end diff --git a/xmake/modules/detect/tools/ml/has_flag.lua b/xmake/modules/detect/tools/ml/has_flags.lua index f41561953..809421d5c 100644 --- a/xmake/modules/detect/tools/ml/has_flag.lua +++ b/xmake/modules/detect/tools/ml/has_flags.lua @@ -19,58 +19,63 @@ -- Copyright (C) 2015 - 2017, TBOOX Open Source Group. -- -- @author ruki --- @file has_flag.lua +-- @file has_flags.lua -- -- imports import("lib.detect.cache") -- attempt to check it from the argument list -function _check_from_arglist(flag, opt) +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end -- make cache key - local key = "detect.tools.ml.has_flag" + local key = "detect.tools.ml.has_flags" - -- make flags key + -- make allflags key local flagskey = opt.program .. "_" .. (opt.programver or "") -- load cache local cacheinfo = cache.load(key) - -- get all flags from argument list - local flags = cacheinfo[flagskey] - if not flags then + -- get all allflags from argument list + local allflags = cacheinfo[flagskey] + if not allflags then -- get argument list - flags = {} + allflags = {} local arglist = os.iorunv(opt.program, {"-?"}) if arglist then for arg in arglist:gmatch("(/[%-%a%d]+)%s+") do - flags[arg:gsub("/", "-")] = true + allflags[arg:gsub("/", "-")] = true end end -- save cache - cacheinfo[flagskey] = flags + cacheinfo[flagskey] = allflags cache.save(key, cacheinfo) end -- ok? - return flags[flag:gsub("/", "-")] + return allflags[flags[1]:gsub("/", "-")] end --- try running to check flag -function _check_try_running(flag, opt) +-- try running to check flags +function _check_try_running(flags, opt) -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "ml_has_flag.asm") + local sourcefile = path.join(os.tmpdir(), "detect", "ml_has_flags.asm") if not os.isfile(sourcefile) then io.writefile(sourcefile, ".code\nend") end -- check it return try { function () - local _, errors = os.iorunv(opt.program, {"-c", "-nologo", flag, "-Fo" .. os.nuldev(), sourcefile}) + local _, errors = os.iorunv(opt.program, table.join("-c", "-nologo", flags, "-Fo" .. os.nuldev(), sourcefile)) if errors and #errors:trim() > 0 then return false end @@ -79,20 +84,20 @@ function _check_try_running(flag, opt) } end --- has_flag(flag)? +-- has_flags(flags)? -- -- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} -- -- @return true or false -- -function main(flag, opt) +function main(flags, opt) -- attempt to check it from the argument list - if _check_from_arglist(flag, opt) then + if _check_from_arglist(flags, opt) then return true end -- try running to check it - return _check_try_running(flag, opt) + return _check_try_running(flags, opt) end diff --git a/xmake/modules/detect/tools/ml64/has_flag.lua b/xmake/modules/detect/tools/ml64/has_flag.lua deleted file mode 100644 index c0086f0e7..000000000 --- a/xmake/modules/detect/tools/ml64/has_flag.lua +++ /dev/null @@ -1,27 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015 - 2017, TBOOX Open Source Group. --- --- @author ruki --- @file has_flag.lua --- - --- imports -inherit("detect.tools.ml.has_flag") - diff --git a/xmake/modules/detect/tools/gccgo/has_flag.lua b/xmake/modules/detect/tools/ml64/has_flags.lua index 0cb83600e..761b5036b 100644 --- a/xmake/modules/detect/tools/gccgo/has_flag.lua +++ b/xmake/modules/detect/tools/ml64/has_flags.lua @@ -19,9 +19,9 @@ -- Copyright (C) 2015 - 2017, TBOOX Open Source Group. -- -- @author ruki --- @file has_flag.lua +-- @file has_flags.lua -- -- imports -inherit("detect.tools.gcc.has_flag") +inherit("detect.tools.ml.has_flags") diff --git a/xmake/modules/detect/tools/rustc/has_flag.lua b/xmake/modules/detect/tools/rustc/has_flags.lua index e5766bba8..6c7977c54 100644 --- a/xmake/modules/detect/tools/rustc/has_flag.lua +++ b/xmake/modules/detect/tools/rustc/has_flags.lua @@ -19,58 +19,63 @@ -- Copyright (C) 2015 - 2017, TBOOX Open Source Group. -- -- @author ruki --- @file has_flag.lua +-- @file has_flags.lua -- -- imports import("lib.detect.cache") -- attempt to check it from the argument list -function _check_from_arglist(flag, opt) +function _check_from_arglist(flags, opt) + + -- only one flag? + if #flags > 1 then + return + end -- make cache key - local key = "detect.tools.rustc.has_flag" + local key = "detect.tools.rustc.has_flags" - -- make flags key + -- make allflags key local flagskey = opt.program .. "_" .. (opt.programver or "") -- load cache local cacheinfo = cache.load(key) - -- get all flags from argument list - local flags = cacheinfo[flagskey] - if not flags then + -- get all allflags from argument list + local allflags = cacheinfo[flagskey] + if not allflags then -- get argument list - flags = {} + allflags = {} local arglist = os.iorunv(opt.program, {"--help"}) if arglist then for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do - flags[arg] = true + allflags[arg] = true end end -- save cache - cacheinfo[flagskey] = flags + cacheinfo[flagskey] = allflags cache.save(key, cacheinfo) end -- ok? - return flags[flag] + return allflags[flags[1]] end --- try running to check flag -function _check_try_running(flag, opt) +-- try running to check flags +function _check_try_running(flags, opt) -- make an stub source file - local sourcefile = path.join(os.tmpdir(), "detect", "rustc_has_flag.rs") + local sourcefile = path.join(os.tmpdir(), "detect", "rustc_has_flags.rs") if not os.isfile(sourcefile) then io.writefile(sourcefile, "fn main() {\n}") end -- check it local objectfile = os.tmpfile() .. ".o" - local ok = try { function () os.runv(opt.program, {"--emit", "obj", flag, "-o", objectfile, sourcefile}); return true end } + local ok = try { function () os.runv(opt.program, table.join("--emit", "obj", flags, "-o", objectfile, sourcefile)); return true end } -- remove files os.tryrm(objectfile) @@ -79,20 +84,20 @@ function _check_try_running(flag, opt) return ok end --- has_flag(flag)? +-- has_flags(flags)? -- -- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} -- -- @return true or false -- -function main(flag, opt) +function main(flags, opt) -- attempt to check it from the argument list - if _check_from_arglist(flag, opt) then + if _check_from_arglist(flags, opt) then return true end -- try running to check it - return _check_try_running(flag, opt) + return _check_try_running(flags, opt) end diff --git a/xmake/modules/lib/detect/features.lua b/xmake/modules/lib/detect/features.lua index 26ee9a18b..be1974a20 100644 --- a/xmake/modules/lib/detect/features.lua +++ b/xmake/modules/lib/detect/features.lua @@ -74,7 +74,7 @@ function main(name, opt) return result end - -- detect.tools.xxx.has_flag(flag, opt)? + -- detect.tools.xxx.features(opt)? _g._checking = ifelse(coroutine_running, key, nil) if os.isfile(path.join(os.programdir(), "modules", "detect", "tools", tool.name, "features.lua")) then local features = import("detect.tools." .. tool.name .. ".features") diff --git a/xmake/modules/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua index ef6d1b1d1..47347e5ed 100644 --- a/xmake/modules/lib/detect/has_flags.lua +++ b/xmake/modules/lib/detect/has_flags.lua @@ -26,8 +26,24 @@ import("core.base.option") import("lib.detect.find_tool") --- has this flag? -function _has_flag(name, flag, opt) +-- has the given flags for the current tool? +-- +-- @param name the tool name +-- @param flags the flags +-- @param opt the argument options, .e.g {verbose = false, program = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} +-- +-- @return true or false +-- +-- @code +-- local ok = has_flags("clang", "-g") +-- local ok = has_flags("clang", {"-g", "-O0"}, {program = "xcrun -sdk macosx clang"}) +-- local ok = has_flags("clang", "-g", {toolkind = "cxx"}) +-- @endcode +-- +function main(name, flags, opt) + + -- init options + opt = opt or {} -- find tool program and version first opt.version = true @@ -36,13 +52,16 @@ function _has_flag(name, flag, opt) return false end + -- wrap flags + flags = table.wrap(flags) + -- init tool opt.toolname = tool.name opt.program = tool.program opt.programver = tool.version -- init cache and key - local key = tool.program .. "_" .. (tool.version or "") .. "_" .. (opt.toolkind or "") .. "_" .. flag + local key = tool.program .. "_" .. (tool.version or "") .. "_" .. (opt.toolkind or "") .. "_" .. table.concat(flags, " ") _g._RESULTS = _g._RESULTS or {} local results = _g._RESULTS @@ -60,21 +79,21 @@ function _has_flag(name, flag, opt) return result end - -- detect.tools.xxx.has_flag(flag, opt)? + -- detect.tools.xxx.has_flags(flags, opt)? _g._checking = ifelse(coroutine_running, key, nil) - if os.isfile(path.join(os.programdir(), "modules", "detect", "tools", tool.name, "has_flag.lua")) then - local hasflag = import("detect.tools." .. tool.name .. ".has_flag") - if hasflag then - result = hasflag(flag, opt) + if os.isfile(path.join(os.programdir(), "modules", "detect", "tools", tool.name, "has_flags.lua")) then + local hasflags = import("detect.tools." .. tool.name .. ".has_flags") + if hasflags then + result = hasflags(flags, opt) end else - result = try { function () os.runv(tool.program, {flag}); return true end } + result = try { function () os.runv(tool.program, flags); return true end } end _g._checking = nil -- trace if option.get("verbose") or opt.verbose then - cprint("checking for the flags(%s) %s ... %s", path.filename(tool.program), flag, ifelse(result, "${green}ok", "${red}no")) + cprint("checking for the flags(%s) %s ... %s", path.filename(tool.program), table.concat(flags, " "), ifelse(result, "${green}ok", "${red}no")) end -- save result to cache @@ -84,34 +103,3 @@ function _has_flag(name, flag, opt) return result end --- has the given flags for the current tool? --- --- @param name the tool name --- @param flags the flags --- @param opt the argument options, .e.g {verbose = false, program = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"} --- --- @return the supported flags or nil --- --- @code --- local flags = has_flags("clang", "-g") --- local flags = has_flags("clang", {"-g", "-O0"}, {program = "xcrun -sdk macosx clang"}) --- local flags = has_flags("clang", "-g", {toolkind = "cxx"}) --- @endcode --- -function main(name, flags, opt) - - -- init options - opt = opt or {} - - -- has all flags? - local results = nil - for _, flag in ipairs(flags) do - if _has_flag(name, flag, opt) then - results = results or {} - table.insert(results, flag) - end - end - - -- ok? - return results -end diff --git a/xmake/platforms/android/load.lua b/xmake/platforms/android/load.lua index 0e0d88131..102540e71 100644 --- a/xmake/platforms/android/load.lua +++ b/xmake/platforms/android/load.lua @@ -113,8 +113,8 @@ function main() -- init flags for rust _g.rcflags = { "--target=" .. targets[arch] } - _g["rc-shflags"] = { "-C linker=" .. config.get("sh"), "-C link-args=\"" .. (table.concat(_g.shflags, " "):gsub("%-march=.-%s", "")) .. "\"" } - _g["rc-ldflags"] = { "-C linker=" .. config.get("ld"), "-C link-args=\"" .. (table.concat(_g.ldflags, " "):gsub("%-march=.-%s", "")) .. "\"" } + _g["rc-shflags"] = { "-C", "linker=" .. config.get("sh"), "-C", "link-args=\"" .. (table.concat(_g.shflags, " "):gsub("%-march=.-%s", "")) .. "\"" } + _g["rc-ldflags"] = { "-C", "linker=" .. config.get("ld"), "-C", "link-args=\"" .. (table.concat(_g.ldflags, " "):gsub("%-march=.-%s", "")) .. "\"" } -- ok return _g diff --git a/xmake/platforms/checker.lua b/xmake/platforms/checker.lua index bf6e60b8c..627d257f7 100644 --- a/xmake/platforms/checker.lua +++ b/xmake/platforms/checker.lua @@ -42,7 +42,7 @@ function _toolchain_check(config, toolkind, toolinfo) end -- get cross - local cross = config.get("cross") or toolinfo.cross or "" + local cross = toolinfo.cross or "" -- attempt to check it if not program then diff --git a/xmake/platforms/linux/load.lua b/xmake/platforms/linux/load.lua index 003b31909..d71d22198 100644 --- a/xmake/platforms/linux/load.lua +++ b/xmake/platforms/linux/load.lua @@ -48,20 +48,20 @@ function main() if arch then if arch == "x86_64" then archflags = "-m64" elseif arch == "i386" then archflags = "-m32" - else archflags = "-arch " .. arch + else archflags = {"-arch", arch} end end -- init flags for c/c++ - _g.cxflags = { archflags, "-I/usr/local/include", "-I/usr/include" } - _g.ldflags = { archflags, "-L/usr/local/lib", "-L/usr/lib" } - _g.shflags = { archflags, "-L/usr/local/lib", "-L/usr/lib" } + _g.cxflags = table.join(table.wrap(archflags), "-I/usr/local/include", "-I/usr/include") + _g.ldflags = table.join(table.wrap(archflags), "-L/usr/local/lib", "-L/usr/lib") + _g.shflags = table.join(table.wrap(archflags), "-L/usr/local/lib", "-L/usr/lib") -- init flags for objc/c++ (with _g.ldflags and _g.shflags) - _g.mxflags = { archflags } + _g.mxflags = table.wrap(archflags) -- init flags for asm (with _g.ldflags and _g.shflags) - _g.asflags = { archflags } + _g.asflags = table.wrap(archflags) -- init flags for golang _g["gc-ldflags"] = {} diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua index 2b57222f9..aa85a92ee 100644 --- a/xmake/platforms/macosx/load.lua +++ b/xmake/platforms/macosx/load.lua @@ -38,20 +38,20 @@ function main() local xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" -- init flags for c/c++ - _g.cxflags = { "-arch " .. arch, "-fpascal-strings", "-fmessage-length=0", "-isysroot " .. xcode_sdkdir, "-I/usr/local/include", "-I/usr/include" } - _g.ldflags = { "-arch " .. arch, "-mmacosx-version-min=" .. target_minver, "-isysroot " .. xcode_sdkdir, "-L/usr/local/lib", "-L/usr/lib", "-stdlib=libc++", "-lz" } - _g.shflags = { "-arch " .. arch, "-mmacosx-version-min=" .. target_minver, "-isysroot " .. xcode_sdkdir, "-L/usr/local/lib", "-L/usr/lib", "-stdlib=libc++", "-lz" } + _g.cxflags = { "-arch", arch, "-fpascal-strings", "-fmessage-length=0", "-isysroot", xcode_sdkdir, "-I/usr/local/include", "-I/usr/include" } + _g.ldflags = { "-arch", arch, "-mmacosx-version-min=" .. target_minver, "-isysroot", xcode_sdkdir, "-L/usr/local/lib", "-L/usr/lib", "-stdlib=libc++", "-lz" } + _g.shflags = { "-arch", arch, "-mmacosx-version-min=" .. target_minver, "-isysroot", xcode_sdkdir, "-L/usr/local/lib", "-L/usr/lib", "-stdlib=libc++", "-lz" } -- init flags for objc/c++ (with _g.ldflags and _g.shflags) - _g.mxflags = { "-arch " .. arch, "-fpascal-strings", "-fmessage-length=0", "-isysroot " .. xcode_sdkdir } + _g.mxflags = { "-arch", arch, "-fpascal-strings", "-fmessage-length=0", "-isysroot " .. xcode_sdkdir } -- init flags for asm (with _g.ldflags and _g.shflags) - _g.asflags = { "-arch " .. arch, "-isysroot " .. xcode_sdkdir } + _g.asflags = { "-arch", arch, "-isysroot", xcode_sdkdir } -- init flags for swift - _g.scflags = { format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } - _g["sc-shflags"] = { format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } - _g["sc-ldflags"] = { format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } + _g.scflags = { "-target", format("%s-apple-macosx%s", arch, target_minver) , "-sdk", xcode_sdkdir } + _g["sc-shflags"] = { "-target", format("%s-apple-macosx%s", arch, target_minver) , "-sdk", xcode_sdkdir } + _g["sc-ldflags"] = { "-target", format("%s-apple-macosx%s", arch, target_minver) , "-sdk", xcode_sdkdir } -- init flags for golang _g["gc-ldflags"] = {} |
