diff options
| author | ruki <[email protected]> | 2016-04-14 09:24:24 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2016-04-14 09:24:24 +0800 |
| commit | 9e736d8b83930330edaee2958b4c66093ca87e37 (patch) | |
| tree | cefcd89bbc72f1aac02535699f97626560be12ab /xmake/core/tool/compiler.lua | |
| parent | 733935aec221c1bce476e7cfea7b5e64d280f71e (diff) | |
reimpl compiler and linker
Diffstat (limited to 'xmake/core/tool/compiler.lua')
| -rw-r--r-- | xmake/core/tool/compiler.lua | 88 |
1 files changed, 46 insertions, 42 deletions
diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 294a9c6c0..34510efd0 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -30,8 +30,8 @@ local utils = require("base/utils") local table = require("base/table") local string = require("base/string") local config = require("project/config") -local tool = require("tool/tool") local platform = require("platform/platform") +local tool = require("tool/tool") -- get the current tool function compiler:_tool() @@ -47,32 +47,6 @@ function compiler:_flagnames() return self._FLAGNAMES end --- get the compiler kind of the source file -function compiler._kind_of_file(srcfile) - - -- get the source file type - local filetype = path.extension(srcfile) - if not filetype then - return nil - end - - -- the kinds - local kinds = - { - [".c"] = "cc" - , [".cc"] = "cxx" - , [".cpp"] = "cxx" - , [".m"] = "mm" - , [".mm"] = "mxx" - , [".s"] = "as" - , [".asm"] = "as" - , [".swift"] = "sc" - } - - -- get kind - return kinds[filetype:lower()] -end - -- get the flags function compiler:_flags(target) @@ -280,7 +254,7 @@ function compiler:_addflags_from_target(flags, target) if target.options then -- add the flags for the target options - for name, opt in pairs(target:options()) do + for _, opt in pairs(target:options()) do -- add the flags from the option self:_addflags_from_target(flags, opt) @@ -344,6 +318,32 @@ function compiler:_addflags_from_compiler(flags, kind) end end +-- get the compiler kind of the source file +function compiler.kind_of_file(srcfile) + + -- get the source file type + local filetype = path.extension(srcfile) + if not filetype then + return nil + end + + -- the kinds + local kinds = + { + [".c"] = "cc" + , [".cc"] = "cxx" + , [".cpp"] = "cxx" + , [".m"] = "mm" + , [".mm"] = "mxx" + , [".s"] = "as" + , [".asm"] = "as" + , [".swift"] = "sc" + } + + -- get kind + return kinds[filetype:lower()] +end + -- get the current kind function compiler:kind() @@ -351,26 +351,23 @@ function compiler:kind() return self._KIND end --- load the compiler from the given source file -function compiler.load(srcfile) +-- load the compiler from the given source kind +function compiler.load(sourcekind) - -- get the compiler kind - local kind = compiler._kind_of_file(srcfile) - if not kind then - return nil, string.format("unknown source file: %s", srcfile) - end + -- check + assert(sourcekind) -- get it directly from cache dirst compiler._INSTANCES = compiler._INSTANCES or {} - if compiler._INSTANCES[kind] then - return compiler._INSTANCES[kind] + if compiler._INSTANCES[sourcekind] then + return compiler._INSTANCES[sourcekind] end -- new instance local instance = table.inherit(compiler) -- load the compiler tool from the source file type - local result, errors = tool.load(kind) + local result, errors = tool.load(sourcekind) if not result then return nil, errors end @@ -379,7 +376,7 @@ function compiler.load(srcfile) instance._TOOL = result -- save kind - instance._KIND = kind + instance._KIND = sourcekind -- save flagnames local flagnames = @@ -391,20 +388,27 @@ function compiler.load(srcfile) , as = { "asflags" } , sc = { "scflags" } } - instance._FLAGNAMES = flagnames[kind] + instance._FLAGNAMES = flagnames[sourcekind] -- check if not instance._FLAGNAMES then - return nil, string.format("unknown compiler for kind: %s", kind) + return nil, string.format("unknown compiler for kind: %s", sourcekind) end -- save this instance - compiler._INSTANCES[kind] = instance + compiler._INSTANCES[sourcekind] = instance -- ok return instance end +-- get properties of the tool +function compiler:get(name) + + -- get it + return self:_tool():get(name) +end + -- run the command function compiler:run(cmd) |
