diff options
| author | ruki <[email protected]> | 2015-06-05 17:04:07 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-05 17:04:07 +0800 |
| commit | 6222a6ede3f06a0c67eccf0225d0ffb88cf9d4c8 (patch) | |
| tree | 84bd3b55fa14113db97f956faecfff424688222e | |
| parent | 411e3138ec53ab99c73f0124ef93ac98d746cdc9 (diff) | |
add optimize flags
| -rw-r--r-- | xmake/scripts/base/compiler.lua | 69 | ||||
| -rw-r--r-- | xmake/scripts/base/linker.lua | 46 | ||||
| -rw-r--r-- | xmake/scripts/platform/windows/tools/cl.lua | 16 | ||||
| -rw-r--r-- | xmake/scripts/platform/windows/tools/link.lua | 7 | ||||
| -rw-r--r-- | xmake/scripts/tools/ar.lua | 7 | ||||
| -rw-r--r-- | xmake/scripts/tools/clang.lua | 7 |
6 files changed, 103 insertions, 49 deletions
diff --git a/xmake/scripts/base/compiler.lua b/xmake/scripts/base/compiler.lua index 3db08581a..af18758a5 100644 --- a/xmake/scripts/base/compiler.lua +++ b/xmake/scripts/base/compiler.lua @@ -31,14 +31,40 @@ local string = require("base/string") local config = require("base/config") local tools = require("tools/tools") +-- map gcc flag to the given compiler flag +function compiler._mapflag(module, flag) + + -- check + assert(module.mapflags and flag) + + -- attempt to map it directly + local flag_mapped = module.mapflags[flag] + if flag_mapped and type(flag_mapped) == "string" then + return flag_mapped + end + + -- find and replace it using pattern + for k, v in pairs(module.mapflags) do + if flag:find(k) then + return flag:gsub(k, v) + end + end + + -- return it directly + return flag +end + -- map gcc flags to the given compiler flags function compiler._mapflags(module, flags) -- check - assert(module and flags) + assert(module) + + -- wrap flags first + flags = utils.wrap(flags) -- need not map flags? return it directly - if not module.mapflag then + if not module.mapflags then return flags end @@ -46,14 +72,32 @@ function compiler._mapflags(module, flags) local flags_mapped = {} for _, flag in pairs(flags) do -- map it - local flag_mapped = module.flag_map(flag) + local flag_mapped = compiler._mapflag(module, flag) if flag_mapped then table.insert(flags_mapped, flag_mapped) end end -- ok? - return flag_mapped + return flags_mapped +end + +-- get the compiler optimize flags from name +function compiler._flag_optimize(module, name) + + -- init the flags table + local flags = + { + none = "-O0" + , fast = "-O1" + , faster = "-O2" + , fastest = "-O3" + , smallest = "-Os" + , aggressive = "-Ofast" + } + + -- get it + return compiler._mapflags(module, flags[name]) end -- get the compiler name from the source file type @@ -129,18 +173,21 @@ function compiler.make(module, target, srcfile, objfile) return end - -- get the common flags from the current compiler + -- append the common flags from the current compiler local flags = {} for _, flag_name in ipairs(flag_names) do table.join2(flags, module[flag_name]) end - -- get the target flags from the current project + -- append the target flags from the current project for _, flag_name in ipairs(flag_names) do - table.join2(flags, compiler._mapflags(module, utils.wrap(target[flag_name]))) + table.join2(flags, compiler._mapflags(module, target[flag_name])) end - -- get the includedirs flags from the current project + -- append the optimize flags from the current project + table.join2(flags, compiler._flag_optimize(module, target.optimize)) + + -- append the includedirs flags from the current project if module._make_includedir then local includedirs = utils.wrap(target.includedirs) for _, includedir in ipairs(includedirs) do @@ -148,7 +195,7 @@ function compiler.make(module, target, srcfile, objfile) end end - -- get the defines flags from the current project + -- append the defines flags from the current project if module._make_define then local defines = utils.wrap(target.defines) for _, define in ipairs(defines) do @@ -156,9 +203,9 @@ function compiler.make(module, target, srcfile, objfile) end end - -- get the config flags + -- append the flags from the configure for _, flag_name in ipairs(flag_names) do - table.join2(flags, compiler._mapflags(module, utils.wrap(config.get(flag_name)))) + table.join2(flags, compiler._mapflags(module, config.get(flag_name))) end -- make the compile command diff --git a/xmake/scripts/base/linker.lua b/xmake/scripts/base/linker.lua index 6f3e7c972..5cf83964c 100644 --- a/xmake/scripts/base/linker.lua +++ b/xmake/scripts/base/linker.lua @@ -30,14 +30,40 @@ local string = require("base/string") local config = require("base/config") local tools = require("tools/tools") +-- map gcc flag to the given linker flag +function linker._mapflag(module, flag) + + -- check + assert(module.mapflags and flag) + + -- attempt to map it directly + local flag_mapped = module.mapflags[flag] + if flag_mapped and type(flag_mapped) == "string" then + return flag_mapped + end + + -- find and replace it using pattern + for k, v in pairs(module.mapflags) do + if flag:find(k) then + return flag:gsub(k, v) + end + end + + -- return it directly + return flag +end + -- map gcc flags to the given linker flags function linker._mapflags(module, flags) -- check - assert(module and flags); + assert(module) + + -- wrap flags first + flags = utils.wrap(flags) -- need not map flags? return it directly - if not module.mapflag then + if not module.mapflags then return flags end @@ -45,7 +71,7 @@ function linker._mapflags(module, flags) local flags_mapped = {} for _, flag in pairs(flags) do -- map it - local flag_mapped = module.flag_map(flag) + local flag_mapped = linker._mapflag(module, flag) if flag_mapped then table.insert(flags_mapped, flag_mapped) end @@ -75,14 +101,14 @@ function linker.make(module, target, objfiles, targetfile) return end - -- get the common flags from the current linker + -- append the common flags from the current linker local flags = {} table.join2(flags, module[flag_name]) - -- get the target flags from the current project - table.join2(flags, linker._mapflags(module, utils.wrap(target[flag_name]))) + -- append the target flags from the current project + table.join2(flags, linker._mapflags(module, target[flag_name])) - -- get the linkdirs flags from the current project + -- append the linkdirs flags from the current project if module._make_linkdir then local linkdirs = utils.wrap(target.linkdirs) for _, linkdir in ipairs(linkdirs) do @@ -90,7 +116,7 @@ function linker.make(module, target, objfiles, targetfile) end end - -- get the links flags from the current project + -- append the links flags from the current project if module._make_link then local links = utils.wrap(target.links) for _, link in ipairs(links) do @@ -98,8 +124,8 @@ function linker.make(module, target, objfiles, targetfile) end end - -- get the config flags - table.join2(flags, linker._mapflags(module, utils.wrap(config.get(flag_name)))) + -- append the flags from the configure + table.join2(flags, linker._mapflags(module, config.get(flag_name))) -- make the link command return module.command_link(table.concat(objfiles, " "), targetfile, table.concat(flags, " "):trim()) diff --git a/xmake/scripts/platform/windows/tools/cl.lua b/xmake/scripts/platform/windows/tools/cl.lua index 24c45bec3..9feda6e98 100644 --- a/xmake/scripts/platform/windows/tools/cl.lua +++ b/xmake/scripts/platform/windows/tools/cl.lua @@ -37,6 +37,15 @@ function cl.init(name) -- init cxxflags cl.cxxflags = { "-nologo" } + -- init flags map + cl.mapflags = + { + ["-O0"] = "-Od" + , ["-O3"] = "-Ot" + , ["-Ofast"] = "-Ox" + , ["-fomit-frame-pointer"] = "-Oy" + } + end -- make the compiler command @@ -60,13 +69,6 @@ function cl.flag_includedir(includedir) return "-I" .. includedir end --- map gcc flag to the current compiler flag -function cl.flag_map(flag) - - -- ok - return flag -end - -- the main function function cl.main(...) diff --git a/xmake/scripts/platform/windows/tools/link.lua b/xmake/scripts/platform/windows/tools/link.lua index 5ccd8945e..e08d314a7 100644 --- a/xmake/scripts/platform/windows/tools/link.lua +++ b/xmake/scripts/platform/windows/tools/link.lua @@ -77,13 +77,6 @@ function link.flag_linkdir(linkdir) return "-libpath:" .. linkdir end --- map gcc flag to the current compiler flag -function link.flag_map(flag) - - -- ok - return flag -end - -- the main function function link.main(...) diff --git a/xmake/scripts/tools/ar.lua b/xmake/scripts/tools/ar.lua index 008aba7b6..1fec6b373 100644 --- a/xmake/scripts/tools/ar.lua +++ b/xmake/scripts/tools/ar.lua @@ -46,13 +46,6 @@ function ar.command_link(objfiles, targetfile, flags) return string.format("%s %s %s %s", ar.name, flags, targetfile, objfiles) end --- map gcc flag to the current linker flag -function ar.flag_map(flag) - - -- ok - return flag -end - -- the main function function ar.main(...) diff --git a/xmake/scripts/tools/clang.lua b/xmake/scripts/tools/clang.lua index d8fdbaf4b..b8c6cbdeb 100644 --- a/xmake/scripts/tools/clang.lua +++ b/xmake/scripts/tools/clang.lua @@ -118,13 +118,6 @@ function clang.flag_linkdir(linkdir) return "-L" .. linkdir end --- map gcc flag to the current compiler flag -function clang.flag_map(flag) - - -- ok - return flag -end - -- the main function function clang.main(...) |
