From 3aab30fc254ae7e9bd138aff2bb263af0d447017 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 27 May 2015 09:32:01 +0800 Subject: add prober to all platforms --- xmake/scripts/base/config.lua | 7 +- xmake/scripts/base/main.lua | 2 +- xmake/scripts/platform/android/_android.lua | 10 +- xmake/scripts/platform/android/_prober.lua | 57 ++++++++ xmake/scripts/platform/ios/_ios.lua | 94 -------------- xmake/scripts/platform/ios/_prober.lua | 121 ----------------- xmake/scripts/platform/iphoneos/_iphoneos.lua | 93 ++++++++++++++ xmake/scripts/platform/iphoneos/_prober.lua | 143 +++++++++++++++++++++ .../platform/iphonesimulator/_iphonesimulator.lua | 93 ++++++++++++++ xmake/scripts/platform/iphonesimulator/_prober.lua | 143 +++++++++++++++++++++ xmake/scripts/platform/linux/_linux.lua | 10 +- xmake/scripts/platform/linux/_prober.lua | 57 ++++++++ xmake/scripts/platform/macosx/_macosx.lua | 1 - xmake/scripts/platform/macosx/_prober.lua | 26 +++- xmake/scripts/platform/windows/_prober.lua | 57 ++++++++ xmake/scripts/platform/windows/_windows.lua | 10 +- 16 files changed, 698 insertions(+), 226 deletions(-) create mode 100644 xmake/scripts/platform/android/_prober.lua delete mode 100644 xmake/scripts/platform/ios/_ios.lua delete mode 100644 xmake/scripts/platform/ios/_prober.lua create mode 100644 xmake/scripts/platform/iphoneos/_iphoneos.lua create mode 100644 xmake/scripts/platform/iphoneos/_prober.lua create mode 100644 xmake/scripts/platform/iphonesimulator/_iphonesimulator.lua create mode 100644 xmake/scripts/platform/iphonesimulator/_prober.lua create mode 100644 xmake/scripts/platform/linux/_prober.lua create mode 100644 xmake/scripts/platform/windows/_prober.lua diff --git a/xmake/scripts/base/config.lua b/xmake/scripts/base/config.lua index e6b4dbfdd..bf201db4b 100644 --- a/xmake/scripts/base/config.lua +++ b/xmake/scripts/base/config.lua @@ -291,11 +291,16 @@ function config.loadxconf() -- save configs config._CONFIGS = newenv._CONFIGS - -- clear configs if the host environment has been changed + -- clear configs if the host has been changed local target = config._target() if target and target.host ~= xmake._HOST then config._CONFIGS = {} end + + -- clear configs if the plat has been changed + if target and target.plat and options.plat and target.plat ~= options.plat then + config._CONFIGS = {} + end end -- the target name diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua index 7d448fc57..7418a625a 100644 --- a/xmake/scripts/base/main.lua +++ b/xmake/scripts/base/main.lua @@ -155,7 +155,7 @@ local menu = end return descriptions end } - , {'a', "arch", "kv", xmake._ARCH, "Compile for the given architecture." + , {'a', "arch", "kv", "auto", "Compile for the given architecture." , function () local descriptions = {} local plats = platform.plats() diff --git a/xmake/scripts/platform/android/_android.lua b/xmake/scripts/platform/android/_android.lua index 9de364e77..a7e8806df 100644 --- a/xmake/scripts/platform/android/_android.lua +++ b/xmake/scripts/platform/android/_android.lua @@ -23,11 +23,17 @@ -- define module: _android local _android = _android or {} +-- load modules +local config = require("base/config") + -- init host -_android._HOST = xmake._HOST +_android._HOST = xmake._HOST -- init architectures -_android._ARCHS = {"armv5te", "armv6", "armv7-a"} +_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/android/_prober.lua b/xmake/scripts/platform/android/_prober.lua new file mode 100644 index 000000000..a1f68de8a --- /dev/null +++ b/xmake/scripts/platform/android/_prober.lua @@ -0,0 +1,57 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- 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 architecture +function _prober._probe_arch(configs) + + -- get the architecture + local arch = configs.arch + + -- ok? + if arch and arch ~= "auto" then return true end + + -- init the default architecture + configs.arch = "armv7-a" + + -- ok + return true +end + +-- probe the configure and update the values with "auto" +function _prober.done(configs) + + -- probe the architecture + if not _prober._probe_arch(configs) then return end + +end + +-- return module: _prober +return _prober diff --git a/xmake/scripts/platform/ios/_ios.lua b/xmake/scripts/platform/ios/_ios.lua deleted file mode 100644 index eee1f6587..000000000 --- a/xmake/scripts/platform/ios/_ios.lua +++ /dev/null @@ -1,94 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- Copyright (C) 2009 - 2015, ruki All rights reserved. --- --- @author ruki --- @file _ios.lua --- - --- define module: _ios -local _ios = _ios or {} - --- load modules -local config = require("base/config") - --- init host -_ios._HOST = "macosx" - --- init architectures -_ios._ARCHS = {"armv7", "armv7s", "arm64"} - --- init prober -_ios._PROBER = require("platform/ios/_prober") - --- make configure -function _ios.make(configs) - - -- init the file name formats - configs.formats = {} - configs.formats.static = {"lib", ".a"} - configs.formats.object = {"", ".o"} - configs.formats.shared = {"", ".dylib"} - - -- init xcode sdk directory - configs.xcode_sdkdir = config.get("xcode_dir") .. "/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS" .. config.get("xcode_sdkver") .. ".sdk" - -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_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" } - , {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_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" } - , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" } - , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" } - , } - - -- 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/ios/_prober.lua b/xmake/scripts/platform/ios/_prober.lua deleted file mode 100644 index 2209c14b9..000000000 --- a/xmake/scripts/platform/ios/_prober.lua +++ /dev/null @@ -1,121 +0,0 @@ ---!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 http://www.gnu.org/licenses/ --- --- 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/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.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/iphoneos/_iphoneos.lua b/xmake/scripts/platform/iphoneos/_iphoneos.lua new file mode 100644 index 000000000..5d7d679e8 --- /dev/null +++ b/xmake/scripts/platform/iphoneos/_iphoneos.lua @@ -0,0 +1,93 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file _iphoneos.lua +-- + +-- define module: _iphoneos +local _iphoneos = _iphoneos or {} + +-- load modules +local config = require("base/config") + +-- init host +_iphoneos._HOST = "macosx" + +-- init architectures +_iphoneos._ARCHS = {"armv7", "armv7s", "arm64"} + +-- init prober +_iphoneos._PROBER = require("platform/iphoneos/_prober") + +-- make configure +function _iphoneos.make(configs) + + -- init the file name formats + configs.formats = {} + configs.formats.static = {"lib", ".a"} + configs.formats.object = {"", ".o"} + configs.formats.shared = {"", ".dylib"} + + -- init xcode sdk directory + configs.xcode_sdkdir = config.get("xcode_dir") .. "/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS" .. config.get("xcode_sdkver") .. ".sdk" + +end + +-- get the option menu for action: xmake config or global +function _iphoneos.menu(action) + + -- init config option menu + _iphoneos._MENU_CONFIG = _iphoneos._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_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" } + , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" } + , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" } + , } + + -- init global option menu + _iphoneos._MENU_GLOBAL = _iphoneos._MENU_GLOBAL or + { {} + , {nil, "xcode_dir", "kv", "auto", "The Xcode Application Directory" } + , {} + , {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 + if action == "config" then + return _iphoneos._MENU_CONFIG + elseif action == "global" then + return _iphoneos._MENU_GLOBAL + end +end + + +-- return module: _iphoneos +return _iphoneos diff --git a/xmake/scripts/platform/iphoneos/_prober.lua b/xmake/scripts/platform/iphoneos/_prober.lua new file mode 100644 index 000000000..52b0e5df4 --- /dev/null +++ b/xmake/scripts/platform/iphoneos/_prober.lua @@ -0,0 +1,143 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- 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 architecture +function _prober._probe_arch(configs) + + -- get the architecture + local arch = configs.arch + + -- ok? + if arch and arch ~= "auto" then return true end + + -- init the default architecture + configs.arch = "armv7" + + -- ok + return true +end + +-- 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/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk", true) + if dirs then + for _, dir in ipairs(dirs) do + xcode_sdkver = string.match(dir, "%d+%.%d+") + if xcode_sdkver then break end + end + 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 architecture + if not _prober._probe_arch(configs) then return end + + -- 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/iphonesimulator/_iphonesimulator.lua b/xmake/scripts/platform/iphonesimulator/_iphonesimulator.lua new file mode 100644 index 000000000..5df326fd0 --- /dev/null +++ b/xmake/scripts/platform/iphonesimulator/_iphonesimulator.lua @@ -0,0 +1,93 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- Copyright (C) 2009 - 2015, ruki All rights reserved. +-- +-- @author ruki +-- @file _iphonesimulator.lua +-- + +-- define module: _iphonesimulator +local _iphonesimulator = _iphonesimulator or {} + +-- load modules +local config = require("base/config") + +-- init host +_iphonesimulator._HOST = "macosx" + +-- init architectures +_iphonesimulator._ARCHS = {"x86", "x64"} + +-- init prober +_iphonesimulator._PROBER = require("platform/iphonesimulator/_prober") + +-- make configure +function _iphonesimulator.make(configs) + + -- init the file name formats + configs.formats = {} + configs.formats.static = {"lib", ".a"} + configs.formats.object = {"", ".o"} + configs.formats.shared = {"", ".dylib"} + + -- init xcode sdk directory + configs.xcode_sdkdir = config.get("xcode_dir") .. "/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator" .. config.get("xcode_sdkver") .. ".sdk" + +end + +-- get the option menu for action: xmake config or global +function _iphonesimulator.menu(action) + + -- init config option menu + _iphonesimulator._MENU_CONFIG = _iphonesimulator._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_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" } + , {nil, "codesign", "kv", "auto", "The Code Signing Indentity" } + , {nil, "entitlements", "kv", "auto", "The Code Signing Entitlements" } + , } + + -- init global option menu + _iphonesimulator._MENU_GLOBAL = _iphonesimulator._MENU_GLOBAL or + { {} + , {nil, "xcode_dir", "kv", "auto", "The Xcode Application Directory" } + , {} + , {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 + if action == "config" then + return _iphonesimulator._MENU_CONFIG + elseif action == "global" then + return _iphonesimulator._MENU_GLOBAL + end +end + + +-- return module: _iphonesimulator +return _iphonesimulator diff --git a/xmake/scripts/platform/iphonesimulator/_prober.lua b/xmake/scripts/platform/iphonesimulator/_prober.lua new file mode 100644 index 000000000..c11d78a03 --- /dev/null +++ b/xmake/scripts/platform/iphonesimulator/_prober.lua @@ -0,0 +1,143 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- 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 architecture +function _prober._probe_arch(configs) + + -- get the architecture + local arch = configs.arch + + -- ok? + if arch and arch ~= "auto" then return true end + + -- init the default architecture + configs.arch = "x86" + + -- ok + return true +end + +-- 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/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk", true) + if dirs then + for _, dir in ipairs(dirs) do + xcode_sdkver = string.match(dir, "%d+%.%d+") + if xcode_sdkver then break end + end + 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 architecture + if not _prober._probe_arch(configs) then return end + + -- 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/linux/_linux.lua b/xmake/scripts/platform/linux/_linux.lua index 4b70986c4..b933d563b 100644 --- a/xmake/scripts/platform/linux/_linux.lua +++ b/xmake/scripts/platform/linux/_linux.lua @@ -23,11 +23,17 @@ -- define module: _linux local _linux = _linux or {} +-- load modules +local config = require("base/config") + -- init host -_linux._HOST = "linux" +_linux._HOST = "linux" -- init architectures -_linux._ARCHS = {"x86", "x64"} +_linux._ARCHS = {"x86", "x64"} + +-- init prober +_linux._PROBER = require("platform/linux/_prober") -- make configure function _linux.make(configs) diff --git a/xmake/scripts/platform/linux/_prober.lua b/xmake/scripts/platform/linux/_prober.lua new file mode 100644 index 000000000..cbfcc3710 --- /dev/null +++ b/xmake/scripts/platform/linux/_prober.lua @@ -0,0 +1,57 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- 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 architecture +function _prober._probe_arch(configs) + + -- get the architecture + local arch = configs.arch + + -- ok? + if arch and arch ~= "auto" then return true end + + -- init the default architecture + configs.arch = xmake._ARCH + + -- ok + return true +end + +-- probe the configure and update the values with "auto" +function _prober.done(configs) + + -- probe the architecture + if not _prober._probe_arch(configs) then return end + +end + +-- return module: _prober +return _prober diff --git a/xmake/scripts/platform/macosx/_macosx.lua b/xmake/scripts/platform/macosx/_macosx.lua index e19e5d5ea..67110058f 100644 --- a/xmake/scripts/platform/macosx/_macosx.lua +++ b/xmake/scripts/platform/macosx/_macosx.lua @@ -69,7 +69,6 @@ function _macosx.menu(action) _macosx._MENU_GLOBAL = _macosx._MENU_GLOBAL or { {} , {nil, "xcode_dir", "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/macosx/_prober.lua b/xmake/scripts/platform/macosx/_prober.lua index 8b12894de..4cb2ef1e3 100644 --- a/xmake/scripts/platform/macosx/_prober.lua +++ b/xmake/scripts/platform/macosx/_prober.lua @@ -29,6 +29,22 @@ local string = require("base/string") -- define module: _prober local _prober = _prober or {} +-- probe the architecture +function _prober._probe_arch(configs) + + -- get the architecture + local arch = configs.arch + + -- ok? + if arch and arch ~= "auto" then return true end + + -- init the default architecture + configs.arch = xmake._ARCH + + -- ok + return true +end + -- probe the xcode application directory function _prober._probe_xcode(configs) @@ -86,8 +102,11 @@ function _prober._probe_xcode_sdkver(configs) -- 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+") + if dirs then + for _, dir in ipairs(dirs) do + xcode_sdkver = string.match(dir, "%d+%.%d+") + if xcode_sdkver then break end + end end end @@ -109,6 +128,9 @@ end -- probe the configure and update the values with "auto" function _prober.done(configs) + -- probe the architecture + if not _prober._probe_arch(configs) then return end + -- probe the xcode application directory if not _prober._probe_xcode(configs) then return end diff --git a/xmake/scripts/platform/windows/_prober.lua b/xmake/scripts/platform/windows/_prober.lua new file mode 100644 index 000000000..cbfcc3710 --- /dev/null +++ b/xmake/scripts/platform/windows/_prober.lua @@ -0,0 +1,57 @@ +--!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 http://www.gnu.org/licenses/ +-- +-- 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 architecture +function _prober._probe_arch(configs) + + -- get the architecture + local arch = configs.arch + + -- ok? + if arch and arch ~= "auto" then return true end + + -- init the default architecture + configs.arch = xmake._ARCH + + -- ok + return true +end + +-- probe the configure and update the values with "auto" +function _prober.done(configs) + + -- probe the architecture + if not _prober._probe_arch(configs) then return end + +end + +-- return module: _prober +return _prober diff --git a/xmake/scripts/platform/windows/_windows.lua b/xmake/scripts/platform/windows/_windows.lua index bda11aa07..394846872 100644 --- a/xmake/scripts/platform/windows/_windows.lua +++ b/xmake/scripts/platform/windows/_windows.lua @@ -23,11 +23,17 @@ -- define module: _windows local _windows = _windows or {} +-- load modules +local config = require("base/config") + -- init host -_windows._HOST = "windows" +_windows._HOST = "windows" -- init architectures -_windows._ARCHS = {"x86", "x64"} +_windows._ARCHS = {"x86", "x64"} + +-- init prober +_windows._PROBER = require("platform/windows/_prober") -- make configure function _windows.make(configs) -- cgit v1.3.1