summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-02 16:58:26 +0800
committerruki <[email protected]>2015-06-02 16:58:26 +0800
commitebebee003da8aa7092a69d0efef7f69a7635d59b (patch)
tree9120c277bea75725e1fb48a4f7f74c9f594aff1b /xmake/scripts
parentf639faef588a95b28ec02c781dee2a581f7a7992 (diff)
improve to make project configs
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/base/project.lua48
-rw-r--r--xmake/scripts/compiler/_clang.lua2
-rw-r--r--xmake/scripts/compiler/_msvc.lua91
-rw-r--r--xmake/scripts/compiler/compiler.lua2
-rw-r--r--xmake/scripts/linker/_ar.lua2
-rw-r--r--xmake/scripts/linker/_clang.lua2
-rw-r--r--xmake/scripts/linker/_msvc.lua82
-rw-r--r--xmake/scripts/linker/linker.lua2
-rw-r--r--xmake/scripts/platform/windows/_windows.lua12
9 files changed, 216 insertions, 27 deletions
diff --git a/xmake/scripts/base/project.lua b/xmake/scripts/base/project.lua
index 888283562..ce6397163 100644
--- a/xmake/scripts/base/project.lua
+++ b/xmake/scripts/base/project.lua
@@ -32,7 +32,7 @@ local preprocessor = require("base/preprocessor")
function project._make_configs(scope, configs)
-- check
- assert(scope and configs)
+ assert(configs)
-- the current mode
local mode = config.get("mode")
@@ -48,8 +48,24 @@ function project._make_configs(scope, configs)
-- check
assert(type(k) == "string")
+ -- enter the target configure?
+ if k == "_TARGET" then
+
+ -- the current
+ local current = project._CURRENT
+
+ -- init all targets
+ for _k, _v in pairs(v) do
+
+ -- init target scope first
+ current[_k] = current[_k] or {}
+
+ -- make the target configure to this scope
+ project._make_configs(current[_k], _v)
+ end
+
-- enter the platform configure?
- if k == "_PLATFORMS" then
+ elseif k == "_PLATFORMS" then
-- append configure to scope for the current mode
for _k, _v in pairs(v) do
@@ -69,7 +85,7 @@ function project._make_configs(scope, configs)
end
-- append configure to scope
- elseif not k:startswith("_") and k:endswith("s") then
+ elseif scope and not k:startswith("_") and k:endswith("s") then
-- wrap it first
local values = utils.wrap(v)
@@ -85,7 +101,7 @@ function project._make_configs(scope, configs)
item[table.getn(item) + 1] = _v
end
-- replace configure to scope
- elseif not k:startswith("_") then
+ elseif scope and not k:startswith("_") then
-- wrap it first
local values = utils.wrap(v)
@@ -107,28 +123,16 @@ function project._make()
-- the configs
local configs = project._CONFIGS
- assert(configs and configs._TARGET)
-
- -- init current config
+ assert(configs)
+
+ -- init current
project._CURRENT = project._CURRENT or {}
- local current = project._CURRENT
-
- -- init all targets
- for name, target in pairs(configs._TARGET) do
-
- -- init target scope first
- current[name] = current[name] or {}
- local scope = current[name]
- -- make the root configure to this scope
- project._make_configs(scope, configs)
-
- -- make the target configure to this scope
- project._make_configs(scope, target)
- end
+ -- make the root configure to the current scope
+ project._make_configs(nil, configs)
-- remove repeat values and unwrap it
- for _, target in pairs(current) do
+ for _, target in pairs(project._CURRENT) do
for k, v in pairs(target) do
-- remove repeat first
diff --git a/xmake/scripts/compiler/_clang.lua b/xmake/scripts/compiler/_clang.lua
index 00b49c47f..4b66e3924 100644
--- a/xmake/scripts/compiler/_clang.lua
+++ b/xmake/scripts/compiler/_clang.lua
@@ -1,4 +1,4 @@
---!The Automatic Cross-_clang Build Tool
+--!The Automatic Cross-platform 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
diff --git a/xmake/scripts/compiler/_msvc.lua b/xmake/scripts/compiler/_msvc.lua
new file mode 100644
index 000000000..0ebb3743e
--- /dev/null
+++ b/xmake/scripts/compiler/_msvc.lua
@@ -0,0 +1,91 @@
+--!The Automatic Cross-platform 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 _msvc.lua
+--
+
+-- define module: _msvc
+local _msvc = _msvc or {}
+
+-- load modules
+local utils = require("base/utils")
+local string = require("base/string")
+local config = require("base/config")
+
+-- init the compiler
+function _msvc._init(configs)
+
+ -- the architecture
+ local arch = config.get("arch")
+ assert(arch)
+
+ -- init flags for architecture
+ local flags_arch = ""
+ if arch == "x86" then flags_arch = "-m32"
+ elseif arch == "x64" then flags_arch = "-m64"
+ else flags_arch = "-arch " .. arch
+ end
+
+ -- init cflags
+ configs.cflags = flags_arch
+
+ -- init cxxflags
+ configs.cxxflags = flags_arch
+
+ -- init mflags
+ configs.mflags = flags_arch
+
+ -- init mxxflags
+ configs.mxxflags = flags_arch
+
+ -- init asflags
+ configs.asflags = flags_arch
+
+end
+
+-- make the compiler command
+function _msvc._make(configs, srcfile, objfile, flags)
+
+ -- make it
+ return string.format("%s -c %s -o%s %s", configs.name, flags, objfile, srcfile)
+end
+
+-- make the define flag
+function _msvc._make_define(configs, define)
+
+ -- make it
+ return "-D" .. define
+end
+
+-- make the includedir flag
+function _msvc._make_includedir(configs, includedir)
+
+ -- make it
+ return "-I" .. includedir
+end
+
+-- map gcc flag to the current compiler flag
+function _msvc._mapflag(configs, flag)
+
+ -- ok
+ return flag
+end
+
+-- return module: _msvc
+return _msvc
diff --git a/xmake/scripts/compiler/compiler.lua b/xmake/scripts/compiler/compiler.lua
index ac25f176a..e1dbb9658 100644
--- a/xmake/scripts/compiler/compiler.lua
+++ b/xmake/scripts/compiler/compiler.lua
@@ -1,4 +1,4 @@
---!The Automatic Cross-compiler Build Tool
+--!The Automatic Cross-platform 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
diff --git a/xmake/scripts/linker/_ar.lua b/xmake/scripts/linker/_ar.lua
index c65fa41f2..c45dbaccb 100644
--- a/xmake/scripts/linker/_ar.lua
+++ b/xmake/scripts/linker/_ar.lua
@@ -1,4 +1,4 @@
---!The Automatic Cross-_ar Build Tool
+--!The Automatic Cross-platform 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
diff --git a/xmake/scripts/linker/_clang.lua b/xmake/scripts/linker/_clang.lua
index 7cb0ed859..f51efae3d 100644
--- a/xmake/scripts/linker/_clang.lua
+++ b/xmake/scripts/linker/_clang.lua
@@ -1,4 +1,4 @@
---!The Automatic Cross-_clang Build Tool
+--!The Automatic Cross-platform 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
diff --git a/xmake/scripts/linker/_msvc.lua b/xmake/scripts/linker/_msvc.lua
new file mode 100644
index 000000000..a49b0827e
--- /dev/null
+++ b/xmake/scripts/linker/_msvc.lua
@@ -0,0 +1,82 @@
+--!The Automatic Cross-platform 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 _msvc.lua
+--
+
+-- define module: _msvc
+local _msvc = _msvc or {}
+
+-- load modules
+local utils = require("base/utils")
+local string = require("base/string")
+local config = require("base/config")
+
+-- init the linker
+function _msvc._init(configs)
+
+ -- the architecture
+ local arch = config.get("arch")
+ assert(arch)
+
+ -- init flags for architecture
+ local flags_arch = ""
+ if arch == "x86" then flags_arch = "-m32"
+ elseif arch == "x64" then flags_arch = "-m64"
+ else flags_arch = "-arch " .. arch
+ end
+
+ -- init ldflags
+ configs.ldflags = flags_arch
+
+ -- init shflags
+ configs.shflags = flags_arch .. " -dynamiclib"
+
+end
+
+-- make the command
+function _msvc._make(configs, objfiles, targetfile, flags)
+
+ -- make it
+ return string.format("%s %s -o%s %s", configs.name, flags, targetfile, objfiles)
+end
+
+-- make the link flag
+function _msvc._make_link(configs, link)
+
+ -- make it
+ return "-l" .. link
+end
+
+-- make the linkdir flag
+function _msvc._make_linkdir(configs, linkdir)
+
+ -- make it
+ return "-L" .. linkdir
+end
+
+-- map gcc flag to the current linker flag
+function _msvc._mapflag(configs, flag)
+
+ -- ok
+ return flag
+end
+
+-- return module: _msvc
+return _msvc
diff --git a/xmake/scripts/linker/linker.lua b/xmake/scripts/linker/linker.lua
index 15a15fdc3..efccdbfb1 100644
--- a/xmake/scripts/linker/linker.lua
+++ b/xmake/scripts/linker/linker.lua
@@ -1,4 +1,4 @@
---!The Automatic Cross-linker Build Tool
+--!The Automatic Cross-platform 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
diff --git a/xmake/scripts/platform/windows/_windows.lua b/xmake/scripts/platform/windows/_windows.lua
index a2feb23fa..cfe3e422d 100644
--- a/xmake/scripts/platform/windows/_windows.lua
+++ b/xmake/scripts/platform/windows/_windows.lua
@@ -44,6 +44,18 @@ function _windows.make(configs)
configs.format.object = {"", ".obj"}
configs.format.shared = {"", ".dll"}
configs.format.execute = {"", ".exe"}
+
+ -- init the compiler
+ configs.compiler = {}
+ configs.compiler.cc = config.get("cc") or "cl.exe"
+ configs.compiler.cxx = config.get("cxx") or "cl.exe"
+
+ -- init the linker
+ configs.linker = {}
+ configs.linker.binary = config.get("ld") or "link.exe"
+ configs.linker.static = config.get("ar") or "link.exe"
+ configs.linker.shared = config.get("sh") or "link.exe"
+
end
-- get the option menu for action: xmake config or global