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/linker.lua | |
| parent | 1e8ddd3262352cc199b51493501a4ce5f48e69d2 (diff) | |
add platform configure to compiler and linker
Diffstat (limited to 'xmake/scripts/base/linker.lua')
| -rw-r--r-- | xmake/scripts/base/linker.lua | 192 |
1 files changed, 134 insertions, 58 deletions
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) |
