diff options
| author | ruki <[email protected]> | 2015-06-11 17:41:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-11 17:45:48 +0800 |
| commit | a731ed4d6ef2c3936d3af791e3d228fa6775eb35 (patch) | |
| tree | 0e1ba672990df66eac4eafc7a3405d6d68ae6169 /xmake/scripts/base | |
| parent | 1e8ddd3262352cc199b51493501a4ce5f48e69d2 (diff) | |
add platform configure to compiler and linker
Diffstat (limited to 'xmake/scripts/base')
| -rw-r--r-- | xmake/scripts/base/compiler.lua | 322 | ||||
| -rw-r--r-- | xmake/scripts/base/linker.lua | 192 |
2 files changed, 314 insertions, 200 deletions
diff --git a/xmake/scripts/base/compiler.lua b/xmake/scripts/base/compiler.lua index 23378f061..d9c3a7c5e 100644 --- a/xmake/scripts/base/compiler.lua +++ b/xmake/scripts/base/compiler.lua @@ -111,112 +111,65 @@ function compiler._getflags(module, names, flags) return flags_mapped end --- get the flag names from the given compiler name -function compiler._flagnames(name) +-- add flags from the compiler +function compiler._addflags_from_compiler(module, flags, flagnames) -- check - assert(name) + assert(module and flags and flagnames) - -- the flag names - local flagnames = nil - if name == "cc" then flagnames = { "cxflags", "cflags" } - elseif name == "cxx" then flagnames = { "cxflags", "cxxflags" } - elseif name == "mm" then flagnames = { "mxflags", "mflags" } - elseif name == "mxx" then flagnames = { "mxflags", "mxxflags" } - elseif name == "as" then flagnames = { "asflags" } - -- error - utils.error("unknown compiler: %s", name) - return + -- done + for _, flagname in ipairs(flagnames) do + table.join2(flags, module, module[flagname]) end - - -- ok - return flagnames end --- get the compiler kind from the source file type -function compiler._kind(srcfile) +-- add flags from the configure +function compiler._addflags_from_config(module, flags, flagnames) - -- get the source file type - local filetype = path.extension(srcfile) - if not filetype then - return nil - end - - -- get the lower file type - filetype = filetype:lower() + -- check + assert(module and flags and flagnames) - -- get the compiler kind - local kind = nil - if filetype == ".c" then kind = "cc" - elseif filetype == ".cpp" or filetype == ".cc" then kind = "cxx" - elseif filetype == ".m" then kind = "mm" - elseif filetype == ".mm" then kind = "mxx" - elseif filetype == ".s" or filetype == ".asm" then kind = "as" + -- done + for _, flagname in ipairs(flagnames) do + table.join2(flags, config.get(flagname)) end - - -- ok - return kind end - --- get the compiler from the given source file -function compiler.get(srcfile) - -- get the compiler kind - local kind = compiler._kind(srcfile) - if not kind then - return - end +-- add flags from the platform +function compiler._addflags_from_platform(module, flags, flagnames) - -- get compiler from the source file type - local module = tools.get(kind) - if module then - - -- invalid compiler - if not module.command_compile then - return - end + -- check + assert(module and flags and flagnames) - -- save kind - module._KIND = kind + -- done + for _, flagname in ipairs(flagnames) do + table.join2(flags, compiler._mapflags(module, platform.get(flagname))) end - - -- ok? - return module end --- make the compile command -function compiler.make(module, target, srcfile, objfile) +-- add flags from the target +function compiler._addflags_from_target(module, flags, flagnames, target) -- check - assert(module and target) - - -- the flag names - local flagnames = compiler._flagnames(module._KIND) - assert(flagnames) - - -- append the common flags from the current compiler - local flags = {} - for _, flagname in ipairs(flagnames) do - table.join2(flags, module[flagname]) - end + assert(module and flags and flagnames and target) - -- append the target flags from the current project + -- add the target flags from the current project for _, flagname in ipairs(flagnames) do table.join2(flags, compiler._mapflags(module, target[flagname])) end - -- append the symbols flags from the current project + -- add the symbols flags from the current project table.join2(flags, compiler._getflags(module, target.symbols, { debug = "-g" , hidden = "-fvisibility=hidden" })) - -- append the warning flags from the current project + -- add the warning flags from the current project table.join2(flags, compiler._getflags(module, target.warnings, { none = "-w" , all = "-Wall" , error = "-Werror" })) - -- append the optimize flags from the current project + -- add the optimize flags from the current project table.join2(flags, compiler._getflags(module, target.optimize, { none = "-O0" , fast = "-O1" , faster = "-O2" @@ -225,7 +178,7 @@ function compiler.make(module, target, srcfile, objfile) , aggressive = "-Ofast" })) - -- append the vector extensions flags from the current project + -- add the vector extensions flags from the current project table.join2(flags, compiler._getflags(module, target.vectorexts, { mmx = "-mmmx" , sse = "-msse" , sse2 = "-msse2" @@ -236,7 +189,7 @@ function compiler.make(module, target, srcfile, objfile) , neon = "-mfpu=neon" })) - -- append the language flags from the current project + -- add the language flags from the current project table.join2(flags, compiler._getflags(module, target.language, { ansi = "-ansi" , c89 = "-std=c89" , gnu89 = "-std=gnu89" @@ -251,14 +204,14 @@ function compiler.make(module, target, srcfile, objfile) })) - -- append the includedirs flags from the current project + -- add the includedirs flags from the current project if module.flag_includedir then for _, includedir in ipairs(utils.wrap(target.includedirs)) do table.join2(flags, module:flag_includedir(includedir)) end end - -- append the defines flags from the current project + -- add the defines flags from the current project if module.flag_define then for _, define in ipairs(utils.wrap(target.defines)) do table.join2(flags, module:flag_define(define)) @@ -281,19 +234,19 @@ function compiler.make(module, target, srcfile, objfile) if config.get(name) then opt = config.get("__" .. name) end if nil ~= opt then - -- append the flags from the option + -- add the flags from the option for _, flagname in ipairs(flagnames) do table.join2(flags, compiler._mapflags(module, opt[flagname])) end - -- append the includedirs flags from the option + -- add the includedirs flags from the option if module.flag_includedir then for _, includedir in ipairs(utils.wrap(opt.includedirs)) do table.join2(flags, module:flag_includedir(includedir)) end end - -- append the defines flags from the option + -- add the defines flags from the option if module.flag_define then local defines = {} @@ -305,7 +258,7 @@ function compiler.make(module, target, srcfile, objfile) end end - -- append the undefines flags from the option + -- add the undefines flags from the option if module.flag_undefine then local undefines = {} @@ -319,12 +272,139 @@ function compiler.make(module, target, srcfile, objfile) end end end +end - -- append the flags from the configure +-- add flags from the option +function compiler._addflags_from_option(module, flags, flagnames, opt) + + -- check + assert(module and flags and flagnames and opt) + + -- append the option flags for _, flagname in ipairs(flagnames) do - table.join2(flags, compiler._mapflags(module, config.get(flagname))) + table.join2(flags, compiler._mapflags(module, opt[flagname])) end + -- append the defines flags + if opt.defines and module.flag_define then + local defines = utils.wrap(opt.defines) + for _, define in ipairs(defines) do + table.join2(flags, module:flag_define(define)) + end + end + + -- append the undefines flags + if opt.undefines and module.flag_undefine then + local undefines = utils.wrap(opt.undefines) + for _, undefine in ipairs(undefines) do + table.join2(flags, module:flag_undefine(undefine)) + end + end + + -- append the includedirs flags + if opt.includedirs and module.flag_includedir then + for _, includedir in ipairs(utils.wrap(opt.includedirs)) do + table.join2(flags, module:flag_includedir(includedir)) + end + end +end + +-- get the flag names from the given compiler name +function compiler._flagnames(name) + + -- check + assert(name) + + -- the flag names + local flagnames = nil + if name == "cc" then flagnames = { "cxflags", "cflags" } + elseif name == "cxx" then flagnames = { "cxflags", "cxxflags" } + elseif name == "mm" then flagnames = { "mxflags", "mflags" } + elseif name == "mxx" then flagnames = { "mxflags", "mxxflags" } + elseif name == "as" then flagnames = { "asflags" } + -- error + utils.error("unknown compiler: %s", name) + return + end + + -- ok + return flagnames +end + +-- get the compiler kind from the source file type +function compiler._kind(srcfile) + + -- get the source file type + local filetype = path.extension(srcfile) + if not filetype then + return nil + end + + -- get the lower file type + filetype = filetype:lower() + + -- get the compiler kind + local kind = nil + if filetype == ".c" then kind = "cc" + elseif filetype == ".cpp" or filetype == ".cc" then kind = "cxx" + elseif filetype == ".m" then kind = "mm" + elseif filetype == ".mm" then kind = "mxx" + elseif filetype == ".s" or filetype == ".asm" then kind = "as" + end + + -- ok + return kind +end + +-- get the compiler from the given source file +function compiler.get(srcfile) + + -- get the compiler kind + local kind = compiler._kind(srcfile) + if not kind then + return + end + + -- get compiler from the source file type + local module = tools.get(kind) + if module then + + -- invalid compiler + if not module.command_compile then + return + end + + -- save kind + module._KIND = kind + end + + -- ok? + return module +end + +-- make the compile command +function compiler.make(module, target, srcfile, objfile) + + -- check + assert(module and target) + + -- the flag names + local flagnames = compiler._flagnames(module._KIND) + assert(flagnames) + + -- add flags from the compiler + local flags = {} + compiler._addflags_from_compiler(module, flags, flagnames) + + -- add flags from the platform + compiler._addflags_from_platform(module, flags, flagnames) + + -- add flags from the target + compiler._addflags_from_target(module, flags, flagnames, target) + + -- add flags from the configure + compiler._addflags_from_config(module, flags, flagnames) + -- make the compile command return module:command_compile(srcfile, objfile, table.concat(flags, " "):trim()) end @@ -361,39 +441,18 @@ function compiler.check_include(opt, include, srcpath, objpath) local flagnames = compiler._flagnames(module._KIND) assert(flagnames) - -- append the common flags + -- add flags from the compiler local flags = {} - for _, flagname in ipairs(flagnames) do - table.join2(flags, module[flagname]) - end + compiler._addflags_from_compiler(module, flags, flagnames) - -- append the option flags - for _, flagname in ipairs(flagnames) do - table.join2(flags, compiler._mapflags(module, opt[flagname])) - end + -- add flags from the platform + compiler._addflags_from_platform(module, flags, flagnames) - -- append the defines flags - if opt.defines and module.flag_define then - local defines = utils.wrap(opt.defines) - for _, define in ipairs(defines) do - table.join2(flags, module:flag_define(define)) - end - end + -- add flags from the option + compiler._addflags_from_option(module, flags, flagnames, opt) - -- append the undefines flags - if opt.undefines and module.flag_undefine then - local undefines = utils.wrap(opt.undefines) - for _, undefine in ipairs(undefines) do - table.join2(flags, module:flag_undefine(undefine)) - end - end - - -- append the includedirs flags - if opt.includedirs and module.flag_includedir then - for _, includedir in ipairs(utils.wrap(opt.includedirs)) do - table.join2(flags, module:flag_includedir(includedir)) - end - end + -- add flags from the configure + compiler._addflags_from_config(module, flags, flagnames) -- make the compile command local cmd = string.format("%s > %s 2>&1", module:command_compile(srcpath, objpath, table.concat(flags, " "):trim()), xmake._NULDEV) @@ -447,39 +506,18 @@ function compiler.check_function(opt, interface, srcpath, objpath) local flagnames = compiler._flagnames(module._KIND) assert(flagnames) - -- append the common flags + -- add flags from the compiler local flags = {} - for _, flagname in ipairs(flagnames) do - table.join2(flags, module[flagname]) - end + compiler._addflags_from_compiler(module, flags, flagnames) - -- append the option flags - for _, flagname in ipairs(flagnames) do - table.join2(flags, compiler._mapflags(module, opt[flagname])) - end - - -- append the defines flags - if opt.defines and module.flag_define then - local defines = utils.wrap(opt.defines) - for _, define in ipairs(defines) do - table.join2(flags, module:flag_define(define)) - end - end + -- add flags from the platform + compiler._addflags_from_platform(module, flags, flagnames) - -- append the undefines flags - if opt.undefines and module.flag_undefine then - local undefines = utils.wrap(opt.undefines) - for _, undefine in ipairs(undefines) do - table.join2(flags, module:flag_undefine(undefine)) - end - end + -- add flags from the option + compiler._addflags_from_option(module, flags, flagnames, opt) - -- append the includedirs flags - if opt.includedirs and module.flag_includedir then - for _, includedir in ipairs(utils.wrap(opt.includedirs)) do - table.join2(flags, module:flag_includedir(includedir)) - end - end + -- add flags from the configure + compiler._addflags_from_config(module, flags, flagnames) -- make the compile command local cmd = string.format("%s > %s 2>&1", module:command_compile(srcpath, objpath, table.concat(flags, " "):trim()), xmake._NULDEV) diff --git a/xmake/scripts/base/linker.lua b/xmake/scripts/base/linker.lua index 8767e49c4..a521a1cbf 100644 --- a/xmake/scripts/base/linker.lua +++ b/xmake/scripts/base/linker.lua @@ -108,66 +108,68 @@ function linker._getflags(module, names, flags) return flags_mapped end --- get the linker from the given kind -function linker.get(kind) - -- check - assert(kind) +-- add flags from the links +function linker._addflags_from_links(module, flags, links) - -- get the linker name from the kind - local name = nil - if kind == "binary" then name = "ld" - elseif kind == "static" then name = "ar" - elseif kind == "shared" then name = "sh" - else return end - - -- get it - local module = tools.get(name) + -- check + assert(module and flags and links) - -- invalid linker? - if module and not module.command_link then - return + -- done + if module.flag_link then + for _, link in ipairs(utils.wrap(links)) do + table.join2(flags, module:flag_link(link)) + end end +end - -- ok? - return module +-- add flags from the linker +function linker._addflags_from_linker(module, flags, flagname) + + -- check + assert(module and flags and flagname) + + -- done + table.join2(flags, module[flagname]) end --- make the link command -function linker.make(module, target, objfiles, targetfile) +-- add flags from the configure +function linker._addflags_from_config(module, flags, flagname) -- check - assert(module and target) + assert(module and flags and flagname) - -- the target kind - local kind = target.kind or "" + -- done + table.join2(flags, config.get(flagname)) +end - -- the flag name - local flagname = nil - if kind == "binary" then flagname = "ldflags" - elseif kind == "static" then flagname = "arflags" - elseif kind == "shared" then flagname = "shflags" - else - -- error - utils.error("unknown type for linker: %s", kind) - return - end +-- add flags from the platform +function linker._addflags_from_platform(module, flags, flagname) - -- append the common flags from the current linker - local flags = {} - table.join2(flags, module[flagname]) + -- check + assert(module and flags and flagname) + + -- done + table.join2(flags, linker._mapflags(module, platform.get(flagname))) +end - -- append the target flags from the current project +-- add flags from the target +function linker._addflags_from_target(module, flags, flagname, target) + + -- check + assert(module and flags and flagname and target) + + -- add the target flags from the current project table.join2(flags, linker._mapflags(module, target[flagname])) - -- append the linkdirs flags from the current project + -- add the linkdirs flags from the current project if module.flag_linkdir then for _, linkdir in ipairs(utils.wrap(target.linkdirs)) do table.join2(flags, module:flag_linkdir(linkdir)) end end - -- append the links flags from the current project + -- add the links flags from the current project if module.flag_link then for _, link in ipairs(utils.wrap(target.links)) do table.join2(flags, module:flag_link(link)) @@ -183,17 +185,17 @@ function linker.make(module, target, objfiles, targetfile) if config.get(name) then opt = config.get("__" .. name) end if nil ~= opt then - -- append the flags from the option + -- add the flags from the option table.join2(flags, linker._mapflags(module, opt[flagname])) - -- append the linkdirs flags from the option + -- add the linkdirs flags from the option if module.flag_linkdir then for _, linkdir in ipairs(utils.wrap(opt.linkdirs)) do table.join2(flags, module:flag_linkdir(linkdir)) end end - -- append the links flags from the option + -- add the links flags from the option if module.flag_link then for _, link in ipairs(utils.wrap(opt.links)) do table.join2(flags, module:flag_link(link)) @@ -202,13 +204,90 @@ function linker.make(module, target, objfiles, targetfile) end end end - -- append the flags from the configure + + -- add the flags from the configure table.join2(flags, linker._mapflags(module, config.get(flagname))) - -- append the strip flags from the current project + -- add the strip flags from the current project table.join2(flags, linker._getflags(module, target.strip, { debug = "-S" , all = "-s" })) +end + +-- add flags from the option +function linker._addflags_from_option(module, flags, flagname, opt) + + -- check + assert(module and flags and flagname and opt) + + -- append the option flags + table.join2(flags, linker._mapflags(module, opt[flagname])) + + -- append the linkdirs flags + if opt.linkdirs and module.flag_linkdir then + for _, linkdir in ipairs(utils.wrap(opt.linkdirs)) do + table.join2(flags, module:flag_linkdir(linkdir)) + end + end +end + +-- get the linker from the given kind +function linker.get(kind) + + -- check + assert(kind) + + -- get the linker name from the kind + local name = nil + if kind == "binary" then name = "ld" + elseif kind == "static" then name = "ar" + elseif kind == "shared" then name = "sh" + else return end + + -- get it + local module = tools.get(name) + + -- invalid linker? + if module and not module.command_link then + return + end + + -- ok? + return module +end + +-- make the link command +function linker.make(module, target, objfiles, targetfile) + + -- check + assert(module and target) + + -- the target kind + local kind = target.kind or "" + + -- the flag name + local flagname = nil + if kind == "binary" then flagname = "ldflags" + elseif kind == "static" then flagname = "arflags" + elseif kind == "shared" then flagname = "shflags" + else + -- error + utils.error("unknown type for linker: %s", kind) + return + end + + -- add flags from the linker + local flags = {} + linker._addflags_from_linker(module, flags, flagname) + + -- add flags from the platform + linker._addflags_from_platform(module, flags, flagname) + + -- add flags from the target + linker._addflags_from_target(module, flags, flagname, target) + + -- add flags from the configure + linker._addflags_from_config(module, flags, flagname) -- make the link command return module:command_link(table.concat(objfiles, " "), targetfile, table.concat(flags, " "):trim()) @@ -224,24 +303,21 @@ function linker.check_links(opt, links, objectfile, targetfile) local module = linker.get("binary") assert(module and module.flag_link) - -- append the common flags + -- add flags from the linker local flags = {} - table.join2(flags, module.ldflags) + linker._addflags_from_linker(module, flags, "ldflags") - -- append the option flags - table.join2(flags, linker._mapflags(module, opt.ldflags)) + -- add flags from the platform + linker._addflags_from_platform(module, flags, "ldflags") - -- append the linkdirs flags - if opt.linkdirs and module.flag_linkdir then - for _, linkdir in ipairs(utils.wrap(opt.linkdirs)) do - table.join2(flags, module:flag_linkdir(linkdir)) - end - end + -- add flags from the option + linker._addflags_from_option(module, flags, "ldflags", opt) - -- append the links flags - for _, link in ipairs(utils.wrap(links)) do - table.join2(flags, module:flag_link(link)) - end + -- add flags from the links + linker._addflags_from_links(module, flags, links) + + -- add flags from the configure + linker._addflags_from_config(module, flags, "ldflags") -- make the compile command local cmd = string.format("%s > %s 2>&1", module:command_link(objectfile, targetfile, table.concat(flags, " "):trim()), xmake._NULDEV) |
