diff options
| author | ruki <[email protected]> | 2015-12-08 19:09:51 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-12-08 19:09:51 +0800 |
| commit | 5fc652aeba3000759914f54286048c239972ac07 (patch) | |
| tree | 07ab3910c01bafab7a5071baf4f9bb026add04f2 /xmake/scripts/base | |
| parent | 119f3d4d895419eb905c1637b88c295f3144ceab (diff) | |
add ldflags for compiler
Diffstat (limited to 'xmake/scripts/base')
| -rw-r--r-- | xmake/scripts/base/compiler.lua | 12 | ||||
| -rw-r--r-- | xmake/scripts/base/linker.lua | 51 | ||||
| -rw-r--r-- | xmake/scripts/base/makefile.lua | 4 | ||||
| -rw-r--r-- | xmake/scripts/base/project.lua | 6 |
4 files changed, 58 insertions, 15 deletions
diff --git a/xmake/scripts/base/compiler.lua b/xmake/scripts/base/compiler.lua index f7a9a0c33..22e7d8e53 100644 --- a/xmake/scripts/base/compiler.lua +++ b/xmake/scripts/base/compiler.lua @@ -359,9 +359,8 @@ function compiler._make_for_option(module, opt, srcfile, objfile, logfile) local flagnames = compiler._flagnames(module._KIND) assert(flagnames) - -- add flags from the compiler + -- init flags local flags = {} - compiler._addflags_from_compiler(module, flags, flagnames) -- add flags from the configure compiler._addflags_from_config(module, flags, flagnames) @@ -372,6 +371,9 @@ function compiler._make_for_option(module, opt, srcfile, objfile, logfile) -- add flags from the platform compiler._addflags_from_platform(module, flags, flagnames) + -- add flags from the compiler + compiler._addflags_from_compiler(module, flags, flagnames) + -- execute the compile command return module:command_compile(srcfile, objfile, table.concat(flags, " "):trim(), logfile) end @@ -414,9 +416,8 @@ function compiler.make(module, target, srcfile, objfile, logfile) local flagnames = compiler._flagnames(module._KIND) assert(flagnames) - -- add flags from the compiler + -- init flags local flags = {} - compiler._addflags_from_compiler(module, flags, flagnames) -- add flags from the configure compiler._addflags_from_config(module, flags, flagnames) @@ -427,6 +428,9 @@ function compiler.make(module, target, srcfile, objfile, logfile) -- add flags from the platform compiler._addflags_from_platform(module, flags, flagnames) + -- add flags from the compiler + compiler._addflags_from_compiler(module, flags, flagnames) + -- make the compile command return module:command_compile(srcfile, objfile, table.concat(flags, " "):trim(), logfile) end diff --git a/xmake/scripts/base/linker.lua b/xmake/scripts/base/linker.lua index a91b57770..4d7d92248 100644 --- a/xmake/scripts/base/linker.lua +++ b/xmake/scripts/base/linker.lua @@ -28,6 +28,7 @@ local utils = require("base/utils") local table = require("base/table") local string = require("base/string") local config = require("base/config") +local compiler = require("base/compiler") local tools = require("tools/tools") local platform = require("platform/platform") @@ -133,6 +134,34 @@ function linker._addflags_from_linker(module, flags, flagname) table.join2(flags, module[flagname]) end +-- add flags from the compiler +function linker._addflags_from_compiler(module, flags, flagname, srcfiles) + + -- check + assert(module and flags and flagname) + + -- add the flags for compiler + local flags_for_compiler = {} + if srcfiles then + for _, srcfile in ipairs(utils.wrap(srcfiles)) do + + -- get the compiler + local c, errors = compiler.get(srcfile) + if not c then + -- error + utils.error(errors) + return + end + + -- add flags + table.join2(flags_for_compiler, c[flagname]) + end + end + + -- done + table.join2(flags, utils.unique(flags_for_compiler)) +end + -- add flags from the configure function linker._addflags_from_config(module, flags, flagname) @@ -271,7 +300,7 @@ function linker.get(kind) end -- make the link command -function linker.make(module, target, objfiles, targetfile, logfile) +function linker.make(module, target, srcfiles, objfiles, targetfile, logfile) -- check assert(module and target) @@ -290,9 +319,8 @@ function linker.make(module, target, objfiles, targetfile, logfile) return end - -- add flags from the linker + -- init flags local flags = {} - linker._addflags_from_linker(module, flags, flagname) -- add flags from the configure linker._addflags_from_config(module, flags, flagname) @@ -303,12 +331,18 @@ function linker.make(module, target, objfiles, targetfile, logfile) -- add flags from the platform linker._addflags_from_platform(module, flags, flagname) + -- add flags from the compiler + linker._addflags_from_compiler(module, flags, flagname, srcfiles) + + -- add flags from the linker + linker._addflags_from_linker(module, flags, flagname) + -- make the link command return module:command_link(table.concat(objfiles, " "), targetfile, table.concat(flags, " "):trim(), logfile) end -- check link for the project option -function linker.check_links(opt, links, objectfile, targetfile) +function linker.check_links(opt, links, sourcefile, objectfile, targetfile) -- check assert(opt and links and objectfile and targetfile) @@ -317,9 +351,8 @@ function linker.check_links(opt, links, objectfile, targetfile) local module = linker.get("binary") assert(module and module.flag_link) - -- add flags from the linker + -- init flags local flags = {} - linker._addflags_from_linker(module, flags, "ldflags") -- add flags from the configure linker._addflags_from_config(module, flags, "ldflags") @@ -333,6 +366,12 @@ function linker.check_links(opt, links, objectfile, targetfile) -- add flags from the links linker._addflags_from_links(module, flags, links) + -- add flags from the compiler + linker._addflags_from_compiler(module, flags, "ldflags", sourcefile) + + -- add flags from the linker + linker._addflags_from_linker(module, flags, "ldflags") + -- execute the link command return module:main(module:command_link(objectfile, targetfile, table.concat(flags, " "):trim(), xmake._NULDEV)) end diff --git a/xmake/scripts/base/makefile.lua b/xmake/scripts/base/makefile.lua index 60cf03f01..0db3791a2 100644 --- a/xmake/scripts/base/makefile.lua +++ b/xmake/scripts/base/makefile.lua @@ -270,13 +270,13 @@ function makefile._make_target(file, name, target) else mode = "" end -- make the command - local cmd = linker.make(l, target, objfiles, targetfile, makefile._LOGFILE) + local cmd = linker.make(l, target, srcfiles, objfiles, targetfile, makefile._LOGFILE) -- the verbose local verbose = cmd:encode() -- too long? if verbose and #verbose > 256 then - verbose = linker.make(l, target, {rule.filename("*", "object")}, targetfile) + verbose = linker.make(l, target, srcfiles, {rule.filename("*", "object")}, targetfile) verbose = verbose:encode() end diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua index 74128be9d..c9d7bd9b3 100644 --- a/xmake/scripts/base/project.lua +++ b/xmake/scripts/base/project.lua @@ -671,7 +671,7 @@ function project._make_option_for_checking_links(opt, links, cfile, objectfile, local ok = compiler.check_include(opt, nil, cfile, objectfile) -- check link - if ok then ok = linker.check_links(opt, links, objectfile, targetfile) end + if ok then ok = linker.check_links(opt, links, cfile, objectfile, targetfile) end -- trace utils.verbose("checking for the links %s ... %s", links_str, utils.ifelse(ok, "ok", "no")) @@ -747,7 +747,7 @@ function project._make_option_for_checking_cfuncs(opt, cfuncs, cfile, objectfile local ok = compiler.check_function(opt, cfunc, cfile, objectfile) -- check link - if ok and opt.links then ok = linker.check_links(opt, opt.links, objectfile, targetfile) end + if ok and opt.links then ok = linker.check_links(opt, opt.links, cfile, objectfile, targetfile) end -- trace utils.verbose("checking for the c function %s ... %s", cfunc, utils.ifelse(ok, "ok", "no")) @@ -770,7 +770,7 @@ function project._make_option_for_checking_cxxfuncs(opt, cxxfuncs, cxxfile, obje local ok = compiler.check_function(opt, cxxfunc, cxxfile, objectfile) -- check link - if ok and opt.links then ok = linker.check_links(opt, opt.links, objectfile, targetfile) end + if ok and opt.links then ok = linker.check_links(opt, opt.links, cxxfile, objectfile, targetfile) end -- trace utils.verbose("checking for the c++ function %s ... %s", cxxfunc, utils.ifelse(ok, "ok", "no")) |
