diff options
| author | ruki <[email protected]> | 2015-06-02 09:35:37 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-02 09:35:37 +0800 |
| commit | f6177ffb405aa474e5d8e8af787778bd8ed8439c (patch) | |
| tree | c4520100c7b617a4ef54f137f2f8acb13d98f5ab /xmake/scripts/compiler/compiler.lua | |
| parent | 52b7de2f4d73e08aba2fea79aa04bb06a9af449d (diff) | |
add linker and compiler common flags
Diffstat (limited to 'xmake/scripts/compiler/compiler.lua')
| -rw-r--r-- | xmake/scripts/compiler/compiler.lua | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/xmake/scripts/compiler/compiler.lua b/xmake/scripts/compiler/compiler.lua index 9a6192b26..7b52bd951 100644 --- a/xmake/scripts/compiler/compiler.lua +++ b/xmake/scripts/compiler/compiler.lua @@ -24,6 +24,7 @@ local compiler = compiler or {} -- load modules +local path = require("base/path") local utils = require("base/utils") local string = require("base/string") local config = require("base/config") @@ -58,17 +59,35 @@ function compiler._mapflags(self, flags) end -- make the compile command -function compiler._make(self, srcfile, objfile, flags) +function compiler._make(self, filetype, srcfile, objfile, flags) -- check - assert(self); + assert(self and filetype); -- the configure local configs = self._CONFIGS assert(configs) + -- get the common flags string for the current compiler + local flags_common = nil + if filetype == "cc" then flags_common = configs.cflags + elseif filetype == "cxx" then flags_common = configs.cxxflags + elseif filetype == "mm" then flags_common = configs.mflags + elseif filetype == "mxx" then flags_common = configs.mxxflags + elseif filetype == "as" then flags_common = configs.asflags + end + flags_common = flags_common or "" + + -- map flags + flags = compiler._mapflags(self, utils.wrap(flags)) + assert(flags) + + -- make flags string + flags = table.concat(flags) + assert(flags) + -- get it - return self._make(configs, srcfile, objfile, compiler._mapflags(self, flags)) + return self._make(configs, srcfile, objfile, flags_common .. " " .. flags) end -- load the given compiler @@ -85,7 +104,9 @@ function compiler.load(name) -- cl.exe? elseif name:find("cl.exe", 1, true) then module = "msvc" -- icc? - elseif name:find("icc", 1, true) then module = "intel" + elseif name:find("icc", 1, true) then module = "icc" + -- as? + elseif name:find("as", 1, true) then module = "as" -- unknown? else -- error @@ -120,6 +141,31 @@ function compiler.load(name) -- ok? return c end + +-- get the source file type +function compiler.filetype(srcfile) + + -- get the source file type + local filetype = path.extension(srcfile) + if not filetype then + return nil + end + + -- get the lower file type + filetype = filetype:lower() + + -- get the compiler name + local name = nil + if filetype == ".c" then name = "cc" + elseif filetype == ".cpp" or filetype == ".cc" then name = "cxx" + elseif filetype == ".m" then name = "mm" + elseif filetype == ".mm" then name = "mxx" + elseif filetype == ".s" or filetype == ".asm" then name = "as" + end + + -- ok + return name +end -- return module: compiler return compiler |
