diff options
| author | ruki <[email protected]> | 2017-07-13 10:52:42 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-07-13 10:52:42 +0800 |
| commit | b7ae88c507b9afe89cd677ee81894e44a961a4b4 (patch) | |
| tree | a8aca817b422ca83f76d8310678351eaa3f3cf75 | |
| parent | b9e5a411e38224db1f71a39cad57cc54dc13fee6 (diff) | |
improve flags for linker and compiler
| -rw-r--r-- | xmake/core/tool/builder.lua | 2 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 20 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 20 | ||||
| -rw-r--r-- | xmake/modules/core/tools/cl.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/core/tools/dmd.lua | 16 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/core/tools/go.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/core/tools/link.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/core/tools/rustc.lua | 16 | ||||
| -rw-r--r-- | xmake/modules/core/tools/swiftc.lua | 14 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/has_flags.lua | 14 | ||||
| -rw-r--r-- | xmake/platforms/android/load.lua | 4 | ||||
| -rw-r--r-- | xmake/platforms/iphoneos/load.lua | 17 | ||||
| -rw-r--r-- | xmake/platforms/linux/load.lua | 13 | ||||
| -rw-r--r-- | xmake/platforms/macosx/load.lua | 17 | ||||
| -rw-r--r-- | xmake/platforms/mingw/load.lua | 11 | ||||
| -rw-r--r-- | xmake/platforms/watchos/load.lua | 17 |
17 files changed, 119 insertions, 80 deletions
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index f66ad811e..e855dcfea 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -125,8 +125,6 @@ end -- add flags from the configure function builder:_addflags_from_config(flags) - - -- done for _, flagkind in ipairs(self:_flagkinds()) do table.join2(flags, config.get(flagkind)) end diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 3aad4c642..00d05fa6c 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -254,13 +254,29 @@ function compiler:compflags(opt) -- add flags from the compiler self:_addflags_from_compiler(flags, targetkind) + -- remove repeat + flags = table.unique(flags) + + -- split flag group, .e.g "-I /xxx" => {"-I", "/xxx"} + local results = {} + for _, flag in ipairs(flags) do + flag = flag:trim() + if #flag > 0 then + if flag:find(" ", 1, true) then + table.join2(results, os.argv(flag)) + else + table.insert(results, flag) + end + end + end + -- save flags if key then - self._FLAGS[key] = flags + self._FLAGS[key] = results end -- get it - return flags + return results end -- return module diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index b63e64d73..fa84819a7 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -256,13 +256,29 @@ function linker:linkflags(opt) -- add flags from the linker self:_addflags_from_linker(flags) + -- remove repeat + flags = table.unique(flags) + + -- split flag group, .e.g "-I /xxx" => {"-I", "/xxx"} + local results = {} + for _, flag in ipairs(flags) do + flag = flag:trim() + if #flag > 0 then + if flag:find(" ", 1, true) then + table.join2(results, os.argv(flag)) + else + table.insert(results, flag) + end + end + end + -- save flags if key then - self._FLAGS[key] = flags + self._FLAGS[key] = results end -- get it - return flags + return results end -- return module diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 0fa1ab65d..542469c5b 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -39,7 +39,7 @@ function init(self) , ["-O1"] = "" , ["-Os"] = "-O1" , ["-O3"] = "-Ox" - , ["-Ofast"] = {"-Ox", "-fp:fast"} + , ["-Ofast"] = "-Ox -fp:fast" , ["-fomit-frame-pointer"] = "-Oy" -- symbols @@ -97,9 +97,9 @@ function nf_symbol(self, level, target) local flags = nil if level == "debug" then if target and target.symbolfile then - flags = {"-ZI", "-Fd" .. target:symbolfile()} + flags = "-ZI -Fd" .. target:symbolfile() if self:has_flags({"-ZI", "-FS", "-Fd" .. os.tmpfile() .. ".pdb"}) then - table.insert(flags, 1, "-FS") + flags = "-FS " .. flags end else flags = "-ZI" @@ -135,9 +135,9 @@ function nf_optimize(self, level) { none = "-Od" , faster = "-Ox" - , fastest = {"-Ox", "-fp:fast"} + , fastest = "-Ox -fp:fast" , smallest = "-O1" - , aggressive = {"-Ox", "-fp:fast"} + , aggressive = "-Ox -fp:fast" } -- make it diff --git a/xmake/modules/core/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua index 03855e4f3..ed30223cc 100644 --- a/xmake/modules/core/tools/dmd.lua +++ b/xmake/modules/core/tools/dmd.lua @@ -58,11 +58,11 @@ function nf_optimize(self, level) -- the maps local maps = { - 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 @@ -89,7 +89,7 @@ function nf_symbol(self, level) -- the maps local maps = { - debug = {"-g", "-debug"} + debug = "-g -debug" } -- make it @@ -104,8 +104,8 @@ function nf_warning(self, level) { none = "-d" , less = "-w" - , more = {"-w", "-wi"} - , all = {"-w", "-wi"} + , more = "-w -wi" + , all = "-w -wi" , error = "-de" } diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index e952f8eb8..ef91c81e6 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -240,7 +240,7 @@ end -- make the framework flag function nf_framework(self, framework) - return {"-framework", framework} + return "-framework " .. framework end -- make the link arguments list diff --git a/xmake/modules/core/tools/go.lua b/xmake/modules/core/tools/go.lua index cb597652f..47630f291 100644 --- a/xmake/modules/core/tools/go.lua +++ b/xmake/modules/core/tools/go.lua @@ -96,12 +96,12 @@ 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 arguments list diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua index a193d2609..b5161bc2c 100644 --- a/xmake/modules/core/tools/link.lua +++ b/xmake/modules/core/tools/link.lua @@ -74,7 +74,7 @@ function nf_symbol(self, level, target) local targetkind = target:get("kind") if level == "debug" and (targetkind == "binary" or targetkind == "shared") then if target and target.symbolfile then - flags = {"-debug", "-pdb:" .. target:symbolfile()} + flags = "-debug -pdb:" .. target:symbolfile() else flags = "-debug" end diff --git a/xmake/modules/core/tools/rustc.lua b/xmake/modules/core/tools/rustc.lua index f82dcf006..6e102f69d 100644 --- a/xmake/modules/core/tools/rustc.lua +++ b/xmake/modules/core/tools/rustc.lua @@ -64,12 +64,12 @@ 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 @@ -82,7 +82,7 @@ function nf_symbol(self, level) -- the maps local maps = { - debug = {"-C", "debuginfo=2"} + debug = "-C debuginfo=2" } -- make it @@ -91,7 +91,7 @@ end -- make the linkdir flag function nf_linkdir(self, dir) - return {"-L", dir} + return "-L" .. dir end -- make the build arguments list diff --git a/xmake/modules/core/tools/swiftc.lua b/xmake/modules/core/tools/swiftc.lua index cfe97a0c3..4ce63567c 100644 --- a/xmake/modules/core/tools/swiftc.lua +++ b/xmake/modules/core/tools/swiftc.lua @@ -74,8 +74,8 @@ function nf_strip(self, level) -- the maps local maps = { - debug = {"-Xlinker", "-S"} - , all = {"-Xlinker", "-s"} + debug = "-Xlinker -S" + , all = "-Xlinker -s" } -- make it @@ -147,27 +147,27 @@ function nf_vectorext(self, extension) } -- make it - return maps[extension] or "" + return maps[extension] 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} + 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/lib/detect/has_flags.lua b/xmake/modules/lib/detect/has_flags.lua index 47347e5ed..1957a6b72 100644 --- a/xmake/modules/lib/detect/has_flags.lua +++ b/xmake/modules/lib/detect/has_flags.lua @@ -55,6 +55,20 @@ function main(name, flags, opt) -- wrap flags flags = table.wrap(flags) + -- split flag group, .e.g "-I /xxx" => {"-I", "/xxx"} + local results = {} + for _, flag in ipairs(flags) do + flag = flag:trim() + if #flag > 0 then + if flag:find(" ", 1, true) then + table.join2(results, os.argv(flag)) + else + table.insert(results, flag) + end + end + end + flags = results + -- init tool opt.toolname = tool.name opt.program = tool.program diff --git a/xmake/platforms/android/load.lua b/xmake/platforms/android/load.lua index 36725f271..1cf2fe6de 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/iphoneos/load.lua b/xmake/platforms/iphoneos/load.lua index c422ef234..d62b49746 100644 --- a/xmake/platforms/iphoneos/load.lua +++ b/xmake/platforms/iphoneos/load.lua @@ -45,23 +45,22 @@ function main() local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) -- init flags for c/c++ - _g.cxflags = { "-arch", arch, target_minver_flags, "-isysroot", xcode_sdkdir } - _g.ldflags = { "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sdkdir } - _g.shflags = { "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sdkdir } + _g.cxflags = { "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir } + _g.ldflags = { "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir } + _g.shflags = { "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir } -- init flags for objc/c++ - _g.mxflags = { "-arch", arch, target_minver_flags, "-isysroot", xcode_sdkdir } + _g.mxflags = { "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir } -- init flags for asm - _g.asflags = { "-arch", arch, target_minver_flags, "-isysroot", xcode_sdkdir } + _g.asflags = { "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir } -- init flags for swift (with _g.ldflags and _g.shflags) - _g.scflags = { "-target", format("%s-apple-ios%s", arch, target_minver) , "-sdk", xcode_sdkdir } - _g["sc-shflags"] = { "-target", format("%s-apple-ios%s", arch, target_minver) , "-sdk", xcode_sdkdir } - _g["sc-ldflags"] = { "-target", format("%s-apple-ios%s", arch, target_minver) , "-sdk", xcode_sdkdir } + _g.scflags = { format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } + _g["sc-shflags"] = { format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } + _g["sc-ldflags"] = { format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } -- ok return _g end - diff --git a/xmake/platforms/linux/load.lua b/xmake/platforms/linux/load.lua index d71d22198..c62322e15 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 = 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") + _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" } -- init flags for objc/c++ (with _g.ldflags and _g.shflags) - _g.mxflags = table.wrap(archflags) + _g.mxflags = { archflags } -- init flags for asm (with _g.ldflags and _g.shflags) - _g.asflags = table.wrap(archflags) + _g.asflags = { archflags } -- init flags for golang _g["gc-ldflags"] = {} @@ -80,4 +80,3 @@ function main() return _g end - diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua index 6baf60dcd..2a0a6a051 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 = { "-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 } + _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 } -- init flags for golang _g["gc-ldflags"] = {} @@ -70,4 +70,3 @@ function main() return _g end - diff --git a/xmake/platforms/mingw/load.lua b/xmake/platforms/mingw/load.lua index a312e8cff..b3ea19097 100644 --- a/xmake/platforms/mingw/load.lua +++ b/xmake/platforms/mingw/load.lua @@ -34,13 +34,13 @@ 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 - _g.cxflags = table.wrap(archflags) - _g.asflags = table.wrap(archflags) - _g.ldflags = table.wrap(archflags) - _g.shflags = table.wrap(archflags) + _g.cxflags = { archflags } + _g.asflags = { archflags } + _g.ldflags = { archflags } + _g.shflags = { archflags } -- init linkdirs and includedirs local sdkdir = config.get("sdk") @@ -53,4 +53,3 @@ function main() return _g end - diff --git a/xmake/platforms/watchos/load.lua b/xmake/platforms/watchos/load.lua index be5a96d82..ec58447e8 100644 --- a/xmake/platforms/watchos/load.lua +++ b/xmake/platforms/watchos/load.lua @@ -45,23 +45,22 @@ function main() local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) -- init flags for c/c++ - _g.cxflags = { "-arch", arch, target_minver_flags, "-isysroot", xcode_sdkdir } - _g.ldflags = { "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sdkdir } - _g.shflags = { "-arch", arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot", xcode_sdkdir } + _g.cxflags = { "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir } + _g.ldflags = { "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir } + _g.shflags = { "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir } -- init flags for objc/c++ - _g.mxflags = { "-arch", arch, target_minver_flags, "-isysroot", xcode_sdkdir } + _g.mxflags = { "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir } -- init flags for asm - _g.asflags = { "-arch", arch, target_minver_flags, "-isysroot", xcode_sdkdir } + _g.asflags = { "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir } -- init flags for swift (with _g.ldflags and _g.shflags) - _g.scflags = { "-target", format("%s-apple-ios%s", arch, target_minver) , "-sdk", xcode_sdkdir } - _g["sc-shflags"] = { "-target", format("%s-apple-ios%s", arch, target_minver) , "-sdk", xcode_sdkdir } - _g["sc-ldflags"] = { "-target", format("%s-apple-ios%s", arch, target_minver) , "-sdk", xcode_sdkdir } + _g.scflags = { format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } + _g["sc-shflags"] = { format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } + _g["sc-ldflags"] = { format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir } -- ok return _g end - |
