diff options
| author | ruki <[email protected]> | 2015-06-04 11:06:33 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-04 11:06:33 +0800 |
| commit | e93e932433483348664804a0cc054b2c6af61a95 (patch) | |
| tree | 25bb8afda99c26c7082f5b2046e79702644405d4 /xmake/scripts/platform | |
| parent | 282c12b8f7b9b01a85844326c28f6bc3529aa088 (diff) | |
load platform from the project and global configure directory
Diffstat (limited to 'xmake/scripts/platform')
| -rw-r--r-- | xmake/scripts/platform/android/_android.lua | 3 | ||||
| -rw-r--r-- | xmake/scripts/platform/iphoneos/_iphoneos.lua | 3 | ||||
| -rw-r--r-- | xmake/scripts/platform/iphonesimulator/_iphonesimulator.lua | 3 | ||||
| -rw-r--r-- | xmake/scripts/platform/linux/_linux.lua | 3 | ||||
| -rw-r--r-- | xmake/scripts/platform/macosx/_macosx.lua | 3 | ||||
| -rw-r--r-- | xmake/scripts/platform/platform.lua | 146 | ||||
| -rw-r--r-- | xmake/scripts/platform/windows/_windows.lua | 3 |
7 files changed, 119 insertions, 45 deletions
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) |
