diff options
| -rw-r--r-- | xmake/core/tool/compiler.lua | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index e2125abcc..dce7bf532 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -203,6 +203,7 @@ function compiler.load(sourcekind, target) return instance end +--[[ -- build the source files (compile and link) function compiler:build(sourcefiles, targetfile, opt) opt = opt or {} @@ -267,6 +268,62 @@ function compiler:buildargv(sourcefiles, targetfile, opt) targetkind = target:kind() end return self:_tool():buildargv(sourcefiles, targetkind or "binary", targetfile, flags, opt) +end]] + +-- build the source files (compile and link) +function compiler:build(sourcefiles, targetfile, opt) + opt = opt or {} + + -- get compile flags + local compflags = opt.compflags + if not compflags then + -- patch sourcefile to get flags of the given source file + if type(sourcefiles) == "string" then + opt.sourcefile = sourcefiles + end + compflags = self:compflags(opt) + end + + -- make flags + local flags = compflags + if opt.target then + flags = table.join(flags, opt.target:linkflags()) + end + + -- get target kind + local targetkind = opt.targetkind + if not targetkind and opt.target and opt.target.targetkind then + targetkind = opt.target:kind() + end + return sandbox.load(self:_tool().build, self:_tool(), sourcefiles, targetkind or "binary", targetfile, flags) +end + +-- get the build arguments list (compile and link) +function compiler:buildargv(sourcefiles, targetfile, opt) + opt = opt or {} + + -- get compile flags + local compflags = opt.compflags + if not compflags then + -- patch sourcefile to get flags of the given source file + if type(sourcefiles) == "string" then + opt.sourcefile = sourcefiles + end + compflags = self:compflags(opt) + end + + -- make flags + local flags = compflags + if opt.target then + flags = table.join(flags, opt.target:linkflags()) + end + + -- get target kind + local targetkind = opt.targetkind + if not targetkind and opt.target and opt.target.targetkind then + targetkind = opt.target:kind() + end + return self:_tool():buildargv(sourcefiles, targetkind or "binary", targetfile, flags) end -- get the build command @@ -277,11 +334,12 @@ end -- compile the source files function compiler:compile(sourcefiles, objectfile, opt) opt = opt or {} + --[[ local target = opt.target or self:target() if not opt.target and target then opt = table.copy(opt) opt.target = target - end + end]] -- get compile flags local compflags = opt.compflags @@ -294,6 +352,8 @@ function compiler:compile(sourcefiles, objectfile, opt) end -- compile it + opt = table.copy(opt) + opt.target = self:target() profiler:enter(self:name(), "compile", sourcefiles) local ok, errors = sandbox.load(self:_tool().compile, self:_tool(), sourcefiles, objectfile, opt.dependinfo, compflags, opt) profiler:leave(self:name(), "compile", sourcefiles) @@ -302,11 +362,13 @@ end -- get the compile arguments list function compiler:compargv(sourcefiles, objectfile, opt) + opt = opt or {} + --[[ local target = opt.target or self:target() if not opt.target and target then opt = table.copy(opt) opt.target = target - end + end]] -- get compile flags local compflags = opt.compflags |
