summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2015-05-25 11:13:04 +0800
committerruki <[email protected]>2015-05-25 11:13:04 +0800
commitd3afea28dfea3709fde2296a090cf94598271047 (patch)
tree954d26f9ffd3ebd29a64cc9ecb585542d9d8d0fa
parent99582c402d5580877247344cca1f708f15e16d7b (diff)
custom option menu for platform
-rw-r--r--xmake/scripts/base/main.lua29
-rw-r--r--xmake/scripts/base/option.lua38
-rw-r--r--xmake/scripts/platform/android/_android.lua24
-rw-r--r--xmake/scripts/platform/ios/_ios.lua34
-rw-r--r--xmake/scripts/platform/linux/_linux.lua20
-rw-r--r--xmake/scripts/platform/macosx/_macosx.lua38
-rw-r--r--xmake/scripts/platform/platform.lua97
-rw-r--r--xmake/scripts/platform/windows/_windows.lua25
8 files changed, 275 insertions, 30 deletions
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index 13ce70dfa..d41e24859 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -182,24 +182,29 @@ local menu =
, {'k', "packages", "kv", "pkg", "Set the packages directory" }
, {}
- , {nil, "cc", "kv", nil, "The c compiler" }
- , {nil, "cxx", "kv", nil, "The c++ compiler" }
- , {nil, "mm", "kv", nil, "The objc compiler" }
- , {nil, "mxx", "kv", nil, "The objc++ compiler" }
- , {nil, "ld", "kv", nil, "The linker" }
- , {nil, "as", "kv", nil, "The assembler" }
- , {nil, "ar", "kv", nil, "The library creator" }
+ , {nil, "cross", "kv", nil, "The cross toolchains prefix"
+ , ".e.g"
+ , " - i386-mingw32-"
+ , " - arm-linux-androideabi-" }
+ , {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, "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, "asflags", "kv", nil, "The assembler flags" }
+
+ , {}
+ , {nil, "ld", "kv", "ld", "The linker" }
, {nil, "ldflags", "kv", nil, "The linker flags" }
- , {nil, "arflags", "kv", nil, "The library creator flags" }
+
+ , {}
+ , {nil, "as", "kv", "as", "The assembler" }
+ , {nil, "asflags", "kv", nil, "The assembler flags" }
+
+ , function () return platform.menu("config") end
, {}
, {'f', "file", "kv", "xmake.xproj","Read a given xmake.xproj file." }
diff --git a/xmake/scripts/base/option.lua b/xmake/scripts/base/option.lua
index 7e3d963b4..3da4850c0 100644
--- a/xmake/scripts/base/option.lua
+++ b/xmake/scripts/base/option.lua
@@ -26,6 +26,42 @@ local option = option or {}
-- load modules
local utils = require("base/utils")
+-- save the option menu
+function option._save_menu(menu)
+
+ -- translate it if exists function in the option menu
+ for _, submenu in pairs(menu) do
+
+ -- exits options?
+ if submenu.options then
+
+ -- translate options
+ local options_all = {}
+ for _, option in ipairs(submenu.options) do
+
+ -- this option is function? translate it
+ if type(option) == "function" then
+ local _options = option()
+ if _options then
+ for _, o in ipairs(_options) do
+ options_all[table.getn(options_all) + 1] = o
+ end
+ end
+ else
+ options_all[table.getn(options_all) + 1] = option
+ end
+ end
+
+ -- update the options
+ submenu.options = options_all
+ end
+ end
+
+ -- save menu
+ option._MENU = menu
+
+end
+
-- init the option
function option.init(argv, menu)
@@ -41,7 +77,7 @@ function option.init(argv, menu)
xmake._OPTIONS._DEFAULTS = {}
-- save menu
- option._MENU = menu
+ option._save_menu(menu)
-- parse _ARGV to _OPTIONS
local _iter, _s, _k = ipairs(argv)
diff --git a/xmake/scripts/platform/android/_android.lua b/xmake/scripts/platform/android/_android.lua
index d79236a28..b91aa4eca 100644
--- a/xmake/scripts/platform/android/_android.lua
+++ b/xmake/scripts/platform/android/_android.lua
@@ -38,6 +38,30 @@ function _android.init(configs)
configs.archs.armv6 = {}
end
+-- get the option menu for action: xmake config or global
+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" }
+ , }
+
+ -- 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" }
+ , }
+
+ -- get the option menu
+ if action == "config" then
+ return _android._MENU_CONFIG
+ elseif action == "global" then
+ return _android._MENU_GLOBAL
+ end
+end
-- return module: _android
return _android
diff --git a/xmake/scripts/platform/ios/_ios.lua b/xmake/scripts/platform/ios/_ios.lua
index f74d26544..a8cb3dc75 100644
--- a/xmake/scripts/platform/ios/_ios.lua
+++ b/xmake/scripts/platform/ios/_ios.lua
@@ -39,6 +39,40 @@ function _ios.init(configs)
configs.archs.arm64 = {}
end
+-- get the option menu for action: xmake config or global
+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, "xcode", "kv", "/Applications/Xcode.app"
+ , "The Xcode application directory" }
+ , {nil, "xcode_sdkver", "kv", "auto", "The SDK version for Xcode" }
+ , }
+
+ -- 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" }
+ , }
+
+ -- get the option menu
+ if action == "config" then
+ return _ios._MENU_CONFIG
+ elseif action == "global" then
+ return _ios._MENU_GLOBAL
+ end
+end
+
-- return module: _ios
return _ios
diff --git a/xmake/scripts/platform/linux/_linux.lua b/xmake/scripts/platform/linux/_linux.lua
index 2bc54e4c1..8aba6d7ec 100644
--- a/xmake/scripts/platform/linux/_linux.lua
+++ b/xmake/scripts/platform/linux/_linux.lua
@@ -38,6 +38,26 @@ function _linux.init(configs)
configs.archs.x64 = {}
end
+-- get the option menu for action: xmake config or global
+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" }
+ }
+
+ -- init global option menu
+ _linux._MENU_GLOBAL = _linux._MENU_GLOBAL or {}
+
+ -- get the option menu
+ if action == "config" then
+ return _linux._MENU_CONFIG
+ elseif action == "global" then
+ return _linux._MENU_GLOBAL
+ end
+end
-- return module: _linux
return _linux
diff --git a/xmake/scripts/platform/macosx/_macosx.lua b/xmake/scripts/platform/macosx/_macosx.lua
index 79fd1c9c5..ee6df36c4 100644
--- a/xmake/scripts/platform/macosx/_macosx.lua
+++ b/xmake/scripts/platform/macosx/_macosx.lua
@@ -23,7 +23,7 @@
-- define module: _macosx
local _macosx = _macosx or {}
--- init _macosx
+-- init configure
function _macosx.init(configs)
-- init the file name formats
@@ -36,8 +36,44 @@ function _macosx.init(configs)
configs.archs = {}
configs.archs.x86 = {}
configs.archs.x64 = {}
+
+ -- save configure
+ _macosx._CONFIGS = configs
end
+-- get the option menu for action: xmake config or global
+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, "xcode", "kv", "/Applications/Xcode.app"
+ , "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" }
+ , }
+
+ -- get the option menu
+ if action == "config" then
+ return _macosx._MENU_CONFIG
+ elseif action == "global" then
+ return _macosx._MENU_GLOBAL
+ end
+end
-- return module: _macosx
return _macosx
diff --git a/xmake/scripts/platform/platform.lua b/xmake/scripts/platform/platform.lua
index 24d618835..533026c9c 100644
--- a/xmake/scripts/platform/platform.lua
+++ b/xmake/scripts/platform/platform.lua
@@ -29,39 +29,46 @@ local path = require("base/path")
local utils = require("base/utils")
local config = require("base/config")
+-- load the given platform
+function platform._load(plat)
+
+ -- load it
+ return require("platform/" .. plat .. "/_" .. plat)
+end
+
-- get the configure of the given platform
-function platform._config(plat)
+function platform._configs(plat)
-- the configure
platform._CONFIGS = platform._CONFIGS or {}
- local config = platform._CONFIGS[plat]
+ local configs = platform._CONFIGS[plat]
-- return it directly if exists
- if config then
- return config
+ if configs then
+ return configs
end
-- load platform
- local p = require("platform/" .. plat .. "/_" .. plat)
+ local p = platform._load(plat)
if p then
-- make configure
platform._CONFIGS[plat]= {}
- config = platform._CONFIGS[plat]
+ configs = platform._CONFIGS[plat]
-- init configure
- p.init(config)
+ p.init(configs)
end
-- ok?
- return config
+ return configs
end
-- init platform
function platform.init()
-- init the current platform
- return platform._config(config.get("plat"))
+ return platform._configs(config.get("plat"))
end
-- get the given configure
@@ -71,10 +78,10 @@ function platform.get(name)
assert(platform._CONFIGS)
-- get the current platform configure
- local config = platform._config(config.get("plat"))
- if config then
+ local configs = platform._configs(config.get("plat"))
+ if configs then
-- get it
- return config[name]
+ return configs[name]
end
end
@@ -96,7 +103,7 @@ function platform.dump()
-- dump
if xmake._OPTIONS.verbose then
- utils.dump(platform._config(config.get("plat")))
+ utils.dump(platform._configs(config.get("plat")))
end
end
@@ -132,9 +139,9 @@ function platform.archs(plat)
-- load all platform configs
local archs = {}
- local config = platform._config(plat)
- if config and config.archs then
- for arch, _ in pairs(config.archs) do
+ local configs = platform._configs(plat)
+ if configs and configs.archs then
+ for arch, _ in pairs(configs.archs) do
archs[table.getn(archs) + 1] = arch
end
end
@@ -142,6 +149,64 @@ function platform.archs(plat)
-- ok
return archs
end
+
+-- get the option menu for action: xmake config or global
+function platform.menu(action)
+
+ -- check
+ assert(action)
+
+ -- get all platforms
+ local plats = platform.plats()
+ assert(plats)
+
+ -- load and merge all platform menus
+ local menus = {}
+ local exist = {}
+ for _, plat in ipairs(plats) do
+
+ -- load platform
+ local p = platform._load(plat)
+ if p and p.menu then
+
+ -- get the platform menu
+ local menu = p.menu(action)
+ if menu then
+
+ -- exists options?
+ local exists = false
+ for _, option in ipairs(menu) do
+ local name = option[2]
+ if name and not exist[name] then
+ exists = true
+ break
+ end
+ end
+
+ -- merge it and remove repeat if exists options
+ if exists then
+ -- get the platform menu option
+ for _, option in ipairs(menu) do
+
+ -- merge it and remove repeat
+ local name = option[2]
+ if name then
+ if not exist[name] then
+ menus[table.getn(menus) + 1] = option
+ exist[name] = true
+ end
+ else
+ menus[table.getn(menus) + 1] = option
+ end
+ end
+ end
+ end
+ end
+ end
+
+ -- get all platform menus
+ return menus
+end
-- return module: platform
return platform
diff --git a/xmake/scripts/platform/windows/_windows.lua b/xmake/scripts/platform/windows/_windows.lua
index 56304ee51..7a31eabaa 100644
--- a/xmake/scripts/platform/windows/_windows.lua
+++ b/xmake/scripts/platform/windows/_windows.lua
@@ -39,6 +39,31 @@ function _windows.init(configs)
configs.archs.x64 = {}
end
+-- get the option menu for action: xmake config or global
+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" }
+ , }
+
+ -- 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" }
+ , }
+
+ -- get the option menu
+ if action == "config" then
+ return _windows._MENU_CONFIG
+ elseif action == "global" then
+ return _windows._MENU_GLOBAL
+ end
+end
+
-- return module: _windows
return _windows