summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-27 08:31:36 +0800
committerruki <[email protected]>2015-05-27 08:31:36 +0800
commit0e3df610b7db95590a9ad32eccfc7b2b2319b128 (patch)
tree306336b11034e115f68dd74df2b0d1ee9a6d44ee
parentf4562609df7ac3f395e5178e76fcefa2c1ffa980 (diff)
modify platform interfaces
-rw-r--r--xmake/scripts/action/_config.lua16
-rw-r--r--xmake/scripts/action/_global.lua16
-rw-r--r--xmake/scripts/base/main.lua40
-rw-r--r--xmake/scripts/platform/android/_android.lua8
-rw-r--r--xmake/scripts/platform/ios/_ios.lua12
-rw-r--r--xmake/scripts/platform/linux/_linux.lua8
-rw-r--r--xmake/scripts/platform/macosx/_macosx.lua112
-rw-r--r--xmake/scripts/platform/macosx/_prober.lua121
-rw-r--r--xmake/scripts/platform/platform.lua21
-rw-r--r--xmake/scripts/platform/windows/_windows.lua8
10 files changed, 201 insertions, 161 deletions
diff --git a/xmake/scripts/action/_config.lua b/xmake/scripts/action/_config.lua
index 71d4d45af..841e84fe2 100644
--- a/xmake/scripts/action/_config.lua
+++ b/xmake/scripts/action/_config.lua
@@ -27,26 +27,10 @@ local _config = _config or {}
local utils = require("base/utils")
local config = require("base/config")
local makefile = require("base/makefile")
-local platform = require("platform/platform")
-- done the given config
function _config.done()
- -- wrap the global configure for more convenient to get and set values
- local config_wrapped = {}
- setmetatable(config_wrapped,
- {
- __index = function(tbl, key)
- return config.get(key)
- end,
- __newindex = function(tbl, key, val)
- config.set(key, val)
- end
- })
-
- -- probe the configure
- platform.probe(config_wrapped, false)
-
-- dump config
config.dump()
diff --git a/xmake/scripts/action/_global.lua b/xmake/scripts/action/_global.lua
index d911a3ba2..fc4113aff 100644
--- a/xmake/scripts/action/_global.lua
+++ b/xmake/scripts/action/_global.lua
@@ -26,26 +26,10 @@ local _global = _global or {}
-- load modules
local utils = require("base/utils")
local global = require("base/global")
-local platform = require("platform/platform")
-- done the given config
function _global.done()
- -- wrap the global configure for more convenient to get and set values
- local global_wrapped = {}
- setmetatable(global_wrapped,
- {
- __index = function(tbl, key)
- return global.get(key)
- end,
- __newindex = function(tbl, key, val)
- global.set(key, val)
- end
- })
-
- -- probe the global configure
- platform.probe(global_wrapped, true)
-
-- dump global
global.dump()
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index d65df8ad9..7d448fc57 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -398,6 +398,21 @@ function main._done_global()
-- load global configure
global.loadxconf()
+ -- wrap the global configure for more convenient to get and set values
+ local global_wrapped = {}
+ setmetatable(global_wrapped,
+ {
+ __index = function(tbl, key)
+ return global.get(key)
+ end,
+ __newindex = function(tbl, key, val)
+ global.set(key, val)
+ end
+ })
+
+ -- probe the global platform configure
+ platform.probe(global_wrapped, true)
+
-- done action
return action.done("global")
end
@@ -427,10 +442,29 @@ function main._done_option()
return false
end
- -- init platform
- if not platform.init() then
+ -- xmake config?
+ if options._ACTION == "config" then
+
+ -- wrap the global configure for more convenient to get and set values
+ local config_wrapped = {}
+ setmetatable(config_wrapped,
+ {
+ __index = function(tbl, key)
+ return config.get(key)
+ end,
+ __newindex = function(tbl, key, val)
+ config.set(key, val)
+ end
+ })
+
+ -- probe the current platform configure
+ platform.probe(config_wrapped, false)
+ end
+
+ -- make the current platform configure
+ if not platform.make() then
-- error
- utils.error("init platform: %s failed!", config.get("plat"))
+ utils.error("make platform configure: %s failed!", config.get("plat"))
return false
end
diff --git a/xmake/scripts/platform/android/_android.lua b/xmake/scripts/platform/android/_android.lua
index 630c95ab1..93920dcc6 100644
--- a/xmake/scripts/platform/android/_android.lua
+++ b/xmake/scripts/platform/android/_android.lua
@@ -23,11 +23,11 @@
-- define module: _android
local _android = _android or {}
--- init _android
-function _android.init(configs)
+-- init host
+_android._HOST = xmake._HOST
- -- init host
- configs.host = xmake._HOST
+-- make configure
+function _android.make(configs)
-- init the file name formats
configs.formats = {}
diff --git a/xmake/scripts/platform/ios/_ios.lua b/xmake/scripts/platform/ios/_ios.lua
index 8cc91c62b..1cf1a135c 100644
--- a/xmake/scripts/platform/ios/_ios.lua
+++ b/xmake/scripts/platform/ios/_ios.lua
@@ -23,11 +23,11 @@
-- define module: _ios
local _ios = _ios or {}
--- init _ios
-function _ios.init(configs)
+-- init host
+_ios._HOST = "macosx"
- -- init host
- configs.host = "macosx"
+-- make configure
+function _ios.make(configs)
-- init the file name formats
configs.formats = {}
@@ -55,7 +55,7 @@ function _ios.menu(action)
, {nil, "mxflags", "kv", nil, "The Objc/c++ Compiler Flags" }
, {nil, "mxxflags", "kv", nil, "The Objc++ Compiler Flags" }
, {}
- , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" }
+ , {nil, "xcode_dir", "kv", "auto", "The Xcode Application Directory" }
, {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" }
, {}
, {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" }
@@ -66,7 +66,7 @@ function _ios.menu(action)
-- init global option menu
_ios._MENU_GLOBAL = _ios._MENU_GLOBAL or
{ {}
- , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" }
+ , {nil, "xcode_dir", "kv", "auto", "The Xcode Application Directory" }
, {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" }
, {}
, {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" }
diff --git a/xmake/scripts/platform/linux/_linux.lua b/xmake/scripts/platform/linux/_linux.lua
index 51e3ee89a..e33a81d8f 100644
--- a/xmake/scripts/platform/linux/_linux.lua
+++ b/xmake/scripts/platform/linux/_linux.lua
@@ -23,11 +23,11 @@
-- define module: _linux
local _linux = _linux or {}
--- init _linux
-function _linux.init(configs)
+-- init host
+_linux._HOST = "linux"
- -- init host
- configs.host = "linux"
+-- make configure
+function _linux.make(configs)
-- init the file name formats
configs.formats = {}
diff --git a/xmake/scripts/platform/macosx/_macosx.lua b/xmake/scripts/platform/macosx/_macosx.lua
index e42b1c81f..2dcdf4b06 100644
--- a/xmake/scripts/platform/macosx/_macosx.lua
+++ b/xmake/scripts/platform/macosx/_macosx.lua
@@ -20,20 +20,24 @@
-- @file _macosx.lua
--
+-- define module: _macosx
+local _macosx = _macosx or {}
+
-- load modules
local os = require("base/os")
local path = require("base/path")
local utils = require("base/utils")
+local config = require("base/config")
local string = require("base/string")
--- define module: _macosx
-local _macosx = _macosx or {}
+-- init host
+_macosx._HOST = "macosx"
--- init configure
-function _macosx.init(configs)
+-- init prober
+_macosx._PROBER = require("platform/macosx/_prober")
- -- init host
- configs.host = "macosx"
+-- make configure
+function _macosx.make(configs)
-- init the file name formats
configs.formats = {}
@@ -41,99 +45,13 @@ function _macosx.init(configs)
configs.formats.object = {"", ".o"}
configs.formats.shared = {"", ".dylib"}
- -- init the architecture scopes
+ -- init the architectures
configs.archs = {}
configs.archs.x86 = {}
configs.archs.x64 = {}
-end
-
--- probe the xcode application directory
-function _macosx._probe_xcode(configs)
-
- -- get the xcode
- local xcode = configs.xcode
-
- -- ok?
- if xcode and xcode ~= "auto" then return true end
-
- -- clear it first
- xcode = nil
-
- -- attempt to get the default directory
- if not xcode then
- if os.isdir("/Applications/Xcode.app") then
- xcode = "/Applications/Xcode.app"
- end
- end
-
- -- attempt to match the other directories
- if not xcode then
- local dirs = os.match("/Applications/Xcode*.app", true)
- if dirs and table.getn(dirs) ~= 0 then
- xcode = dirs[1]
- end
- end
-
- -- probe ok? update it
- if xcode then
- configs.xcode = xcode
- else
- -- failed
- utils.error("The Xcode directory is unknown now, please config it first!")
- utils.error(" - xmake config --xcode=xxx")
- utils.error("or - xmake global --xcode=xxx")
- return false
- end
-
- -- ok
- return true
-end
-
--- probe the xcode sdk version
-function _macosx._probe_xcode_sdkver(configs)
-
- -- get the xcode sdk version
- local xcode_sdkver = configs.xcode_sdkver
-
- -- ok?
- if xcode_sdkver and xcode_sdkver ~= "auto" then return true end
-
- -- clear it first
- xcode_sdkver = nil
-
- -- attempt to match the directory
- if not xcode_sdkver then
- local dirs = os.match("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX*.sdk", true)
- if dirs and table.getn(dirs) ~= 0 then
- xcode_sdkver = string.match(dirs[1], "%d+%.%d+")
- end
- end
-
- -- probe ok? update it
- if xcode_sdkver then
- configs.xcode_sdkver = xcode_sdkver
- else
- -- failed
- utils.error("The Xcode SDK version is unknown now, please config it first!")
- utils.error(" - xmake config --xcode_sdkver=xxx")
- utils.error("or - xmake global --xcode_sdkver=xxx")
- return false
- end
-
- -- ok
- return true
-end
-
--- probe the configure and update the values with "auto"
-function _macosx.probe(configs)
-
- -- probe the xcode application directory
- if not _macosx._probe_xcode(configs) then return end
-
- -- probe the xcode sdk version
- if not _macosx._probe_xcode_sdkver(configs) then return end
-
+ -- 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
-- get the option menu for action: xmake config or global
@@ -149,14 +67,14 @@ function _macosx.menu(action)
, {nil, "mxflags", "kv", nil, "The Objc/c++ Compiler Flags" }
, {nil, "mxxflags", "kv", nil, "The Objc++ Compiler Flags" }
, {}
- , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" }
+ , {nil, "xcode_dir", "kv", "auto", "The Xcode Application Directory" }
, {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" }
, }
-- init global option menu
_macosx._MENU_GLOBAL = _macosx._MENU_GLOBAL or
{ {}
- , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" }
+ , {nil, "xcode_dir", "kv", "auto", "The Xcode Application Directory" }
, {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" }
, }
diff --git a/xmake/scripts/platform/macosx/_prober.lua b/xmake/scripts/platform/macosx/_prober.lua
new file mode 100644
index 000000000..8b12894de
--- /dev/null
+++ b/xmake/scripts/platform/macosx/_prober.lua
@@ -0,0 +1,121 @@
+--!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 _prober.lua
+--
+
+-- load modules
+local os = require("base/os")
+local path = require("base/path")
+local utils = require("base/utils")
+local string = require("base/string")
+
+-- define module: _prober
+local _prober = _prober or {}
+
+-- probe the xcode application directory
+function _prober._probe_xcode(configs)
+
+ -- get the xcode directory
+ local xcode_dir = configs.xcode_dir
+
+ -- ok?
+ if xcode_dir and xcode_dir ~= "auto" then return true end
+
+ -- clear it first
+ xcode_dir = nil
+
+ -- attempt to get the default directory
+ if not xcode_dir then
+ if os.isdir("/Applications/Xcode.app") then
+ xcode_dir = "/Applications/Xcode.app"
+ end
+ end
+
+ -- attempt to match the other directories
+ if not xcode_dir then
+ local dirs = os.match("/Applications/Xcode*.app", true)
+ if dirs and table.getn(dirs) ~= 0 then
+ xcode_dir = dirs[1]
+ end
+ end
+
+ -- probe ok? update it
+ if xcode_dir then
+ configs.xcode_dir = xcode_dir
+ else
+ -- failed
+ utils.error("The Xcode directory is unknown now, please config it first!")
+ utils.error(" - xmake config --xcode_dir=xxx")
+ utils.error("or - xmake global --xcode_dir=xxx")
+ return false
+ end
+
+ -- ok
+ return true
+end
+
+-- probe the xcode sdk version
+function _prober._probe_xcode_sdkver(configs)
+
+ -- get the xcode sdk version
+ local xcode_sdkver = configs.xcode_sdkver
+
+ -- ok?
+ if xcode_sdkver and xcode_sdkver ~= "auto" then return true end
+
+ -- clear it first
+ xcode_sdkver = nil
+
+ -- attempt to match the directory
+ if not xcode_sdkver then
+ local dirs = os.match(configs.xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX*.sdk", true)
+ if dirs and table.getn(dirs) ~= 0 then
+ xcode_sdkver = string.match(dirs[1], "%d+%.%d+")
+ end
+ end
+
+ -- probe ok? update it
+ if xcode_sdkver then
+ configs.xcode_sdkver = xcode_sdkver
+ else
+ -- failed
+ utils.error("The Xcode SDK version is unknown now, please config it first!")
+ utils.error(" - xmake config --xcode_sdkver=xxx")
+ utils.error("or - xmake global --xcode_sdkver=xxx")
+ return false
+ end
+
+ -- ok
+ return true
+end
+
+-- probe the configure and update the values with "auto"
+function _prober.done(configs)
+
+ -- probe the xcode application directory
+ if not _prober._probe_xcode(configs) then return end
+
+ -- probe the xcode sdk version
+ if not _prober._probe_xcode_sdkver(configs) then return end
+
+end
+
+-- return module: _prober
+return _prober
diff --git a/xmake/scripts/platform/platform.lua b/xmake/scripts/platform/platform.lua
index dc5c9616e..4cc5df0da 100644
--- a/xmake/scripts/platform/platform.lua
+++ b/xmake/scripts/platform/platform.lua
@@ -52,22 +52,22 @@ function platform._configs(plat)
local p = platform._load(plat)
if p then
- -- make configure
+ -- init configure
platform._CONFIGS[plat]= {}
configs = platform._CONFIGS[plat]
- -- init configure
- p.init(configs)
+ -- make configure
+ p.make(configs)
end
-- ok?
return configs
end
--- init platform
-function platform.init()
+-- make the current platform configure
+function platform.make()
- -- init the current platform
+ -- make and get the current platform configure
return platform._configs(config.get("plat"))
end
@@ -221,9 +221,8 @@ function platform.probe(configs, is_global)
-- probe all platforms with the current host
for _, plat in ipairs(plats) do
local p = platform._load(plat)
- local c = platform._configs(plat)
- if p and p.probe and c and c.host and c.host == xmake._HOST then
- p.probe(configs)
+ if p and p._PROBER and p._PROBER.done and p._HOST and p._HOST == xmake._HOST then
+ p._PROBER.done(configs)
end
end
@@ -231,8 +230,8 @@ function platform.probe(configs, is_global)
else
-- probe it
local p = platform._load(config.get("plat"))
- if p and p.probe then
- p.probe(configs)
+ if p and p._PROBER and p._PROBER.done then
+ p._PROBER.done(configs)
end
end
end
diff --git a/xmake/scripts/platform/windows/_windows.lua b/xmake/scripts/platform/windows/_windows.lua
index 793de81b0..293958dae 100644
--- a/xmake/scripts/platform/windows/_windows.lua
+++ b/xmake/scripts/platform/windows/_windows.lua
@@ -23,11 +23,11 @@
-- define module: _windows
local _windows = _windows or {}
--- init _windows
-function _windows.init(configs)
+-- init host
+_windows._HOST = "windows"
- -- init host
- configs.host = "windows"
+-- make configure
+function _windows.make(configs)
-- init the file name formats
configs.formats = {}