summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2016-04-15 14:54:25 +0800
committerruki <[email protected]>2016-04-15 14:54:25 +0800
commitb6520ecb79a870b48e2609d114c415b808405f61 (patch)
treed52b9011bd19d9b8583038a48c99e186df00f24d
parenta8915ae9e7eb10d30ff1cd59bb1dc719e23d0155 (diff)
add common checker for platforms
-rw-r--r--xmake/core/sandbox/modules/os.lua7
-rw-r--r--xmake/platforms/checker.lua162
-rw-r--r--xmake/platforms/macosx/checker.lua185
3 files changed, 191 insertions, 163 deletions
diff --git a/xmake/core/sandbox/modules/os.lua b/xmake/core/sandbox/modules/os.lua
index 81378c66e..9ab8eb648 100644
--- a/xmake/core/sandbox/modules/os.lua
+++ b/xmake/core/sandbox/modules/os.lua
@@ -159,6 +159,13 @@ function sandbox_os.tmpdir()
return tmpdir
end
+-- get the program directory
+function sandbox_os.programdir()
+
+ -- get it
+ return xmake._PROGRAM_DIR
+end
+
-- run shell
function sandbox_os.run(cmd, ...)
diff --git a/xmake/platforms/checker.lua b/xmake/platforms/checker.lua
new file mode 100644
index 000000000..c808bbdc8
--- /dev/null
+++ b/xmake/platforms/checker.lua
@@ -0,0 +1,162 @@
+--!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 <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a>
+--
+-- Copyright (C) 2015 - 2016, ruki All rights reserved.
+--
+-- @author ruki
+-- @file checker.lua
+--
+
+-- imports
+import("core.tool.tool")
+
+-- check the architecture
+function check_arch(config)
+
+ -- get the architecture
+ local arch = config.get("arch")
+ if not arch then
+
+ -- init the default architecture
+ config.set("arch", os.arch())
+
+ -- trace
+ print("checking for the architecture ... %s", config.get("arch"))
+
+ end
+end
+
+-- check the xcode application directory
+function check_xcode(config)
+
+ -- get the xcode directory
+ local xcode_dir = config.get("xcode_dir")
+ if not xcode_dir then
+
+ -- 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 #dirs ~= 0 then
+ xcode_dir = dirs[1]
+ end
+ end
+
+ -- check ok? update it
+ if xcode_dir then
+
+ -- save it
+ config.set("xcode_dir", xcode_dir)
+
+ -- trace
+ print("checking for the Xcode application directory ... %s", xcode_dir)
+ else
+ -- failed
+ print("checking for the Xcode application directory ... no")
+ print("please run:")
+ print(" - xmake config --xcode_dir=xxx")
+ print("or - xmake global --xcode_dir=xxx")
+ raise()
+ end
+ end
+end
+
+-- check the make
+function check_make(config)
+
+ -- get the make
+ local make = config.get("make")
+ if not make then
+
+ -- check the make path
+ make = tool.check("make", {"/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin"})
+
+ -- check ok? update it
+ if make then config.set("make", make) end
+
+ -- trace
+ print("checking for the make ... %s", ifelse(make, make, "no"))
+
+ end
+end
+
+-- check the ccache
+function check_ccache(config)
+
+ -- ok?
+ local ccache = config.get("ccache")
+ if ccache ~= nil then
+
+ -- check the ccache path
+ local ccache_path = tool.check("ccache", {"/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin"})
+
+ -- check ok? update it
+ if ccache_path then
+ config.set("ccache", true)
+ config.set("__ccache", ccache_path)
+ else
+ config.set("ccache", false)
+ end
+
+ -- trace
+ print("checking for the ccache ... %s", ifelse(ccache_path, ccache_path, "no"))
+
+ end
+end
+
+-- check the toolchain
+function check_toolchain(config, kind, cross, name, description)
+
+ -- get the tool path
+ local toolpath = config.get(kind)
+ if not toolpath then
+
+ -- get the cross
+ cross = config.get("cross") or cross
+
+ -- attempt to get it from the given cross toolchains
+ local toolchains = config.get("toolchains")
+ if not toolpath and toolchains then
+ toolpath = tool.check(cross .. name, toolchains)
+ end
+
+ -- attempt to run it directly
+ if not toolpath then
+ toolpath = tool.check(cross .. name)
+ end
+
+ -- check ok?
+ if toolpath then
+
+ -- update config
+ config.set(kind, toolpath)
+
+ end
+
+ -- trace
+ if toolpath then
+ print("checking for %s (%s) ... %s", description, kind, path.filename(toolpath))
+ else
+ print("checking for %s (%s) ... no", description, kind)
+ end
+ end
+end
diff --git a/xmake/platforms/macosx/checker.lua b/xmake/platforms/macosx/checker.lua
index afba70fb6..3e1dca563 100644
--- a/xmake/platforms/macosx/checker.lua
+++ b/xmake/platforms/macosx/checker.lua
@@ -22,65 +22,9 @@
-- imports
import("core.tool.tool")
+import("platforms.checker", {rootdir = os.programdir()})
--- check the architecture
-function _check_arch(config)
-
- -- get the architecture
- local arch = config.get("arch")
- if not arch then
-
- -- init the default architecture
- config.set("arch", os.arch())
-
- -- trace
- print("checking for the architecture ... %s", config.get("arch"))
-
- end
-end
-
--- check the xcode application directory
-function _check_xcode(config)
-
- -- get the xcode directory
- local xcode_dir = config.get("xcode_dir")
- if not xcode_dir then
-
- -- 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 #dirs ~= 0 then
- xcode_dir = dirs[1]
- end
- end
-
- -- check ok? update it
- if xcode_dir then
-
- -- save it
- config.set("xcode_dir", xcode_dir)
-
- -- trace
- print("checking for the Xcode application directory ... %s", xcode_dir)
- else
- -- failed
- print("checking for the Xcode application directory ... no")
- print("please run:")
- print(" - xmake config --xcode_dir=xxx")
- print("or - xmake global --xcode_dir=xxx")
- raise()
- end
- end
-end
-
--- probe the xcode sdk version
+-- check the xcode sdk version
function _check_xcode_sdkver(config)
-- get the xcode sdk version
@@ -133,109 +77,24 @@ function _check_target_minver(config)
end
end
--- check the make
-function _check_make(config)
-
- -- ok?
- local make = config.get("make")
- if not make then
-
- -- check the make path
- make = tool.check("make", {"/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin"})
-
- -- check ok? update it
- if make then config.set("make", make) end
-
- -- trace
- print("checking for the make ... %s", ifelse(make, make, "no"))
-
- end
-end
-
--- check the ccache
-function _check_ccache(config)
-
- -- ok?
- local ccache = config.get("ccache")
- if ccache ~= nil then
-
- -- check the ccache path
- local ccache_path = tool.check("ccache", {"/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin"})
-
- -- check ok? update it
- if ccache_path then
- config.set("ccache", true)
- config.set("__ccache", ccache_path)
- else
- config.set("ccache", false)
- end
-
- -- trace
- print("checking for the ccache ... %s", ifelse(ccache_path, ccache_path, "no"))
-
- end
-end
-
--- check the tool path
-function _check_toolpath(config, kind, cross, names, description)
-
- -- get the cross
- cross = config.get("cross") or cross
-
- -- done
- local toolpath = nil
- local toolchains = config.get("toolchains")
- for _, name in ipairs(names) do
-
- -- attempt to get it from the given cross toolchains
- if toolchains then
- toolpath = tool.check(cross .. (config.get(kind) or name), toolchains)
- end
-
- -- attempt to get it directly from the configure
- if not toolpath then
- toolpath = config.get(kind)
- end
-
- -- attempt to run it directly
- if not toolpath then
- toolpath = tool.check(cross .. name)
- end
-
- -- check ok?
- if toolpath then
-
- -- update config
- config.set(kind, toolpath)
-
- -- end
- break
- end
-
- end
-
- -- trace
- if toolpath then
- print("checking for %s (%s) ... %s", description, kind, path.filename(toolpath))
- else
- print("checking for %s (%s) ... no", description, kind)
- end
-
-end
-
-- check the toolchains
function _check_toolchains(config)
-- done
- _check_toolpath(config, "cc", "xcrun -sdk macosx ", "clang", "the c compiler")
- _check_toolpath(config, "cxx", "xcrun -sdk macosx ", {"clang++", "clang"}, "the c++ compiler")
- _check_toolpath(config, "mm", "xcrun -sdk macosx ", "clang", "the objc compiler")
- _check_toolpath(config, "mxx", "xcrun -sdk macosx ", {"clang++", "clang"}, "the objc++ compiler")
- _check_toolpath(config, "as", "xcrun -sdk macosx ", "clang", "the assember")
- _check_toolpath(config, "ld", "xcrun -sdk macosx ", {"clang++", "clang"}, "the linker")
- _check_toolpath(config, "ar", "xcrun -sdk macosx ", "ar", "the static library linker")
- _check_toolpath(config, "sh", "xcrun -sdk macosx ", {"clang++", "clang"}, "the shared library linker")
- _check_toolpath(config, "sc", "xcrun -sdk macosx ", "swiftc", "the swift compiler")
+ checker.check_toolchain(config, "cc", "xcrun -sdk macosx ", "clang", "the c compiler")
+ checker.check_toolchain(config, "cxx", "xcrun -sdk macosx ", "clang", "the c++ compiler")
+ checker.check_toolchain(config, "cxx", "xcrun -sdk macosx ", "clang++", "the c++ compiler")
+ checker.check_toolchain(config, "mm", "xcrun -sdk macosx ", "clang", "the objc compiler")
+ checker.check_toolchain(config, "mxx", "xcrun -sdk macosx ", "clang++", "the objc++ compiler")
+ checker.check_toolchain(config, "mxx", "xcrun -sdk macosx ", "clang", "the objc++ compiler")
+ checker.check_toolchain(config, "as", "xcrun -sdk macosx ", "clang", "the assember")
+ checker.check_toolchain(config, "ld", "xcrun -sdk macosx ", "clang++", "the linker")
+ checker.check_toolchain(config, "ld", "xcrun -sdk macosx ", "clang", "the linker")
+ checker.check_toolchain(config, "ar", "xcrun -sdk macosx ", "ar", "the static library linker")
+ checker.check_toolchain(config, "sh", "xcrun -sdk macosx ", "clang++", "the shared library linker")
+ checker.check_toolchain(config, "sh", "xcrun -sdk macosx ", "clang", "the shared library linker")
+ checker.check_toolchain(config, "sc", "xcrun -sdk macosx ", "swiftc", "the swift compiler")
+
end
-- init it
@@ -247,20 +106,20 @@ function init()
-- init the check list of config
_g.config =
{
- _check_arch
- , _check_xcode
+ checker.check_arch
+ , checker.check_xcode
, _check_xcode_sdkver
, _check_target_minver
- , _check_make
- , _check_ccache
+ , checker.check_make
+ , checker.check_ccache
, _check_toolchains
}
-- init the check list of global
_g.global =
{
- _check_xcode
- , _check_ccache
+ checker.check_xcode
+ , checker.check_ccache
}
end