summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-26 10:19:43 +0800
committerruki <[email protected]>2015-05-26 10:19:43 +0800
commitf4562609df7ac3f395e5178e76fcefa2c1ffa980 (patch)
tree526caad47b590de1be57996ee19b28d4e34d082a /xmake/scripts
parent49ae120e090b2d4dd15e486ade2dfc2ea1ded440 (diff)
probe configure for macosx
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/action/_config.lua21
-rw-r--r--xmake/scripts/action/_global.lua33
-rw-r--r--xmake/scripts/base/config.lua21
-rw-r--r--xmake/scripts/base/global.lua19
-rw-r--r--xmake/scripts/base/main.lua58
-rw-r--r--xmake/scripts/platform/android/_android.lua11
-rw-r--r--xmake/scripts/platform/ios/_ios.lua33
-rw-r--r--xmake/scripts/platform/linux/_linux.lua7
-rw-r--r--xmake/scripts/platform/macosx/_macosx.lua121
-rw-r--r--xmake/scripts/platform/platform.lua29
-rw-r--r--xmake/scripts/platform/windows/_windows.lua11
11 files changed, 281 insertions, 83 deletions
diff --git a/xmake/scripts/action/_config.lua b/xmake/scripts/action/_config.lua
index 46e123800..71d4d45af 100644
--- a/xmake/scripts/action/_config.lua
+++ b/xmake/scripts/action/_config.lua
@@ -27,11 +27,30 @@ 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()
- -- save configs
+ -- 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()
+
+ -- save the configure
if not config.savexconf() then
-- error
utils.error("save configure failed!")
diff --git a/xmake/scripts/action/_global.lua b/xmake/scripts/action/_global.lua
index daf7774e4..d911a3ba2 100644
--- a/xmake/scripts/action/_global.lua
+++ b/xmake/scripts/action/_global.lua
@@ -17,20 +17,39 @@
-- Copyright (C) 2009 - 2015, ruki All rights reserved.
--
-- @author ruki
--- @file _config.lua
+-- @file _global.lua
--
--- define module: _config
-local _config = _config or {}
+-- define module: _global
+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 _config.done()
+function _global.done()
- -- save globals
+ -- 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()
+
+ -- save the global configure
if not global.savexconf() then
-- error
utils.error("save configure failed!")
@@ -42,5 +61,5 @@ function _config.done()
return true
end
--- return module: _config
-return _config
+-- return module: _global
+return _global
diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua
index 2e64e2430..e6b4dbfdd 100644
--- a/xmake/scripts/base/config.lua
+++ b/xmake/scripts/base/config.lua
@@ -207,6 +207,23 @@ function config.get(name)
return config._CURRENT[name]
end
+-- set the given configure to the current
+function config.set(name, value)
+
+ -- check
+ assert(config._CURRENT and name and value)
+
+ -- get the current target
+ local target = config._target()
+ assert(target)
+
+ -- set it to the current target configure for saving to file
+ target[name] = value
+
+ -- set it to the current configure
+ config._CURRENT[name] = value
+end
+
-- save xmake.xconf
function config.savexconf()
@@ -340,9 +357,7 @@ function config.dump()
assert(config._CURRENT)
-- dump
- if xmake._OPTIONS.verbose then
- utils.dump(config._CURRENT)
- end
+ utils.dump(config._CURRENT)
end
diff --git a/xmake/scripts/base/global.lua b/xmake/scripts/base/global.lua
index c50fa70cf..0a6b93042 100644
--- a/xmake/scripts/base/global.lua
+++ b/xmake/scripts/base/global.lua
@@ -136,6 +136,21 @@ function global.get(name)
return global._CURRENT[name]
end
+-- set the given configure to the current
+function global.set(name, value)
+
+ -- check
+ assert(global._CURRENT and global._CONFIGS)
+ assert(name and value)
+
+ -- set it to the current configure
+ global._CURRENT[name] = value
+
+ -- set it to the configure for saving to file
+ global._CONFIGS[name] = value
+
+end
+
-- save xmake.xconf
function global.savexconf()
@@ -248,9 +263,7 @@ function global.dump()
assert(global._CURRENT)
-- dump
- if xmake._OPTIONS.verbose then
- utils.dump(global._CURRENT)
- end
+ utils.dump(global._CURRENT)
end
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index e983d4da5..d65df8ad9 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -67,9 +67,9 @@ local menu =
, {'f', "file", "kv", "xmake.xproj","Read a given xmake.xproj file." }
, {'P', "project", "kv", nil, "Change to the given project directory."
, "Search priority:"
- , " 1. the given command argument"
- , " 2. the envirnoment variable: XMAKE_PROJECT_DIR"
- , " 3. the current directory" }
+ , " 1. The Given Command Argument"
+ , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
+ , " 3. The Current Directory" }
, {}
@@ -101,9 +101,9 @@ local menu =
, {'f', "file", "kv", "xmake.xproj","Create a given xmake.xproj file." }
, {'P', "project", "kv", nil, "Create from the given project directory."
, "Search priority:"
- , " 1. the given command argument"
- , " 2. the envirnoment variable: XMAKE_PROJECT_DIR"
- , " 3. the current directory" }
+ , " 1. The Given Command Argument"
+ , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
+ , " 3. The Current Directory" }
, {'l', "language", "kv", "c", "The project language"
, " - c"
, " - c++"
@@ -190,20 +190,20 @@ local menu =
, {nil, "toolchains", "kv", nil, "The cross toolchains directory" }
, {}
- , {nil, "cc", "kv", "gcc", "The c compiler" }
- , {nil, "cx", "kv", "gcc", "The c/c++ compiler" }
- , {nil, "cxx", "kv", "gcc", "The c++ compiler" }
- , {nil, "cflags", "kv", nil, "The c compiler flags" }
- , {nil, "cxflags", "kv", nil, "The c/c++ compiler flags" }
- , {nil, "cxxflags", "kv", nil, "The c++ compiler flags" }
+ , {nil, "cc", "kv", "gcc", "The C Compiler" }
+ , {nil, "cx", "kv", "gcc", "The C/C++ Compiler" }
+ , {nil, "cxx", "kv", "gcc", "The C++ Compiler" }
+ , {nil, "cflags", "kv", nil, "The C Compiler Flags" }
+ , {nil, "cxflags", "kv", nil, "The C/C++ compiler Flags" }
+ , {nil, "cxxflags", "kv", nil, "The C++ Compiler Flags" }
, {}
- , {nil, "ld", "kv", "ld", "The linker" }
- , {nil, "ldflags", "kv", nil, "The linker flags" }
+ , {nil, "ld", "kv", "ld", "The Linker" }
+ , {nil, "ldflags", "kv", nil, "The Linker Flags" }
, {}
- , {nil, "as", "kv", "as", "The assembler" }
- , {nil, "asflags", "kv", nil, "The assembler flags" }
+ , {nil, "as", "kv", "as", "The Assembler" }
+ , {nil, "asflags", "kv", nil, "The Assembler Flags" }
-- the options for all platforms
, function () return platform.menu("config") end
@@ -212,9 +212,9 @@ local menu =
, {'f', "file", "kv", "xmake.xproj","Read a given xmake.xproj file." }
, {'P', "project", "kv", nil, "Change to the given project directory."
, "Search priority:"
- , " 1. the given command argument"
- , " 2. the envirnoment variable: XMAKE_PROJECT_DIR"
- , " 3. the current directory" }
+ , " 1. The Given Command Argument"
+ , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
+ , " 3. The Current Directory" }
, {}
@@ -270,10 +270,9 @@ local menu =
{'f', "file", "kv", "xmake.xproj","Read a given xmake.xproj file." }
, {'P', "project", "kv", nil, "Change to the given project directory."
, "Search priority:"
- , " 1. the given command argument"
- , " 2. the envirnoment variable: XMAKE_PROJECT_DIR"
- , " 3. the current directory" }
-
+ , " 1. The Given Command Argument"
+ , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
+ , " 3. The Current Directory" }
, {}
, {'v', "verbose", "k", nil, "Print lots of verbose information." }
@@ -303,10 +302,9 @@ local menu =
{'f', "file", "kv", "xmake.xproj","Read a given xmake.xproj file." }
, {'P', "project", "kv", nil, "Change to the given project directory."
, "Search priority:"
- , " 1. the given command argument"
- , " 2. the envirnoment variable: XMAKE_PROJECT_DIR"
- , " 3. the current directory" }
-
+ , " 1. The Given Command Argument"
+ , " 2. The Envirnoment Variable: XMAKE_PROJECT_DIR"
+ , " 3. The Current Directory" }
, {}
, {'v', "verbose", "k", nil, "Print lots of verbose information." }
, {nil, "version", "k", nil, "Print the version number and exit." }
@@ -400,9 +398,6 @@ function main._done_global()
-- load global configure
global.loadxconf()
- -- dump global
- global.dump()
-
-- done action
return action.done("global")
end
@@ -449,9 +444,6 @@ function main._done_option()
-- dump project
project.dump()
- -- dump config
- config.dump()
-
-- dump platform
platform.dump()
diff --git a/xmake/scripts/platform/android/_android.lua b/xmake/scripts/platform/android/_android.lua
index b91aa4eca..630c95ab1 100644
--- a/xmake/scripts/platform/android/_android.lua
+++ b/xmake/scripts/platform/android/_android.lua
@@ -26,6 +26,9 @@ local _android = _android or {}
-- init _android
function _android.init(configs)
+ -- init host
+ configs.host = xmake._HOST
+
-- init the file name formats
configs.formats = {}
configs.formats.static = {"lib", ".a"}
@@ -44,15 +47,15 @@ function _android.menu(action)
-- init config option menu
_android._MENU_CONFIG = _android._MENU_CONFIG or
{ {}
- , {nil, "ndk", "kv", nil, "The NDK directory" }
- , {nil, "ndk_sdkver", "kv", "auto", "The SDK version for NDK" }
+ , {nil, "ndk", "kv", nil, "The NDK Directory" }
+ , {nil, "ndk_sdkver", "kv", "auto", "The SDK Version for NDK" }
, }
-- init global option menu
_android._MENU_GLOBAL = _android._MENU_GLOBAL or
{ {}
- , {nil, "ndk", "kv", nil, "The NDK directory" }
- , {nil, "ndk_sdkver", "kv", "auto", "The SDK version for NDK" }
+ , {nil, "ndk", "kv", nil, "The NDK Directory" }
+ , {nil, "ndk_sdkver", "kv", "auto", "The SDK Version for NDK" }
, }
-- get the option menu
diff --git a/xmake/scripts/platform/ios/_ios.lua b/xmake/scripts/platform/ios/_ios.lua
index a8cb3dc75..8cc91c62b 100644
--- a/xmake/scripts/platform/ios/_ios.lua
+++ b/xmake/scripts/platform/ios/_ios.lua
@@ -26,6 +26,9 @@ local _ios = _ios or {}
-- init _ios
function _ios.init(configs)
+ -- init host
+ configs.host = "macosx"
+
-- init the file name formats
configs.formats = {}
configs.formats.static = {"lib", ".a"}
@@ -45,24 +48,30 @@ function _ios.menu(action)
-- init config option menu
_ios._MENU_CONFIG = _ios._MENU_CONFIG or
{ {}
- , {nil, "mm", "kv", nil, "The objc compiler" }
- , {nil, "mx", "kv", nil, "The objc/c++ compiler" }
- , {nil, "mxx", "kv", nil, "The objc++ compiler" }
- , {nil, "mflags", "kv", nil, "The objc compiler flags" }
- , {nil, "mxflags", "kv", nil, "The objc/c++ compiler flags" }
- , {nil, "mxxflags", "kv", nil, "The objc++ compiler flags" }
+ , {nil, "mm", "kv", nil, "The Objc Compiler" }
+ , {nil, "mx", "kv", nil, "The Objc/c++ Compiler" }
+ , {nil, "mxx", "kv", nil, "The Objc++ Compiler" }
+ , {nil, "mflags", "kv", nil, "The Objc Compiler Flags" }
+ , {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_sdkver", "kv", "auto", "The SDK Version for Xcode" }
, {}
- , {nil, "xcode", "kv", "/Applications/Xcode.app"
- , "The Xcode application directory" }
- , {nil, "xcode_sdkver", "kv", "auto", "The SDK version for Xcode" }
+ , {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" }
+ , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" }
+ , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" }
, }
-- init global option menu
_ios._MENU_GLOBAL = _ios._MENU_GLOBAL or
{ {}
- , {nil, "xcode", "kv", "/Applications/Xcode.app"
- , "The Xcode application directory" }
- , {nil, "xcode_sdkver", "kv", "auto", "The SDK version for Xcode" }
+ , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" }
+ , {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" }
+ , {}
+ , {nil, "mobileprovision","kv", "auto", "The Provisioning Profile File" }
+ , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" }
+ , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" }
, }
-- get the option menu
diff --git a/xmake/scripts/platform/linux/_linux.lua b/xmake/scripts/platform/linux/_linux.lua
index 8aba6d7ec..51e3ee89a 100644
--- a/xmake/scripts/platform/linux/_linux.lua
+++ b/xmake/scripts/platform/linux/_linux.lua
@@ -26,6 +26,9 @@ local _linux = _linux or {}
-- init _linux
function _linux.init(configs)
+ -- init host
+ configs.host = "linux"
+
-- init the file name formats
configs.formats = {}
configs.formats.static = {"lib", ".a"}
@@ -44,8 +47,8 @@ function _linux.menu(action)
-- init config option menu
_linux._MENU_CONFIG = _linux._MENU_CONFIG or
{ {}
- , {nil, "ar", "kv", "ar", "The library creator" }
- , {nil, "arflags", "kv", nil, "The library creator flags" }
+ , {nil, "ar", "kv", "ar", "The Library Creator" }
+ , {nil, "arflags", "kv", nil, "The Library Creator Flags" }
}
-- init global option menu
diff --git a/xmake/scripts/platform/macosx/_macosx.lua b/xmake/scripts/platform/macosx/_macosx.lua
index ee6df36c4..e42b1c81f 100644
--- a/xmake/scripts/platform/macosx/_macosx.lua
+++ b/xmake/scripts/platform/macosx/_macosx.lua
@@ -20,12 +20,21 @@
-- @file _macosx.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: _macosx
local _macosx = _macosx or {}
-- init configure
function _macosx.init(configs)
+ -- init host
+ configs.host = "macosx"
+
-- init the file name formats
configs.formats = {}
configs.formats.static = {"lib", ".a"}
@@ -37,8 +46,94 @@ function _macosx.init(configs)
configs.archs.x86 = {}
configs.archs.x64 = {}
- -- save configure
- _macosx._CONFIGS = configs
+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
+
end
-- get the option menu for action: xmake config or global
@@ -47,24 +142,22 @@ function _macosx.menu(action)
-- init config option menu
_macosx._MENU_CONFIG = _macosx._MENU_CONFIG or
{ {}
- , {nil, "mm", "kv", nil, "The objc compiler" }
- , {nil, "mx", "kv", nil, "The objc/c++ compiler" }
- , {nil, "mxx", "kv", nil, "The objc++ compiler" }
- , {nil, "mflags", "kv", nil, "The objc compiler flags" }
- , {nil, "mxflags", "kv", nil, "The objc/c++ compiler flags" }
- , {nil, "mxxflags", "kv", nil, "The objc++ compiler flags" }
+ , {nil, "mm", "kv", nil, "The Objc Compiler" }
+ , {nil, "mx", "kv", nil, "The Objc/c++ Compiler" }
+ , {nil, "mxx", "kv", nil, "The Objc++ Compiler" }
+ , {nil, "mflags", "kv", nil, "The Objc Compiler Flags" }
+ , {nil, "mxflags", "kv", nil, "The Objc/c++ Compiler Flags" }
+ , {nil, "mxxflags", "kv", nil, "The Objc++ Compiler Flags" }
, {}
- , {nil, "xcode", "kv", "/Applications/Xcode.app"
- , "The Xcode application directory" }
- , {nil, "xcode_sdkver", "kv", "auto", "The SDK version for Xcode" }
+ , {nil, "xcode", "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", "/Applications/Xcode.app"
- , "The Xcode application directory" }
- , {nil, "xcode_sdkver", "kv", "auto", "The SDK version for Xcode" }
+ , {nil, "xcode", "kv", "auto", "The Xcode Application Directory" }
+ , {nil, "xcode_sdkver", "kv", "auto", "The SDK Version for Xcode" }
, }
-- get the option menu
diff --git a/xmake/scripts/platform/platform.lua b/xmake/scripts/platform/platform.lua
index 533026c9c..dc5c9616e 100644
--- a/xmake/scripts/platform/platform.lua
+++ b/xmake/scripts/platform/platform.lua
@@ -207,6 +207,35 @@ function platform.menu(action)
-- get all platform menus
return menus
end
+
+-- probe the platform configure and update the values with "auto"
+function platform.probe(configs, is_global)
+
+ -- probe global
+ if is_global then
+
+ -- get all platforms
+ local plats = platform.plats()
+ assert(plats)
+
+ -- 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)
+ end
+ end
+
+ -- probe config
+ else
+ -- probe it
+ local p = platform._load(config.get("plat"))
+ if p and p.probe then
+ p.probe(configs)
+ end
+ end
+end
-- return module: platform
return platform
diff --git a/xmake/scripts/platform/windows/_windows.lua b/xmake/scripts/platform/windows/_windows.lua
index 7a31eabaa..793de81b0 100644
--- a/xmake/scripts/platform/windows/_windows.lua
+++ b/xmake/scripts/platform/windows/_windows.lua
@@ -26,6 +26,9 @@ local _windows = _windows or {}
-- init _windows
function _windows.init(configs)
+ -- init host
+ configs.host = "windows"
+
-- init the file name formats
configs.formats = {}
configs.formats.static = {"", ".lib"}
@@ -45,15 +48,15 @@ function _windows.menu(action)
-- init config option menu
_windows._MENU_CONFIG = _windows._MENU_CONFIG or
{ {}
- , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio directory" }
- , {nil, "vs_sdk", "kv", "auto", "The Microsoft Visual Studio SDK directory" }
+ , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio Directory" }
+ , {nil, "vs_sdk", "kv", "auto", "The Microsoft Visual Studio SDK Directory" }
, }
-- init global option menu
_windows._MENU_GLOBAL = _windows._MENU_GLOBAL or
{ {}
- , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio directory" }
- , {nil, "vs_sdk", "kv", "auto", "The Microsoft Visual Studio SDK directory" }
+ , {nil, "vs", "kv", "auto", "The Microsoft Visual Studio Directory" }
+ , {nil, "vs_sdk", "kv", "auto", "The Microsoft Visual Studio SDK Directory" }
, }
-- get the option menu