summaryrefslogtreecommitdiff
path: root/xmake/scripts
diff options
context:
space:
mode:
authorruki <[email protected]>2015-06-04 11:06:33 +0800
committerruki <[email protected]>2015-06-04 11:06:33 +0800
commite93e932433483348664804a0cc054b2c6af61a95 (patch)
tree25bb8afda99c26c7082f5b2046e79702644405d4 /xmake/scripts
parent282c12b8f7b9b01a85844326c28f6bc3529aa088 (diff)
load platform from the project and global configure directory
Diffstat (limited to 'xmake/scripts')
-rw-r--r--xmake/scripts/base/main.lua8
-rw-r--r--xmake/scripts/base/option.lua82
-rw-r--r--xmake/scripts/platform/android/_android.lua3
-rw-r--r--xmake/scripts/platform/iphoneos/_iphoneos.lua3
-rw-r--r--xmake/scripts/platform/iphonesimulator/_iphonesimulator.lua3
-rw-r--r--xmake/scripts/platform/linux/_linux.lua3
-rw-r--r--xmake/scripts/platform/macosx/_macosx.lua3
-rw-r--r--xmake/scripts/platform/platform.lua146
-rw-r--r--xmake/scripts/platform/windows/_windows.lua3
9 files changed, 208 insertions, 46 deletions
diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua
index 830a958d6..2624c8d53 100644
--- a/xmake/scripts/base/main.lua
+++ b/xmake/scripts/base/main.lua
@@ -573,7 +573,13 @@ end
-- the main function
function main.done()
- -- init option first
+ -- init project directory first
+ local projectdir = option.find(xmake._ARGV, "project", "P")
+ if projectdir then
+ xmake._PROJECT_DIR = path.absolute(projectdir)
+ end
+
+ -- init option
if not option.init(xmake._ARGV, menu) then
return -1
end
diff --git a/xmake/scripts/base/option.lua b/xmake/scripts/base/option.lua
index df1fb54cb..cdf82adb5 100644
--- a/xmake/scripts/base/option.lua
+++ b/xmake/scripts/base/option.lua
@@ -320,6 +320,88 @@ function option.init(argv, menu)
return true
end
+-- find the value of a given name from the arguments
+-- only for kv mode and need not check it using menu
+--
+function option.find(argv, name, shortname)
+
+ -- check
+ assert(argv and name)
+
+ -- parse _ARGV to _OPTIONS
+ local _iter, _s, _k = ipairs(argv)
+ while true do
+
+ -- the idx and arg
+ local idx, arg = _iter(_s, _k)
+
+ -- end?
+ _k = idx
+ if idx == nil then break end
+
+ -- parse key and value
+ local key, value
+ local i = arg:find("=", 1, true)
+
+ -- key=value?
+ if i then
+ key = arg:sub(1, i - 1)
+ value = arg:sub(i + 1)
+ -- only key?
+ else
+ key = arg
+ value = true
+ end
+
+ -- --key?
+ local prefix = 0
+ if key:startswith("--") then
+ key = key:sub(3)
+ prefix = 2
+ -- -k?
+ elseif key:startswith("-") then
+ key = key:sub(2)
+ prefix = 1
+ end
+
+ -- check key
+ if prefix and #key == 0 then
+ -- failed
+ return
+ end
+
+ -- --key=value or -k value or -k?
+ if prefix ~= 0 then
+
+ -- -k value? continue to get the value
+ if prefix == 1 then
+
+ -- get the next idx and arg
+ idx, arg = _iter(_s, _k)
+
+ -- exists value?
+ _k = idx
+ if idx == nil or arg:startswith("-") then
+ -- failed
+ return
+ end
+
+ -- get value
+ value = arg
+ end
+
+ -- ok?
+ if key == name or (shortname and key == shortname) then
+ return value
+ end
+
+ -- action? skip it
+ elseif idx == 1 then
+ -- value?
+ else return end
+ end
+end
+
-- print the menu
function option.print_menu(action)
diff --git a/xmake/scripts/platform/android/_android.lua b/xmake/scripts/platform/android/_android.lua
index 49dd8ce0e..ba180d87d 100644
--- a/xmake/scripts/platform/android/_android.lua
+++ b/xmake/scripts/platform/android/_android.lua
@@ -32,9 +32,6 @@ _android._HOST = xmake._HOST
-- init architectures
_android._ARCHS = {"armv5te", "armv6", "armv7-a"}
--- init prober
-_android._PROBER = require("platform/android/_prober")
-
-- make configure
function _android.make(configs)
diff --git a/xmake/scripts/platform/iphoneos/_iphoneos.lua b/xmake/scripts/platform/iphoneos/_iphoneos.lua
index e35d17bc9..872f7c2e1 100644
--- a/xmake/scripts/platform/iphoneos/_iphoneos.lua
+++ b/xmake/scripts/platform/iphoneos/_iphoneos.lua
@@ -32,9 +32,6 @@ _iphoneos._HOST = "macosx"
-- init architectures
_iphoneos._ARCHS = {"armv7", "armv7s", "arm64"}
--- init prober
-_iphoneos._PROBER = require("platform/iphoneos/_prober")
-
-- make configure
function _iphoneos.make(configs)
diff --git a/xmake/scripts/platform/iphonesimulator/_iphonesimulator.lua b/xmake/scripts/platform/iphonesimulator/_iphonesimulator.lua
index 84805e3ea..4a814691d 100644
--- a/xmake/scripts/platform/iphonesimulator/_iphonesimulator.lua
+++ b/xmake/scripts/platform/iphonesimulator/_iphonesimulator.lua
@@ -32,9 +32,6 @@ _iphonesimulator._HOST = "macosx"
-- init architectures
_iphonesimulator._ARCHS = {"x86", "x64"}
--- init prober
-_iphonesimulator._PROBER = require("platform/iphonesimulator/_prober")
-
-- make configure
function _iphonesimulator.make(configs)
diff --git a/xmake/scripts/platform/linux/_linux.lua b/xmake/scripts/platform/linux/_linux.lua
index cd1fdd139..57d436eb5 100644
--- a/xmake/scripts/platform/linux/_linux.lua
+++ b/xmake/scripts/platform/linux/_linux.lua
@@ -32,9 +32,6 @@ _linux._HOST = "linux"
-- init architectures
_linux._ARCHS = {"x86", "x64"}
--- init prober
-_linux._PROBER = require("platform/linux/_prober")
-
-- make configure
function _linux.make(configs)
diff --git a/xmake/scripts/platform/macosx/_macosx.lua b/xmake/scripts/platform/macosx/_macosx.lua
index 6ab67da0f..0ab0407b4 100644
--- a/xmake/scripts/platform/macosx/_macosx.lua
+++ b/xmake/scripts/platform/macosx/_macosx.lua
@@ -32,9 +32,6 @@ _macosx._HOST = "macosx"
-- init architectures
_macosx._ARCHS = {"x86", "x64"}
--- init prober
-_macosx._PROBER = require("platform/macosx/_prober")
-
-- make configure
function _macosx.make(configs)
diff --git a/xmake/scripts/platform/platform.lua b/xmake/scripts/platform/platform.lua
index 07a973dcd..1ef136ae3 100644
--- a/xmake/scripts/platform/platform.lua
+++ b/xmake/scripts/platform/platform.lua
@@ -28,14 +28,87 @@ local os = require("base/os")
local path = require("base/path")
local utils = require("base/utils")
local config = require("base/config")
+local global = require("base/global")
local linker = require("linker/linker")
local compiler = require("compiler/compiler")
+-- load prober the given platform directory
+function platform._load_prober(root)
+
+ -- the platform file path
+ local file = string.format("%s/_prober.lua", root)
+ if os.isfile(file) then
+
+ -- load script
+ local script = loadfile(file)
+ if script then
+
+ -- load prober
+ local prober = script()
+ if prober then
+
+ -- ok
+ return prober
+ end
+ end
+ end
+end
+
+-- load the given platform from the given root directory
+function platform._load_from(root, plat)
+
+ -- the platform file path
+ local file = string.format("%s/platform/%s/_%s.lua", root, plat, plat)
+ if os.isfile(file) then
+
+ -- load script
+ local script = loadfile(file)
+ if script then
+
+ -- load module
+ local module = script()
+ if module then
+
+ -- save directory
+ module._DIRECTORY = path.directory(file)
+ assert(module._DIRECTORY)
+
+ -- attempt to load prober
+ module._PROBER = platform._load_prober(module._DIRECTORY)
+
+ -- ok
+ return module
+ end
+ end
+ end
+end
+
-- load the given platform
function platform._load(plat)
-
- -- load it
- return require("platform/" .. plat .. "/_" .. plat)
+
+ -- the module
+ platform._MODULES = platform._MODULES or {}
+ local module = platform._MODULES[plat]
+
+ -- return it directory if ok
+ if module then return module end
+
+ -- attempt to load it from the project configure directory
+ if not module then module = platform._load_from(config.directory(), plat) end
+
+ -- attempt to load it from the global configure directory
+ if not module then module = platform._load_from(global.directory(), plat) end
+
+ -- attempt to load it from the script directory
+ if not module then module = platform._load_from(xmake._SCRIPTS_DIR, plat) end
+
+ -- cache it if ok
+ if module then
+ platform._MODULES[plat] = module
+ end
+
+ -- ok?
+ return module
end
-- get the configure of the given platform
@@ -51,15 +124,15 @@ function platform._configs(plat)
end
-- load platform
- local p = platform._load(plat)
- if p then
+ local module = platform._load(plat)
+ if module then
-- init configure
platform._CONFIGS[plat]= {}
configs = platform._CONFIGS[plat]
-- make configure
- p.make(configs)
+ module.make(configs)
end
-- ok?
@@ -169,19 +242,38 @@ function platform.plats()
return platform._PLATS
end
- -- get the platform list
- local plats = os.match(xmake._SCRIPTS_DIR .. "/platform/*", true)
+ -- make list
+ local list = {}
+
+ -- get the platform list from the project configure directory
+ local plats = os.match(config.directory() .. "/platform/*", true)
+ if plats then
+ for _, v in ipairs(plats) do
+ table.insert(list, path.basename(v))
+ end
+ end
+
+ -- get the platform list from the global configure directory
+ plats = os.match(global.directory() .. "/platform/*", true)
+ if plats then
+ for _, v in ipairs(plats) do
+ table.insert(list, path.basename(v))
+ end
+ end
+
+ -- get the platform list from the script directory
+ plats = os.match(xmake._SCRIPTS_DIR .. "/platform/*", true)
if plats then
- for i, v in ipairs(plats) do
- plats[i] = path.basename(v)
+ for _, v in ipairs(plats) do
+ table.insert(list, path.basename(v))
end
end
-- save it
- platform._PLATS = plats
+ platform._PLATS = list
-- ok
- return plats
+ return list
end
-- list all architectures
@@ -192,9 +284,9 @@ function platform.archs(plat)
-- load all platform configs
local archs = {}
- local p = platform._load(plat)
- if p and p._ARCHS then
- for _, arch in ipairs(p._ARCHS) do
+ local module = platform._load(plat)
+ if module and module._ARCHS then
+ for _, arch in ipairs(module._ARCHS) do
table.insert(archs, arch)
end
end
@@ -219,11 +311,11 @@ function platform.menu(action)
for _, plat in ipairs(plats) do
-- load platform
- local p = platform._load(plat)
- if p and p.menu then
+ local module = platform._load(plat)
+ if module and module.menu then
-- get the platform menu
- local menu = p.menu(action)
+ local menu = module.menu(action)
if menu then
-- exists options?
@@ -273,18 +365,18 @@ function platform.probe(configs, is_global)
-- probe all platforms with the current host
for _, plat in ipairs(plats) do
- local p = platform._load(plat)
- if p and p._PROBER and p._PROBER.done and p._HOST and p._HOST == xmake._HOST then
- p._PROBER.done(configs, is_global)
+ local module = platform._load(plat)
+ if module and module._PROBER and module._PROBER.done and module._HOST and module._HOST == xmake._HOST then
+ module._PROBER.done(configs, is_global)
end
end
-- probe config
else
-- probe it
- local p = platform._load(config.get("plat"))
- if p and p._PROBER and p._PROBER.done then
- p._PROBER.done(configs, is_global)
+ local module = platform._load(config.get("plat"))
+ if module and module._PROBER and module._PROBER.done then
+ module._PROBER.done(configs, is_global)
end
end
end
@@ -293,9 +385,9 @@ end
function platform.build(mkfile, target)
-- attempt to done the platform special make first
- local p = platform._load(config.get("plat"))
- if p and p._MAKER and p._MAKER.done then
- return p._MAKER.done(mkfile, target)
+ local module = platform._load(config.get("plat"))
+ if module and module._MAKER and module._MAKER.done then
+ return module._MAKER.done(mkfile, target)
end
-- is verbose?
diff --git a/xmake/scripts/platform/windows/_windows.lua b/xmake/scripts/platform/windows/_windows.lua
index b1bc0890b..8caa84fa3 100644
--- a/xmake/scripts/platform/windows/_windows.lua
+++ b/xmake/scripts/platform/windows/_windows.lua
@@ -35,9 +35,6 @@ _windows._ARCHS = {"x86", "x64"}
-- init maker
_windows._MAKER = require("platform/windows/_maker")
--- init prober
-_windows._PROBER = require("platform/windows/_prober")
-
-- make configure
function _windows.make(configs)