diff options
| author | ruki <[email protected]> | 2016-07-24 21:19:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-07-24 21:20:22 +0800 |
| commit | ac2b15dd34b40f1cf24d91856192b26cd772686e (patch) | |
| tree | 0c563362dc57bbd6596f99ba48767acf7b63e511 | |
| parent | 1c42c1e90812ea0da1153f193ea2ce061536187e (diff) | |
add some flag interfaces for compilers
| -rw-r--r-- | xmake/core/tool/archiver.lua | 26 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 108 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 26 | ||||
| -rwxr-xr-x | xmake/platforms/windows/xmake.lua | 1 | ||||
| -rw-r--r-- | xmake/tools/ar.lua | 14 | ||||
| -rwxr-xr-x | xmake/tools/cl.lua | 90 | ||||
| -rwxr-xr-x | xmake/tools/gcc.lua | 122 | ||||
| -rwxr-xr-x | xmake/tools/link.lua | 5 | ||||
| -rw-r--r-- | xmake/tools/swiftc.lua | 73 |
9 files changed, 373 insertions, 92 deletions
diff --git a/xmake/core/tool/archiver.lua b/xmake/core/tool/archiver.lua index 2b539ca33..50cee5c65 100644 --- a/xmake/core/tool/archiver.lua +++ b/xmake/core/tool/archiver.lua @@ -144,19 +144,6 @@ function archiver:_mapflags(flags) return results end --- get the named flags -function archiver:_named_flags(names, flags) - - -- map it - local flags_mapped = {} - for _, name in ipairs(table.wrap(names)) do - table.join2(flags_mapped, self:_mapflags(flags[name])) - end - - -- get it - return flags_mapped -end - -- add flags from the configure function archiver:_addflags_from_config(flags) @@ -171,9 +158,9 @@ function archiver:_addflags_from_target(flags, target) table.join2(flags, self:_mapflags(target:get(self:_flagname()))) -- add the strip flags - table.join2(flags, self:_named_flags(target:get("strip"), { debug = "-S" - , all = "-s" - })) + for _, strip in ipairs(table.wrap(target:get("strip"))) do + table.join2(flags, self:strip(strip)) + end end -- add flags from the platform @@ -253,6 +240,13 @@ function archiver:archivecmd(objectfiles, targetfile, target) return self:_tool().archivecmd(table.concat(table.wrap(objectfiles), " "), targetfile, flags or "") end +-- make the strip flag +function archiver:strip(level) + + -- make it + return self:_tool().strip(level) +end + -- check the given flags function archiver:check(flags) diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 1f983b60a..5125aecea 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -144,19 +144,6 @@ function compiler:_mapflags(flags) return results end --- get the named flags -function compiler:_named_flags(names, flags) - - -- map it - local flags_mapped = {} - for _, name in ipairs(table.wrap(names)) do - table.join2(flags_mapped, self:_mapflags(flags[name])) - end - - -- get it - return flags_mapped -end - -- add flags from the configure function compiler:_addflags_from_config(flags) @@ -174,62 +161,28 @@ function compiler:_addflags_from_target(flags, target) table.join2(flags, self:_mapflags(target:get(flagname))) end - -- add the symbols flags - table.join2(flags, self:_named_flags(target:get("symbols"), { debug = "-g" - , hidden = "-fvisibility=hidden" - })) + -- add the symbol flags + for _, symbol in ipairs(table.wrap(target:get("symbols"))) do + table.join2(flags, self:symbol(symbol)) + end -- add the warning flags - table.join2(flags, self:_named_flags(target:get("warnings"), { none = "-w" - , less = "-W1" - , more = "-W3" - , all = "-Wall" - , error = "-Werror" - })) + 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:_named_flags(target:get("optimize"), { none = "-O0" - , fast = "-O1" - , faster = "-O2" - , fastest = "-O3" - , smallest = "-Os" - , aggressive = "-Ofast" - })) + table.join2(flags, self:optimize(target:get("optimize") or "")) -- add the vector extensions flags - table.join2(flags, self:_named_flags(target:get("vectorexts"), { mmx = "-mmmx" - , sse = "-msse" - , sse2 = "-msse2" - , sse3 = "-msse3" - , ssse3 = "-mssse3" - , avx = "-mavx" - , avx2 = "-mavx2" - , neon = "-mfpu=neon" - })) + for _, vectorext in ipairs(table.wrap(target:get("vectorexts"))) do + table.join2(flags, self:vectorext(vectorext)) + end -- add the language flags - local languages = {} - for _, flagname in ipairs(self:_flagnames()) do - if flagname == "cflags" or flagname == "mflags" then - table.join2(languages, { ansi = "-ansi" - , c89 = "-std=c89" - , gnu89 = "-std=gnu89" - , c99 = "-std=c99" - , gnu99 = "-std=gnu99" - , c11 = "-std=c11" - , gnu11 = "-std=gnu11" - }) - elseif flagname == "cxxflags" or flagname == "mxxflags" then - table.join2(languages, { cxx98 = "-std=c++98" - , gnuxx98 = "-std=gnu++98" - , cxx11 = "-std=c++11" - , gnuxx11 = "-std=gnu++11" - , cxx14 = "-std=c++14" - , gnuxx14 = "-std=gnu++14" - }) - end + for _, language in ipairs(table.wrap(target:get("languages"))) do + table.join2(flags, self:language(language)) end - table.join2(flags, self:_named_flags(target:get("languages"), languages)) -- add the includedirs flags for _, includedir in ipairs(table.wrap(target:get("includedirs"))) do @@ -425,6 +378,41 @@ function compiler:compcmd(sourcefile, objectfile, target) return self:_tool().compcmd(sourcefile, objectfile, flags or "") end +-- make the symbol flag +function compiler:symbol(level) + + -- make it + return self:_tool().symbol(level) +end + +-- make the language flag +function compiler:language(stdname) + + -- make it + return self:_tool().language(stdname) +end + +-- make the vector extension flag +function compiler:vectorext(extension) + + -- make it + return self:_tool().vectorext(extension) +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) diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index 5d01bd3cd..c464a4cdf 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -162,19 +162,6 @@ function linker:_mapflags(flags) return results end --- get the named flags -function linker:_named_flags(names, flags) - - -- map it - local flags_mapped = {} - for _, name in ipairs(table.wrap(names)) do - table.join2(flags_mapped, self:_mapflags(flags[name])) - end - - -- get it - return flags_mapped -end - -- add flags from the configure function linker:_addflags_from_config(flags) @@ -220,9 +207,9 @@ function linker:_addflags_from_target(flags, target) end -- add the strip flags - table.join2(flags, self:_named_flags(target:get("strip"), { debug = "-S" - , all = "-s" - })) + for _, strip in ipairs(table.wrap(target:get("strip"))) do + table.join2(flags, self:strip(strip)) + end end -- add flags from the platform @@ -357,6 +344,13 @@ function linker:linkcmd(objectfiles, targetfile, target) return self:_tool().linkcmd(table.concat(table.wrap(objectfiles), " "), targetfile, flags or "") end +-- make the strip flag +function linker:strip(level) + + -- make it + return self:_tool().strip(level) +end + -- make the linklib flag function linker:linklib(lib) diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 54b8294d3..9b8fbab26 100755 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -50,6 +50,7 @@ platform("windows") _g.formats.object = {"", ".obj"} _g.formats.shared = {"", ".dll"} _g.formats.binary = {"", ".exe"} + _g.formats.symbol = {"", ".pdb"} end) diff --git a/xmake/tools/ar.lua b/xmake/tools/ar.lua index a1cf5522d..d7d37acbc 100644 --- a/xmake/tools/ar.lua +++ b/xmake/tools/ar.lua @@ -44,6 +44,20 @@ function get(name) return _g[name] end +-- make the strip flag +function strip(level) + + -- the maps + local maps = + { + debug = "-S" + , all = "-s" + } + + -- make it + return maps[level] or "" +end + -- make the archive command function archivecmd(objectfiles, targetfile, flags) diff --git a/xmake/tools/cl.lua b/xmake/tools/cl.lua index ba2e7291a..9a6847398 100755 --- a/xmake/tools/cl.lua +++ b/xmake/tools/cl.lua @@ -86,6 +86,96 @@ function get(name) return _g[name] end +-- make the symbol flag +function symbol(level) + + -- the maps + local maps = + { + debug = "-Z7" + } + + -- make it + return maps[level] or "" +end + +-- make the warning flag +function warning(level) + + -- the maps + local maps = + { + none = "-w" + , less = "-W1" + , more = "-W3" + , all = "-W3" + , error = "-WX" + } + + -- make it + return maps[level] or "" +end + +-- make the optimize flag +function optimize(level) + + -- the maps + local maps = + { + none = "-Od" + , fast = "-O1" + , faster = "-O2" + , fastest = "-Ot" + , smallest = "-Os" + , aggressive = "-Ox" + } + + -- make it + return maps[level] or "" +end + +-- make the vector extension flag +function vectorext(extension) + + -- the maps + local maps = + { + mmx = "-arch:MMX" + , sse = "-arch:SSE" + , sse2 = "-arch:SSE2" + , sse3 = "-arch:SSE3" + , ssse3 = "-arch:SSSE3" + , avx = "-arch:AVX" + , avx2 = "-arch:AVX2" + } + + -- make it + return maps[extension] or "" +end + +-- make the language flag +function language(stdname) + + -- the stdc maps + local cmaps = + { + -- stdc + c99 = "-TP" -- compile as c++ files because msvc only support c89 + , gnu99 = "-TP" + , c11 = "-TP" + , gnu11 = "-TP" + } + + -- select maps + local maps = cmaps + if _g.kind == "cxx" or _g.kind == "mxx" then + maps = {} + end + + -- make it + return maps[stdname] or "" +end + -- make the define flag function define(macro) diff --git a/xmake/tools/gcc.lua b/xmake/tools/gcc.lua index 54170a9a0..beb4a154e 100755 --- a/xmake/tools/gcc.lua +++ b/xmake/tools/gcc.lua @@ -71,6 +71,128 @@ function get(name) return _g[name] end +-- make the strip flag +function strip(level) + + -- the maps + local maps = + { + debug = "-S" + , all = "-s" + } + + -- make it + return maps[level] or "" +end + +-- make the symbol flag +function symbol(level) + + -- the maps + local maps = + { + debug = "-g" + , hidden = "-fvisibility=hidden" + } + + -- make it + return maps[level] or "" +end + +-- make the warning flag +function warning(level) + + -- the maps + local maps = + { + none = "-w" + , less = "-W1" + , more = "-W3" + , all = "-Wall" + , error = "-Werror" + } + + -- make it + return maps[level] or "" +end + +-- make the optimize flag +function optimize(level) + + -- the maps + local maps = + { + none = "-O0" + , fast = "-O1" + , faster = "-O2" + , fastest = "-O3" + , smallest = "-Os" + , aggressive = "-Ofast" + } + + -- make it + return maps[level] or "" +end + +-- make the vector extension flag +function vectorext(extension) + + -- the maps + local maps = + { + mmx = "-mmmx" + , sse = "-msse" + , sse2 = "-msse2" + , sse3 = "-msse3" + , ssse3 = "-mssse3" + , avx = "-mavx" + , avx2 = "-mavx2" + , neon = "-mfpu=neon" + } + + -- make it + return maps[extension] or "" +end + +-- make the language flag +function language(stdname) + + -- the stdc maps + local cmaps = + { + -- stdc + ansi = "-ansi" + , c89 = "-std=c89" + , gnu89 = "-std=gnu89" + , c99 = "-std=c99" + , gnu99 = "-std=gnu99" + , c11 = "-std=c11" + , gnu11 = "-std=gnu11" + } + + -- the stdc++ maps + local cxxmaps = + { + cxx98 = "-std=c++98" + , gnuxx98 = "-std=gnu++98" + , cxx11 = "-std=c++11" + , gnuxx11 = "-std=gnu++11" + , cxx14 = "-std=c++14" + , gnuxx14 = "-std=gnu++14" + } + + -- select maps + local maps = cmaps + if _g.kind == "cxx" or _g.kind == "mxx" then + maps = cxxmaps + elseif _g.kind == "sc" then + maps = {} + end + + -- make it + return maps[stdname] or "" +end + -- make the define flag function define(macro) diff --git a/xmake/tools/link.lua b/xmake/tools/link.lua index 68b2ee9d1..c15b53616 100755 --- a/xmake/tools/link.lua +++ b/xmake/tools/link.lua @@ -69,6 +69,11 @@ function get(name) return _g[name] end +-- make the strip flag +function strip(level) + return "" +end + -- make the linklib flag function linklib(lib) diff --git a/xmake/tools/swiftc.lua b/xmake/tools/swiftc.lua index 92b7ecaed..596ea1801 100644 --- a/xmake/tools/swiftc.lua +++ b/xmake/tools/swiftc.lua @@ -74,6 +74,79 @@ function get(name) return _g[name] end +-- make the symbol flag +function symbol(level) + + -- the maps + local maps = + { + debug = "-g" + } + + -- make it + return maps[level] or "" +end + +-- make the warning flag +function warning(level) + + -- the maps + local maps = + { + none = "-w" + , less = "-W1" + , more = "-W3" + , all = "-Wall" + , error = "-Werror" + } + + -- make it + return maps[level] or "" +end + +-- make the optimize flag +function optimize(level) + + -- the maps + local maps = + { + none = "-Onone" + , fast = "-O" + , faster = "-O" + , fastest = "-O" + , smallest = "-O" + , aggressive = "-Ounchecked" + } + + -- make it + return maps[level] or "" +end + +-- make the vector extension flag +function vectorext(extension) + + -- the maps + local maps = + { + mmx = "-mmmx" + , sse = "-msse" + , sse2 = "-msse2" + , sse3 = "-msse3" + , ssse3 = "-mssse3" + , avx = "-mavx" + , avx2 = "-mavx2" + , neon = "-mfpu=neon" + } + + -- make it + return maps[extension] or "" +end + +-- make the language flag +function language(stdname) + return "" +end + -- make the compile command function compcmd(sourcefile, objectfile, flags) |
