summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-29 11:06:34 +0800
committerruki <[email protected]>2015-05-29 11:06:34 +0800
commit9aa34cbeaac0f6117fc0879a4f5f7059438da3c1 (patch)
tree541e4cb20a225867bd00f67f7fcb6aec9f4fa4ad /xmake/scripts
parent6292b0f0938625902da6e3deec4877e409007708 (diff)
add compiler
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/compiler/_clang.lua44
-rw-r--r--xmake/scripts/compiler/compiler.lua126
-rw-r--r--xmake/scripts/platform/macosx/_macosx.lua36
3 files changed, 170 insertions, 36 deletions
diff --git a/xmake/scripts/compiler/_clang.lua b/xmake/scripts/compiler/_clang.lua
new file mode 100644
index 000000000..27f9b868f
--- /dev/null
+++ b/xmake/scripts/compiler/_clang.lua
@@ -0,0 +1,44 @@
+--!The Automatic Cross-_clang Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file _clang.lua
+--
+
+-- define module: _clang
+local _clang = _clang or {}
+
+-- load modules
+local utils = require("base/utils")
+local string = require("base/string")
+local config = require("base/config")
+
+-- init the compiler
+function _clang._init(configs)
+
+end
+
+-- map gcc flag to the current compiler flag
+function _clang._mapflag(configs, flag)
+
+ -- ok
+ return flag
+end
+
+-- return module: _clang
+return _clang
diff --git a/xmake/scripts/compiler/compiler.lua b/xmake/scripts/compiler/compiler.lua
new file mode 100644
index 000000000..bc84c177f
--- /dev/null
+++ b/xmake/scripts/compiler/compiler.lua
@@ -0,0 +1,126 @@
+--!The Automatic Cross-compiler Build Tool
+--
+-- XMake is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU Lesser General Public License as published by
+-- the Free Software Foundation; either version 2.1 of the License, or
+-- (at your option) any later version.
+--
+-- XMake is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU Lesser General Public License for more details.
+--
+-- You should have received a copy of the GNU Lesser General Public License
+-- along with XMake;
+-- If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2009 - 2015, ruki All rights reserved.
+--
+-- @author ruki
+-- @file compiler.lua
+--
+
+-- define module: compiler
+local compiler = compiler or {}
+
+-- load modules
+local utils = require("base/utils")
+local string = require("base/string")
+local config = require("base/config")
+
+-- get the configure from the given name
+function compiler._get(self, name)
+
+ -- check
+ assert(self and name);
+
+ -- the compiler configure
+ local configs = self._CONFIGS
+ assert(configs)
+
+ -- get it
+ return configs[name]
+end
+
+-- map gcc flags to the given compiler flags
+function compiler._mapflags(self, flags)
+
+ -- check
+ assert(self and flags);
+
+ -- need not map flags? return it directly
+ if not self.mapflag then
+ return flags
+ end
+
+ -- the configure
+ local configs = self._CONFIGS
+ assert(configs)
+
+ -- map flags
+ local flags_mapped = {}
+ for _, flag in pairs(flags) do
+ -- map it
+ local flag_mapped = self._mapflag(configs, flag)
+ if flag_mapped then
+ flags_mapped[table.getn(flags_mapped) + 1] = flag_mapped
+ end
+ end
+
+ -- ok?
+ return flag_mapped;
+end
+
+-- load the given compiler
+function compiler.load(name)
+
+ -- check
+ assert(name and type(name) == "string")
+
+ -- gcc?
+ local module = nil
+ if name:find("gcc", 1, true) then module = "gcc"
+ -- clang?
+ elseif name:find("clang", 1, true) then module = "clang"
+ -- cl.exe?
+ elseif name:find("cl.exe", 1, true) then module = "msvc"
+ -- icc?
+ elseif name:find("icc", 1, true) then module = "intel"
+ -- unknown?
+ else
+ -- error
+ utils.error("unknown compiler: %s", name)
+ return nil
+ end
+
+ -- load the given compiler
+ local c = require("compiler/_" .. module)
+ if not c then
+ return nil
+ end
+
+ -- the compiler has been loaded? return it directly
+ if c._CONFIGS then
+ return c
+ end
+
+ -- make the compiler configure
+ c._CONFIGS = {}
+ local configs = c._CONFIGS
+
+ -- init the compiler name
+ configs.name = name
+
+ -- init the compiler configure
+ c._init(configs)
+
+ -- init interfaces
+ c["get"] = compiler._get
+ c["mapflags"] = compiler._mapflags
+
+ -- ok?
+ return c
+end
+
+-- return module: compiler
+return compiler
diff --git a/xmake/scripts/platform/macosx/_macosx.lua b/xmake/scripts/platform/macosx/_macosx.lua
index 6a66d12cb..85b2822a1 100644
--- a/xmake/scripts/platform/macosx/_macosx.lua
+++ b/xmake/scripts/platform/macosx/_macosx.lua
@@ -51,42 +51,6 @@ function _macosx.make(configs)
configs.compiler.mm = config.get("mm") or configs.compiler.cc
configs.compiler.mxx = config.get("mxx") or configs.compiler.cxx
- -- init the linker
- configs.linker = {}
- configs.linker.ld = config.get("ld") or configs.compiler.cxx
-
- -- init the assembler
- configs.assembler = {}
- configs.assembler.as = config.get("as") or configs.compiler.cc
-
- -- init the cflags
- configs.compiler.cflags = {}
- configs.compiler.cflags.opti = {}
- configs.compiler.cflags.warn = {}
- configs.compiler.cflags.all = "-c"
- configs.compiler.cflags.debug = "-g"
- configs.compiler.cflags.release = "-fomit-frame-pointer -fvisibility=hidden"
- configs.compiler.cflags.profile = ""
- configs.compiler.cflags.opti.O0 = "-O0"
- configs.compiler.cflags.opti.O1 = "-O1"
- configs.compiler.cflags.opti.O2 = "-O2"
- configs.compiler.cflags.opti.O3 = "-O3"
- configs.compiler.cflags.opti.Os = "-Os"
- configs.compiler.cflags.warn.W0 = "-W0"
- configs.compiler.cflags.warn.W1 = "-W1"
- configs.compiler.cflags.warn.W2 = "-W2"
- configs.compiler.cflags.warn.W3 = "-W3"
- configs.compiler.cflags.warn.We = "-Werror"
-
- -- init the cxxflags
- configs.compiler.cxxflags = {}
- configs.compiler.cxxflags.opti = configs.compiler.cflags.opti
- configs.compiler.cxxflags.warn = configs.compiler.cflags.warn
- configs.compiler.cxxflags.all = ""
- configs.compiler.cxxflags.debug = "-g"
- configs.compiler.cxxflags.release = "-fomit-frame-pointer -fvisibility=hidden"
- configs.compiler.cxxflags.profile = ""
-
-- init xcode sdk directory
configs.xcode_sdkdir = config.get("xcode_dir") .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. config.get("xcode_sdkver") .. ".sdk"
end