diff options
| author | ruki <[email protected]> | 2017-02-07 09:01:16 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-02-07 09:01:16 +0800 |
| commit | 072f97eb86fd3626fb70325e17e028bf90766dc2 (patch) | |
| tree | c7b323a7bb3d9bc38ea2eba024eff2591d0dc6c7 | |
| parent | 59c7e717b3e627fbfcee313f0c1d050e9bbceb5b (diff) | |
move some linker interfaces to builder
| -rw-r--r-- | xmake/core/project/option.lua | 2 | ||||
| -rw-r--r-- | xmake/core/tool/archiver.lua | 38 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 45 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 55 | ||||
| -rw-r--r-- | xmake/core/tool/linker.lua | 61 |
5 files changed, 73 insertions, 128 deletions
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index 2648338ad..4ce846134 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -49,7 +49,7 @@ function option:_check_link(sourcefile, objectfile, targetfile) self._SOURCEKINDS = language.sourcekind_of(sourcefile) -- load the linker instance - local instance = linker.load("binary") + local instance = linker.load("binary", self._SOURCEKINDS) if not instance then return false end diff --git a/xmake/core/tool/archiver.lua b/xmake/core/tool/archiver.lua index 1b2f6dbc2..8936f3e8e 100644 --- a/xmake/core/tool/archiver.lua +++ b/xmake/core/tool/archiver.lua @@ -39,13 +39,6 @@ local platform = require("platform/platform") local tool = require("tool/tool") local builder = require("tool/builder") --- get the current flag name -function archiver:_flagname() - - -- get it - return self._FLAGNAME -end - -- get the flags function archiver:_flags(target) @@ -87,32 +80,13 @@ function archiver:_flags(target) return flags end --- add flags from the configure -function archiver:_addflags_from_config(flags) - - -- done - table.join2(flags, config.get(self:_flagname())) -end - --- add flags from the target -function archiver:_addflags_from_target(flags, target) - - -- add the target flags - table.join2(flags, self:_mapflags(target:get(self:_flagname()))) -end - --- add flags from the platform -function archiver:_addflags_from_platform(flags) - - -- add flags - table.join2(flags, platform.get(self:_flagname())) -end - -- add flags from the archiver function archiver:_addflags_from_archiver(flags) - -- done - table.join2(flags, self:get(self:_flagname())) + -- add flags + for _, flagkind in ipairs(self:_flagkinds()) do + table.join2(flags, self:get(flagkind)) + end end -- load the archiver @@ -155,8 +129,8 @@ function archiver.load(sourcekinds) end instance._NAMEFLAGS = nameflags - -- init flag name - instance._FLAGNAME = "arflags" + -- init flag kinds + instance._FLAGKINDS = {"arflags"} -- save this instance archiver._INSTANCE = instance diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index c529d2327..c0a75dac8 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -109,6 +109,51 @@ function builder:_mapflags(flags) return results end +-- get the flag kinds +function builder:_flagkinds() + + -- get it + return self._FLAGKINDS +end + +-- add flags from the configure +function builder:_addflags_from_config(flags) + + -- done + for _, flagkind in ipairs(self:_flagkinds()) do + table.join2(flags, config.get(flagkind)) + end +end + +-- add flags from the target +function builder:_addflags_from_target(flags, target) + + -- add the target flags + for _, flagkind in ipairs(self:_flagkinds()) do + table.join2(flags, self:_mapflags(target:get(flagkind))) + end + + -- for target options? + if target.options then + + -- add the flags for the target options + for _, opt in ipairs(target:options()) do + + -- add the flags from the option + self:_addflags_from_target(flags, opt) + end + end +end + +-- add flags from the platform +function builder:_addflags_from_platform(flags) + + -- add flags + for _, flagkind in ipairs(self:_flagkinds()) do + table.join2(flags, platform.get(flagkind)) + end +end + -- add flags (named) from the language function builder:_addflags_from_language(flags, target) diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 61cfd2114..cf175e622 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -46,63 +46,18 @@ function compiler:_language() return self._LANGUAGE end --- get the source flags -function compiler:_sourceflags() - - -- get it - return self._SOURCEFLAGS -end - --- add flags from the configure -function compiler:_addflags_from_config(flags) - - -- done - for _, sourceflag in ipairs(self:_sourceflags()) do - table.join2(flags, config.get(sourceflag)) - end -end - --- add flags from the target -function compiler:_addflags_from_target(flags, target) - - -- add the target flags - for _, sourceflag in ipairs(self:_sourceflags()) do - table.join2(flags, self:_mapflags(target:get(sourceflag))) - end - - -- for target options? - if target.options then - - -- add the flags for the target options - for _, opt in ipairs(target:options()) do - - -- add the flags from the option - self:_addflags_from_target(flags, opt) - end - end -end - --- add flags from the platform -function compiler:_addflags_from_platform(flags) - - -- add flags - for _, sourceflag in ipairs(self:_sourceflags()) do - table.join2(flags, platform.get(sourceflag)) - end -end - -- add flags from the compiler function compiler:_addflags_from_compiler(flags, kind) -- done - for _, sourceflag in ipairs(self:_sourceflags()) do + for _, flagkind in ipairs(self:_flagkinds()) do -- add compiler.xxflags - table.join2(flags, self:get(sourceflag)) + table.join2(flags, self:get(flagkind)) -- add compiler.kind.xxflags if kind ~= nil and self:get(kind) ~= nil then - table.join2(flags, self:get(kind)[sourceflag]) + table.join2(flags, self:get(kind)[flagkind]) end end end @@ -139,8 +94,8 @@ function compiler.load(sourcekind) -- init name flags instance._NAMEFLAGS = result:nameflags()["compiler"] - -- init source flags - instance._SOURCEFLAGS = table.wrap(result:sourceflags()[sourcekind]) + -- init flag kinds + instance._FLAGKINDS = table.wrap(result:sourceflags()[sourcekind]) -- save this instance compiler._INSTANCES[sourcekind] = instance diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index e925efa81..0f71123c6 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -40,56 +40,19 @@ local tool = require("tool/tool") local builder = require("tool/builder") local compiler = require("tool/compiler") --- get the current flag name -function linker:_flagname() - - -- get it - return self._FLAGNAME -end - --- add flags from the configure -function linker:_addflags_from_config(flags) - - -- done - table.join2(flags, config.get(self:_flagname())) -end - --- add flags from the target -function linker:_addflags_from_target(flags, target) - - -- add the target flags - table.join2(flags, self:_mapflags(target:get(self:_flagname()))) - - -- for target options? - if target.options then - - -- add the flags for the target options - for _, opt in ipairs(target:options()) do - - -- add the flags from the option - table.join2(flags, self:_mapflags(opt:get(self:_flagname()))) - end - end -end - --- add flags from the platform -function linker:_addflags_from_platform(flags) - - -- add flags - table.join2(flags, platform.get(self:_flagname())) -end - -- add flags from the compiler function linker:_addflags_from_compiler(flags, sourcekinds) - -- done + -- make flags local flags_of_compiler = {} for _, sourcekind in ipairs(table.wrap(sourcekinds)) do -- load compiler local instance, errors = compiler.load(sourcekind) if instance then - table.join2(flags_of_compiler, instance:get(self:_flagname())) + for _, flagkind in ipairs(self:_flagkinds()) do + table.join2(flags_of_compiler, instance:get(flagkind)) + end end end @@ -100,13 +63,21 @@ end -- add flags from the linker function linker:_addflags_from_linker(flags) - -- done - table.join2(flags, self:get(self:_flagname())) + -- add flags + for _, flagkind in ipairs(self:_flagkinds()) do + table.join2(flags, self:get(flagkind)) + end end -- load the linker from the given target kind function linker.load(targetkind, sourcekinds) + -- check + assert(sourcekinds) + + -- wrap sourcekinds first + sourcekinds = table.wrap(sourcekinds) + -- get the linker info local linkerinfo, errors = language.linkerinfo_of(targetkind, sourcekinds) if not linkerinfo then @@ -151,8 +122,8 @@ function linker.load(targetkind, sourcekinds) end instance._NAMEFLAGS = nameflags - -- init flag name - instance._FLAGNAME = linkerinfo.flag + -- init flag kinds + instance._FLAGKINDS = {linkerinfo.flag} -- save this instance linker._INSTANCES[linkerinfo.kind] = instance |
