diff options
| author | ruki <[email protected]> | 2017-06-26 22:26:33 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-06-26 22:26:33 +0800 |
| commit | 08423656d08715670959b69c64957e9e9b1b3db1 (patch) | |
| tree | 8739a1ef0ed686ab83239910681b70c0dea858ad | |
| parent | f57db3954d227c29d15b68316e9b18838a55c3d4 (diff) | |
modify compiler and linker args
| -rw-r--r-- | xmake/actions/build/kinds/binary.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/object.lua | 8 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/shared.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/build/kinds/static.lua | 6 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 10 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 4 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/compiler.lua | 33 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/tool/linker.lua | 20 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 63 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 20 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/has_cxsnippets.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/project/makefile/makefile.lua | 10 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua | 4 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 4 |
14 files changed, 123 insertions, 73 deletions
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua index b7dd5f512..17d4e063c 100644 --- a/xmake/actions/build/kinds/binary.lua +++ b/xmake/actions/build/kinds/binary.lua @@ -67,7 +67,7 @@ function _build_from_objects(target, buildinfo) end -- link it - linker.link(objectfiles, targetfile, target) + linker.link(target:get("kind"), target:sourcekinds(), objectfiles, targetfile, {target = target}) end -- build target from sources @@ -89,11 +89,11 @@ function _build_from_sources(target, buildinfo, sourcebatch, sourcekind) -- trace verbose info if verbose then - print(compiler.buildcmd(sourcebatch.sourcefiles, targetfile, target, sourcekind)) + print(compiler.buildcmd(sourcebatch.sourcefiles, targetfile, {target = target, sourcekind = sourcekind})) end -- build it - compiler.build(sourcebatch.sourcefiles, targetfile, target, sourcekind) + compiler.build(sourcebatch.sourcefiles, targetfile, {target = target, sourcekind = sourcekind}) end -- build binary target diff --git a/xmake/actions/build/kinds/object.lua b/xmake/actions/build/kinds/object.lua index 18140dee5..0e808ab0c 100644 --- a/xmake/actions/build/kinds/object.lua +++ b/xmake/actions/build/kinds/object.lua @@ -152,11 +152,11 @@ function _build_object(target, buildinfo, index, sourcebatch, ccache) -- trace verbose info if verbose then - print(compiler.compcmd(sourcefile, objectfile, target)) + print(compiler.compcmd(sourcefile, objectfile, {target = target})) end -- complie it - compiler.compile(sourcefile, objectfile, incdepfile, target) + compiler.compile(sourcefile, objectfile, {incdepfiles = incdepfile, target = target}) end -- build each objects from the given source batch @@ -205,11 +205,11 @@ function _build_single_object(target, buildinfo, sourcekind, sourcebatch, jobs, -- trace verbose info if verbose then - print(compiler.compcmd(sourcefiles, objectfiles, target, sourcekind)) + print(compiler.compcmd(sourcefiles, objectfiles, {target = target, sourcekind = sourcekind})) end -- complie them - compiler.compile(sourcefiles, objectfiles, incdepfiles, target, sourcekind) + compiler.compile(sourcefiles, objectfiles, {incdepfiles = incdepfiles, target = target, sourcekind = sourcekind}) -- update object index _g.sourceindex = _g.sourceindex + #sourcebatch.sourcefiles diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua index ab2cd40b0..158b71ccf 100644 --- a/xmake/actions/build/kinds/shared.lua +++ b/xmake/actions/build/kinds/shared.lua @@ -80,7 +80,7 @@ function _build_from_objects(target, buildinfo) end -- link it - linker.link(objectfiles, targetfile, target) + linker.link(target:get("kind"), target:sourcekinds(), objectfiles, targetfile, {target = target}) end -- build target from sources @@ -102,11 +102,11 @@ function _build_from_sources(target, buildinfo, sourcebatch, sourcekind) -- trace verbose info if verbose then - print(compiler.buildcmd(sourcebatch.sourcefiles, targetfile, target, sourcekind)) + print(compiler.buildcmd(sourcebatch.sourcefiles, targetfile, {target = target, sourcekind = sourcekind})) end -- build it - compiler.build(sourcebatch.sourcefiles, targetfile, target, sourcekind) + compiler.build(sourcebatch.sourcefiles, targetfile, {target = target, sourcekind = sourcekind}) end -- build shared target diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua index 6dcacbd30..a4971cd7f 100644 --- a/xmake/actions/build/kinds/static.lua +++ b/xmake/actions/build/kinds/static.lua @@ -80,7 +80,7 @@ function _build_from_objects(target, buildinfo) end -- link it - linker.link(objectfiles, targetfile, target) + linker.link(target:get("kind"), target:sourcekinds(), objectfiles, targetfile, {target = target}) end -- build target from sources @@ -102,11 +102,11 @@ function _build_from_sources(target, buildinfo, sourcebatch, sourcekind) -- trace verbose info if verbose then - print(compiler.buildcmd(sourcebatch.sourcefiles, targetfile, target, sourcekind)) + print(compiler.buildcmd(sourcebatch.sourcefiles, targetfile, {target = target, sourcekind = sourcekind})) end -- build it - compiler.build(sourcebatch.sourcefiles, targetfile, target, sourcekind) + compiler.build(sourcebatch.sourcefiles, targetfile, {target = target, sourcekind = sourcekind}) end -- build static target diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index 72cc0d750..403945f97 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -70,7 +70,7 @@ function option:_check_link(sourcefile, objectfile, targetfile) end -- attempt to link it - return instance:link(objectfile, targetfile, self) + return instance:link(objectfile, targetfile, {target = self}) end -- check include @@ -106,7 +106,7 @@ function option:_check_include(include, srcpath, objpath) end -- attempt to compile it - return instance:compile(srcpath, objpath, nil, self) + return instance:compile(srcpath, objpath, {target = self}) end -- check function @@ -157,7 +157,7 @@ function option:_check_function(checkcode, srcpath, objpath) srcfile:close() -- attempt to compile it - return instance:compile(srcpath, objpath, nil, self) + return instance:compile(srcpath, objpath, {target = self}) end -- check type @@ -208,7 +208,7 @@ function option:_check_type(typename, srcpath, objpath) srcfile:close() -- attempt to compile it - return instance:compile(srcpath, objpath, nil, self) + return instance:compile(srcpath, objpath, {target = self}) end -- check snippet @@ -232,7 +232,7 @@ function option:_check_snippet(snippet, srcpath, objpath) end -- attempt to compile it - return instance:compile(srcpath, objpath, nil, self) + return instance:compile(srcpath, objpath, {target = self}) end -- check option for checking links diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 008cddc91..ace3a2a18 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -116,14 +116,14 @@ end function target:linkcmd(objectfiles) -- make command - return self:linker():linkcmd(objectfiles or self:objectfiles(), self:targetfile(), self) + return self:linker():linkcmd(objectfiles or self:objectfiles(), self:targetfile(), {target = self}) end -- make link flags for the given target function target:linkflags() -- make flags - return self:linker():linkflags(self) + return self:linker():linkflags({target = self}) end -- get target deps diff --git a/xmake/core/sandbox/modules/import/core/tool/compiler.lua b/xmake/core/sandbox/modules/import/core/tool/compiler.lua index 8990f7935..a6ebc45f6 100644 --- a/xmake/core/sandbox/modules/import/core/tool/compiler.lua +++ b/xmake/core/sandbox/modules/import/core/tool/compiler.lua @@ -46,9 +46,13 @@ function sandbox_core_tool_compiler.feature(sourcekind, name) end -- make command for compiling source file -function sandbox_core_tool_compiler.compcmd(sourcefiles, objectfile, target, sourcekind) +function sandbox_core_tool_compiler.compcmd(sourcefiles, objectfile, opt) + + -- init options + opt = opt or {} -- get source kind if only one source file + local sourcekind = opt.sourcekind if not sourcekind and type(sourcefiles) == "string" then sourcekind = language.sourcekind_of(sourcefiles) end @@ -60,13 +64,17 @@ function sandbox_core_tool_compiler.compcmd(sourcefiles, objectfile, target, sou end -- make command - return instance:compcmd(sourcefiles, objectfile, target) + return instance:compcmd(sourcefiles, objectfile, opt) end -- compile source files -function sandbox_core_tool_compiler.compile(sourcefiles, objectfile, incdepfile, target, sourcekind) +function sandbox_core_tool_compiler.compile(sourcefiles, objectfile, opt) + + -- init options + opt = opt or {} -- get source kind if only one source file + local sourcekind = opt.sourcekind if not sourcekind and type(sourcefiles) == "string" then sourcekind = language.sourcekind_of(sourcefiles) end @@ -78,16 +86,17 @@ function sandbox_core_tool_compiler.compile(sourcefiles, objectfile, incdepfile, end -- compile it - local ok, errors = instance:compile(sourcefiles, objectfile, incdepfile, target) + local ok, errors = instance:compile(sourcefiles, objectfile, opt) if not ok then raise(errors) end end --- make compiling flags for the given target -function sandbox_core_tool_compiler.compflags(sourcefiles, target, sourcekind) +-- make compiling flags +function sandbox_core_tool_compiler.compflags(sourcefiles, opt) -- get source kind if only one source file + local sourcekind = opt.sourcekind if not sourcekind and type(sourcefiles) == "string" then sourcekind = language.sourcekind_of(sourcefiles) end @@ -99,13 +108,14 @@ function sandbox_core_tool_compiler.compflags(sourcefiles, target, sourcekind) end -- make flags - return instance:compflags(target) + return instance:compflags(opt) end -- make command for building source file -function sandbox_core_tool_compiler.buildcmd(sourcefiles, targetfile, target, sourcekind) +function sandbox_core_tool_compiler.buildcmd(sourcefiles, targetfile, opt) -- get source kind if only one source file + local sourcekind = opt.sourcekind if not sourcekind and type(sourcefiles) == "string" then sourcekind = language.sourcekind_of(sourcefiles) end @@ -117,13 +127,14 @@ function sandbox_core_tool_compiler.buildcmd(sourcefiles, targetfile, target, so end -- make command - return instance:buildcmd(sourcefiles, target:targetkind(), targetfile, target) + return instance:buildcmd(sourcefiles, targetfile, opt) end -- build source files -function sandbox_core_tool_compiler.build(sourcefiles, targetfile, target, sourcekind) +function sandbox_core_tool_compiler.build(sourcefiles, targetfile, opt) -- get source kind if only one source file + local sourcekind = opt.sourcekind if not sourcekind and type(sourcefiles) == "string" then sourcekind = language.sourcekind_of(sourcefiles) end @@ -135,7 +146,7 @@ function sandbox_core_tool_compiler.build(sourcefiles, targetfile, target, sourc end -- build it - local ok, errors = instance:build(sourcefiles, target:targetkind(), targetfile, target) + local ok, errors = instance:build(sourcefiles, targetfile, opt) if not ok then raise(errors) end diff --git a/xmake/core/sandbox/modules/import/core/tool/linker.lua b/xmake/core/sandbox/modules/import/core/tool/linker.lua index b785f2c50..7b95d8b7c 100644 --- a/xmake/core/sandbox/modules/import/core/tool/linker.lua +++ b/xmake/core/sandbox/modules/import/core/tool/linker.lua @@ -31,42 +31,42 @@ local linker = require("tool/linker") local raise = require("sandbox/modules/raise") -- make command for linking target file -function sandbox_core_tool_linker.linkcmd(objectfiles, targetfile, target) +function sandbox_core_tool_linker.linkcmd(targetkind, sourcekinds, objectfiles, targetfile, opt) -- get the linker instance - local instance, errors = linker.load(target:get("kind"), target:sourcekinds()) + local instance, errors = linker.load(targetkind, sourcekinds) if not instance then raise(errors) end -- make command - return instance:linkcmd(objectfiles, targetfile, target) + return instance:linkcmd(objectfiles, targetfile, opt) end -- make link flags for the given target -function sandbox_core_tool_linker.linkflags(target) - +function sandbox_core_tool_linker.linkflags(targetkind, sourcekinds, opt) + -- get the linker instance - local instance, errors = linker.load(target:get("kind"), target:sourcekinds()) + local instance, errors = linker.load(targetkind, sourcekinds) if not instance then raise(errors) end -- make flags - return instance:linkflags(target) + return instance:linkflags(opt) end -- link target file -function sandbox_core_tool_linker.link(objectfiles, targetfile, target) +function sandbox_core_tool_linker.link(targetkind, sourcekinds, objectfiles, targetfile, opt) -- get the linker instance - local instance, errors = linker.load(target:get("kind"), target:sourcekinds()) + local instance, errors = linker.load(targetkind, sourcekinds) if not instance then raise(errors) end -- link it - local ok, errors = instance:link(objectfiles, targetfile, target) + local ok, errors = instance:link(objectfiles, targetfile, opt) if not ok then raise(errors) end diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index d6a1c74ed..a4f8dc5f4 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -124,36 +124,73 @@ function compiler.load(sourcekind) return instance end --- build the source files -function compiler:build(sourcefiles, targetkind, targetfile, target) +-- build the source files (compile and link) +function compiler:build(sourcefiles, targetfile, opt) + + -- init options + opt = opt or {} + + -- make flags + local flags = self:compflags(opt) + if opt.target then + flags = flags .. " " .. (opt.target:linkflags()) + end + + -- get target kind + local targetkind = opt.targetkind + if not targetkind and opt.target then + targetkind = opt.target:get("kind") + end -- get it - return sandbox.load(self:_tool().build, self:_tool(), sourcefiles, targetkind, targetfile, (self:compflags(target)) .. " " .. (target:linkflags())) + return sandbox.load(self:_tool().build, self:_tool(), sourcefiles, targetkind or "binary", targetfile, flags) end --- get the build command -function compiler:buildcmd(sourcefiles, targetkind, targetfile, target) +-- get the build command (compile and link) +function compiler:buildcmd(sourcefiles, targetfile, opt) + + -- init options + opt = opt or {} + + -- make flags + local flags = self:compflags(opt) + if opt.target then + flags = flags .. " " .. (opt.target:linkflags()) + end + + -- get target kind + local targetkind = opt.targetkind + if not targetkind and opt.target then + targetkind = opt.target:get("kind") + end -- get it - return self:_tool():buildcmd(sourcefiles, targetkind, targetfile, (self:compflags(target) .. " " .. (target:linkflags()))) + return self:_tool():buildcmd(sourcefiles, targetkind or "binary", targetfile, flags) end -- compile the source files -function compiler:compile(sourcefiles, objectfile, incdepfile, target) +function compiler:compile(sourcefiles, objectfile, opt) + + -- init options + opt = opt or {} -- compile it - return sandbox.load(self:_tool().compile, self:_tool(), sourcefiles, objectfile, incdepfile, (self:compflags(target))) + return sandbox.load(self:_tool().compile, self:_tool(), sourcefiles, objectfile, opt.incdepfiles, (self:compflags(opt))) end -- get the compile command -function compiler:compcmd(sourcefiles, objectfile, target) - - -- get it - return self:_tool():compcmd(sourcefiles, objectfile, (self:compflags(target))) +function compiler:compcmd(sourcefiles, objectfile, opt) + return self:_tool():compcmd(sourcefiles, objectfile, (self:compflags(opt))) end -- get the compling flags -function compiler:compflags(target) +function compiler:compflags(opt) + + -- init options + opt = opt or {} + + -- get target + local target = opt.target -- no target? if not target then diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index 7427dbfac..43ef26485 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -173,21 +173,23 @@ function linker.load(targetkind, sourcekinds) end -- link the target file -function linker:link(objectfiles, targetfile, target) - - -- link it - return sandbox.load(self:_tool().link, self:_tool(), table.concat(table.wrap(objectfiles), " "), self:_targetkind(), targetfile, (self:linkflags(target))) +function linker:link(objectfiles, targetfile, opt) + return sandbox.load(self:_tool().link, self:_tool(), table.concat(table.wrap(objectfiles), " "), self:_targetkind(), targetfile, (self:linkflags(opt))) end -- get the link command -function linker:linkcmd(objectfiles, targetfile, target) - - -- get it - return self:_tool():linkcmd(table.concat(table.wrap(objectfiles), " "), self:_targetkind(), targetfile, (self:linkflags(target))) +function linker:linkcmd(objectfiles, targetfile, opt) + return self:_tool():linkcmd(table.concat(table.wrap(objectfiles), " "), self:_targetkind(), targetfile, (self:linkflags(opt))) end -- get the link flags -function linker:linkflags(target) +function linker:linkflags(opt) + + -- init options + opt = opt or {} + + -- get target + local target = opt.target -- no target? if not target then diff --git a/xmake/modules/lib/detect/has_cxsnippets.lua b/xmake/modules/lib/detect/has_cxsnippets.lua index 44011b842..78665ac14 100644 --- a/xmake/modules/lib/detect/has_cxsnippets.lua +++ b/xmake/modules/lib/detect/has_cxsnippets.lua @@ -170,7 +170,7 @@ function main(csnippets, opt) local ok = try { function () - compiler.compile(sourcefile, objectfile, nil, opt.target) + compiler.compile(sourcefile, objectfile, opt) -- linker.link(objectfile, os.nuldev(), opt.target) return true end, diff --git a/xmake/plugins/project/makefile/makefile.lua b/xmake/plugins/project/makefile/makefile.lua index dadaaba1c..2efe09cea 100644 --- a/xmake/plugins/project/makefile/makefile.lua +++ b/xmake/plugins/project/makefile/makefile.lua @@ -103,10 +103,10 @@ function _make_object(makefile, target, sourcefile, objectfile) local program = platform.tool(sourcekind) -- get complier flags - local compflags = compiler.compflags(sourcefile, target, sourcekind) + local compflags = compiler.compflags(sourcefile, {target = target, sourcekind = sourcekind}) -- make command - local command = compiler.compcmd(sourcefile, objectfile, target) + local command = compiler.compcmd(sourcefile, objectfile, {target = target}) -- replace compflags to $(XX) local p, e = command:find(compflags, 1, true) @@ -164,10 +164,10 @@ function _make_single_object(makefile, target, sourcekind, sourcebatch) local program = platform.tool(sourcekind) -- get complier flags - local compflags = compiler.compflags(sourcefiles, target, sourcekind) + local compflags = compiler.compflags(sourcefiles, {target = target, sourcekind = sourcekind}) -- make command - local command = compiler.compcmd(sourcefiles, objectfiles, target, sourcekind) + local command = compiler.compcmd(sourcefiles, objectfiles, {target = target, sourcekind = sourcekind}) -- replace compflags to $(XX) local p, e = command:find(compflags, 1, true) @@ -346,7 +346,7 @@ function _make_all(makefile) for targetname, target in pairs(project.targets()) do if not target:isphony() then for sourcekind, sourcebatch in pairs(target:sourcebatches()) do - makefile:print("%s_%s=%s", targetname, sourcekind:upper(), compiler.compflags(sourcebatch.sourcefiles, target, sourcekind)) + makefile:print("%s_%s=%s", targetname, sourcekind:upper(), compiler.compflags(sourcebatch.sourcefiles, {target = target, sourcekind = sourcekind})) end makefile:print("%s_%s=%s", targetname, target:linker():get("kind"):upper(), target:linkflags()) end diff --git a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua index 094b7a166..f937c5efb 100644 --- a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua @@ -32,7 +32,7 @@ import("vsfile") function _make_compflags(sourcefile, target, vcprojdir) -- make the compiling flags - local _, compflags = compiler.compflags(sourcefile, target) + local _, compflags = compiler.compflags(sourcefile, {target = target}) -- replace -Idir or /Idir, -Fdsymbol.pdb or /Fdsymbol.pdb local flags = {} @@ -74,7 +74,7 @@ end function _make_linkflags(target, vcprojdir) -- make the linking flags - local _, linkflags = linker.linkflags(target) + local _, linkflags = linker.linkflags(target:get("kind"), target:sourcekinds()) -- replace -libpath:dir or /libpath:dir, -pdb:symbol.pdb or /pdb:symbol.pdb local flags = {} diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 29b004030..a134bbb90 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -51,12 +51,12 @@ function _make_targetinfo(mode, arch, target) -- save compiler flags targetinfo.compflags = {} for _, sourcefile in ipairs(target:sourcefiles()) do - local _, compflags = compiler.compflags(sourcefile, target) + local _, compflags = compiler.compflags(sourcefile, {target = target}) targetinfo.compflags[sourcefile] = compflags end -- save linker flags - local _, linkflags = linker.linkflags(target) + local _, linkflags = linker.linkflags(target:get("kinds"), target:sourcekinds()) targetinfo.linkflags = linkflags -- ok |
