From 2e58f26793dc910c024eeba4adb6d52df26e0e22 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 5 Jan 2017 12:15:59 +0800 Subject: move checker to on_check --- xmake/core/platform/checker.lua | 144 ---------- xmake/core/platform/platform.lua | 9 +- .../sandbox/modules/import/core/project/config.lua | 10 +- .../sandbox/modules/import/core/project/global.lua | 31 ++- xmake/platforms/android/check.lua | 162 ++++++++++++ xmake/platforms/android/checker.lua | 166 ------------ xmake/platforms/android/xmake.lua | 6 +- xmake/platforms/checker.lua | 23 ++ xmake/platforms/iphoneos/check.lua | 103 ++++++++ xmake/platforms/iphoneos/checker.lua | 108 -------- xmake/platforms/iphoneos/xmake.lua | 6 +- xmake/platforms/linux/check.lua | 137 ++++++++++ xmake/platforms/linux/checker.lua | 142 ---------- xmake/platforms/linux/xmake.lua | 6 +- xmake/platforms/macosx/check.lua | 103 ++++++++ xmake/platforms/macosx/checker.lua | 108 -------- xmake/platforms/macosx/xmake.lua | 6 +- xmake/platforms/mingw/check.lua | 85 ++++++ xmake/platforms/mingw/checker.lua | 90 ------- xmake/platforms/mingw/xmake.lua | 4 +- xmake/platforms/watchos/check.lua | 103 ++++++++ xmake/platforms/watchos/checker.lua | 108 -------- xmake/platforms/watchos/xmake.lua | 6 +- xmake/platforms/windows/check.lua | 287 ++++++++++++++++++++ xmake/platforms/windows/checker.lua | 292 --------------------- xmake/platforms/windows/xmake.lua | 6 +- 26 files changed, 1054 insertions(+), 1197 deletions(-) delete mode 100644 xmake/core/platform/checker.lua create mode 100644 xmake/platforms/android/check.lua delete mode 100644 xmake/platforms/android/checker.lua create mode 100644 xmake/platforms/iphoneos/check.lua delete mode 100644 xmake/platforms/iphoneos/checker.lua create mode 100644 xmake/platforms/linux/check.lua delete mode 100644 xmake/platforms/linux/checker.lua create mode 100644 xmake/platforms/macosx/check.lua delete mode 100644 xmake/platforms/macosx/checker.lua create mode 100644 xmake/platforms/mingw/check.lua delete mode 100644 xmake/platforms/mingw/checker.lua create mode 100644 xmake/platforms/watchos/check.lua delete mode 100644 xmake/platforms/watchos/checker.lua create mode 100644 xmake/platforms/windows/check.lua delete mode 100644 xmake/platforms/windows/checker.lua diff --git a/xmake/core/platform/checker.lua b/xmake/core/platform/checker.lua deleted file mode 100644 index da0bd891f..000000000 --- a/xmake/core/platform/checker.lua +++ /dev/null @@ -1,144 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- 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) 2015 - 2016, ruki All rights reserved. --- --- @author ruki --- @file checker.lua --- - --- define module -local checker = checker or {} - --- load modules -local os = require("base/os") -local path = require("base/path") -local utils = require("base/utils") -local config = require("project/config") -local global = require("project/global") -local sandbox = require("sandbox/sandbox") -local platform = require("platform/platform") - --- check it -function checker._check(callers, ...) - - -- check all - for _, caller in ipairs(table.wrap(callers)) do - - -- has arguments? - local args = nil - if type(caller) == "table" then - if #caller > 1 then - args = caller[2] - end - caller = caller[1] - end - - -- check - assert(type(caller) == "function") - - -- call it - local ok, errors = sandbox.load(caller, ..., args) - if not ok then - return false, errors - end - end - - -- ok - return true -end - --- load the given checker from the given platform -function checker.load(plat) - - -- load platform - local instance, errors = platform.load(plat) - if not instance then - return nil, errors - end - - -- get checker - return instance:checker() -end - --- check the project or global configure --- --- @param name the configure name: global or config --- -function checker.check(name) - - -- check the project configure? - if name == "config" then - - -- get the current platform - local plat = config.get("plat") - if not plat then - return false, string.format("the current platform is unknown!") - end - - -- load the checker module - local module, errors = checker.load(plat) - if not module then - return false, errors - end - - -- check it - return checker._check(module.get("config"), config) - - -- check the global configure? - elseif name == "global" then - - -- check all platforms with the current host - for _, plat in ipairs(table.wrap(platform.plats())) do - - -- load platform - local instance, errors = platform.load(plat) - if not instance then - return false, errors - end - - -- belong to the current host? - for _, host in ipairs(table.wrap(instance:hosts())) do - if host == xmake._HOST then - - -- get the checker module - local module, errors = instance:checker() - if not module then - return false, errors - end - - -- check it - local ok, errors = checker._check(module.get("global"), global) - if not ok then - return false, errors - end - - -- ok - break - end - end - end - - -- ok - return true - end - - -- failed - return false, string.format("unknown check name: %s", name) -end - --- return module -return checker diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 079e42de3..ded064214 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -167,13 +167,6 @@ function _instance:tooldirs() return self._INFO.tooldirs end --- get the checker -function _instance:checker() - - -- load checker - return self:_load("checker") -end - -- get the environment function _instance:environment() @@ -213,7 +206,6 @@ function platform._interpreter() , "platform.set_hosts" , "platform.set_archs" , "platform.set_menu" - , "platform.set_checker" , "platform.set_tooldirs" , "platform.set_environment" } @@ -221,6 +213,7 @@ function platform._interpreter() { -- platform.on_xxx "platform.on_load" + , "platform.on_check" , "platform.on_install" , "platform.on_uninstall" } diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua index 897d1e669..9be136fa7 100644 --- a/xmake/core/sandbox/modules/import/core/project/config.lua +++ b/xmake/core/sandbox/modules/import/core/project/config.lua @@ -25,7 +25,6 @@ local sandbox_core_project_config = sandbox_core_project_config or {} -- load modules local config = require("project/config") -local checker = require("platform/checker") local platform = require("platform/platform") local raise = require("sandbox/modules/raise") @@ -133,12 +132,11 @@ end -- check the configure function sandbox_core_project_config.check() - -- check it - local ok, errors = checker.check("config") - if not ok then - raise(errors) + -- get the check script + local check = platform.get("check") + if check then + check("config") end - end -- dump the configure diff --git a/xmake/core/sandbox/modules/import/core/project/global.lua b/xmake/core/sandbox/modules/import/core/project/global.lua index d9d418b4f..26dc58676 100644 --- a/xmake/core/sandbox/modules/import/core/project/global.lua +++ b/xmake/core/sandbox/modules/import/core/project/global.lua @@ -24,8 +24,8 @@ local sandbox_core_project_global = sandbox_core_project_global or {} -- load modules +local table = require("base/table") local global = require("project/global") -local checker = require("platform/checker") local platform = require("platform/platform") local raise = require("sandbox/modules/raise") @@ -80,10 +80,31 @@ end -- check the configure function sandbox_core_project_global.check() - -- check it - local ok, errors = checker.check("global") - if not ok then - raise(errors) + -- check all platforms with the current host + for _, plat in ipairs(table.wrap(platform.plats())) do + + -- load platform + local instance, errors = platform.load(plat) + if not instance then + raise(errors) + end + + -- belong to the current host? + for _, host in ipairs(table.wrap(instance:hosts())) do + if host == xmake._HOST then + + -- get the check script + local check = instance:get("check") + if check ~= nil then + + -- check it + check("global") + end + + -- ok + break + end + end end end diff --git a/xmake/platforms/android/check.lua b/xmake/platforms/android/check.lua new file mode 100644 index 000000000..10c15e8cc --- /dev/null +++ b/xmake/platforms/android/check.lua @@ -0,0 +1,162 @@ +--!The Make-like Build Utility based on Lua +-- +-- 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) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.tool.tool") +import("platforms.checker", {rootdir = os.programdir()}) + +-- check the sdk version for ndk +function _check_ndk_sdkver(config) + + -- get ndk sdk version + local ndk_sdkver = config.get("ndk_sdkver") + if not ndk_sdkver then + + -- get the ndk + local ndk = config.get("ndk") + if ndk then + + -- match all sdk directories + local version_maxn = 0 + for _, sdkdir in ipairs(os.match(ndk .. "/platforms/android-*", true)) do + + -- get version + local filename = path.filename(sdkdir) + local version, count = filename:gsub("android%-", "") + if count > 0 then + + -- get the max version + version = tonumber(version) + if version > version_maxn then + version_maxn = version + end + end + end + + -- save the version + if version_maxn > 0 then ndk_sdkver = version_maxn end + end + + -- probe ok? update it + if ndk_sdkver ~= nil and ndk_sdkver > 0 then + + -- save it + config.set("ndk_sdkver", ndk_sdkver) + + -- trace + cprint("checking for the SDK version of NDK ... ${green}android-%d", ndk_sdkver) + else + + -- trace + cprint("checking for the SDK version of NDK ... ${red}no") + end + end +end + +-- check the toolchains +function _check_toolchains(config) + + -- get architecture + local arch = config.get("arch") + + -- get toolchains + local toolchains = config.get("toolchains") + if not toolchains then + + -- get ndk + local ndk = config.get("ndk") + if ndk then + + -- match all toolchains + if arch and arch:startswith("arm64") then + toolchains = os.match("%s/toolchains/aarch64-linux-android-**/prebuilt/*/bin/aarch64-linux-android-*", false, ndk) + else + toolchains = os.match("%s/toolchains/arm-linux-androideabi-**/prebuilt/*/bin/arm-linux-androideabi-*", false, ndk) + end + + -- save the toolchains directory + for _, filepath in ipairs(toolchains) do + config.set("toolchains", path.directory(filepath)) + break + end + end + end + + -- get toolchains version + local toolchains = config.get("toolchains") + if toolchains then + local pos, _, toolchains_ver = toolchains:find("%-(%d*%.%d*)[/\\]") + if pos and toolchains_ver then + + -- save the toolchains version + config.set("toolchains_ver", toolchains_ver) + + -- trace + cprint("checking for the version of toolchains ... ${green}%s", toolchains_ver) + else + -- trace + cprint("checking for the version of toolchains ... ${red}no") + end + end + + -- get cross + local cross = "arm-linux-androideabi-" + if arch and arch:startswith("arm64") then + cross = "aarch64-linux-android-" + end + + -- done + checker.check_toolchain(config, "cc", cross, "gcc", "the c compiler") + checker.check_toolchain(config, "cxx", cross, "g++", "the c++ compiler") + checker.check_toolchain(config, "as", cross, "gcc", "the assember") + checker.check_toolchain(config, "ld", cross, "g++", "the linker") + checker.check_toolchain(config, "ld", cross, "gcc", "the linker") + checker.check_toolchain(config, "ar", cross, "ar", "the static library archiver") + checker.check_toolchain(config, "ex", cross, "ar", "the static library extractor") + checker.check_toolchain(config, "sh", cross, "g++", "the shared library linker") + checker.check_toolchain(config, "sh", cross, "gcc", "the shared library linker") +end + +-- check it +function main(kind) + + -- init the check list of config + _g.config = + { + { checker.check_arch, "armv7-a" } + , checker.check_ccache + , _check_ndk_sdkver + , _check_toolchains + } + + -- init the check list of global + _g.global = + { + checker.check_ccache + , _check_ndk_sdkver + } + + -- check it + checker.check(kind, _g) +end + + diff --git a/xmake/platforms/android/checker.lua b/xmake/platforms/android/checker.lua deleted file mode 100644 index 4d6ac4087..000000000 --- a/xmake/platforms/android/checker.lua +++ /dev/null @@ -1,166 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- 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) 2015 - 2016, ruki All rights reserved. --- --- @author ruki --- @file checker.lua --- - --- imports -import("core.tool.tool") -import("platforms.checker", {rootdir = os.programdir()}) - --- check the sdk version for ndk -function _check_ndk_sdkver(config) - - -- get ndk sdk version - local ndk_sdkver = config.get("ndk_sdkver") - if not ndk_sdkver then - - -- get the ndk - local ndk = config.get("ndk") - if ndk then - - -- match all sdk directories - local version_maxn = 0 - for _, sdkdir in ipairs(os.match(ndk .. "/platforms/android-*", true)) do - - -- get version - local filename = path.filename(sdkdir) - local version, count = filename:gsub("android%-", "") - if count > 0 then - - -- get the max version - version = tonumber(version) - if version > version_maxn then - version_maxn = version - end - end - end - - -- save the version - if version_maxn > 0 then ndk_sdkver = version_maxn end - end - - -- probe ok? update it - if ndk_sdkver ~= nil and ndk_sdkver > 0 then - - -- save it - config.set("ndk_sdkver", ndk_sdkver) - - -- trace - cprint("checking for the SDK version of NDK ... ${green}android-%d", ndk_sdkver) - else - - -- trace - cprint("checking for the SDK version of NDK ... ${red}no") - end - end -end - --- check the toolchains -function _check_toolchains(config) - - -- get architecture - local arch = config.get("arch") - - -- get toolchains - local toolchains = config.get("toolchains") - if not toolchains then - - -- get ndk - local ndk = config.get("ndk") - if ndk then - - -- match all toolchains - if arch and arch:startswith("arm64") then - toolchains = os.match("%s/toolchains/aarch64-linux-android-**/prebuilt/*/bin/aarch64-linux-android-*", false, ndk) - else - toolchains = os.match("%s/toolchains/arm-linux-androideabi-**/prebuilt/*/bin/arm-linux-androideabi-*", false, ndk) - end - - -- save the toolchains directory - for _, filepath in ipairs(toolchains) do - config.set("toolchains", path.directory(filepath)) - break - end - end - end - - -- get toolchains version - local toolchains = config.get("toolchains") - if toolchains then - local pos, _, toolchains_ver = toolchains:find("%-(%d*%.%d*)[/\\]") - if pos and toolchains_ver then - - -- save the toolchains version - config.set("toolchains_ver", toolchains_ver) - - -- trace - cprint("checking for the version of toolchains ... ${green}%s", toolchains_ver) - else - -- trace - cprint("checking for the version of toolchains ... ${red}no") - end - end - - -- get cross - local cross = "arm-linux-androideabi-" - if arch and arch:startswith("arm64") then - cross = "aarch64-linux-android-" - end - - -- done - checker.check_toolchain(config, "cc", cross, "gcc", "the c compiler") - checker.check_toolchain(config, "cxx", cross, "g++", "the c++ compiler") - checker.check_toolchain(config, "as", cross, "gcc", "the assember") - checker.check_toolchain(config, "ld", cross, "g++", "the linker") - checker.check_toolchain(config, "ld", cross, "gcc", "the linker") - checker.check_toolchain(config, "ar", cross, "ar", "the static library archiver") - checker.check_toolchain(config, "ex", cross, "ar", "the static library extractor") - checker.check_toolchain(config, "sh", cross, "g++", "the shared library linker") - checker.check_toolchain(config, "sh", cross, "gcc", "the shared library linker") -end - --- init it -function init() - - -- init the check list of config - _g.config = - { - { checker.check_arch, "armv7-a" } - , checker.check_ccache - , _check_ndk_sdkver - , _check_toolchains - } - - -- init the check list of global - _g.global = - { - checker.check_ccache - , _check_ndk_sdkver - } - -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua index 7595d78c7..83ad9d17d 100755 --- a/xmake/platforms/android/xmake.lua +++ b/xmake/platforms/android/xmake.lua @@ -32,12 +32,12 @@ platform("android") -- set archs set_archs("armv5te", "armv6", "armv7-a", "armv8-a", "arm64-v8a") - -- set checker - set_checker("checker") - -- set tooldirs set_tooldirs("/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin") + -- on check + on_check("check") + -- on load on_load(function () diff --git a/xmake/platforms/checker.lua b/xmake/platforms/checker.lua index 8b30f7dd5..02d5daa71 100644 --- a/xmake/platforms/checker.lua +++ b/xmake/platforms/checker.lua @@ -23,6 +23,29 @@ -- imports import("core.tool.tool") +-- check all for the given config kind +function check(kind, checkers) + + -- import config module + local config = import("core.project." .. kind) + + -- check all + for _, checker in ipairs(checkers[kind]) do + + -- has arguments? + local args = nil + if type(checker) == "table" then + if #checker > 1 then + args = checker[2] + end + checker = checker[1] + end + + -- check it + checker(config, args) + end +end + -- check the architecture function check_arch(config, default) diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua new file mode 100644 index 000000000..c3eeee453 --- /dev/null +++ b/xmake/platforms/iphoneos/check.lua @@ -0,0 +1,103 @@ +--!The Make-like Build Utility based on Lua +-- +-- 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) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.tool.tool") +import("platforms.checker", {rootdir = os.programdir()}) + +-- check the as +function _check_as(shellname) + + -- make an empty tmp.S + local tmpfile = path.join(os.tmpdir(), "xmake.checker.as.S") + io.write(tmpfile, "") + + -- check it + os.run("%s -arch armv7 -o %s -c %s", shellname, os.nuldev(), tmpfile) + + -- remove this tmp.S + os.rm(tmpfile) +end + +-- check the toolchains +function _check_toolchains(config) + + -- iphoneos or iphonesimulator? + local arch = config.get("arch") + if arch == "i386" or arch == "x86_64" then + checker.check_toolchain(config, "cc", "xcrun -sdk iphonesimulator ", "clang", "the c compiler") + checker.check_toolchain(config, "cxx", "xcrun -sdk iphonesimulator ", "clang", "the c++ compiler") + checker.check_toolchain(config, "cxx", "xcrun -sdk iphonesimulator ", "clang++", "the c++ compiler") + checker.check_toolchain(config, "mm", "xcrun -sdk iphonesimulator ", "clang", "the objc compiler") + checker.check_toolchain(config, "mxx", "xcrun -sdk iphonesimulator ", "clang++", "the objc++ compiler") + checker.check_toolchain(config, "mxx", "xcrun -sdk iphonesimulator ", "clang", "the objc++ compiler") + checker.check_toolchain(config, "as", "xcrun -sdk iphonesimulator ", "clang", "the assember") + checker.check_toolchain(config, "ld", "xcrun -sdk iphonesimulator ", "clang++", "the linker") + checker.check_toolchain(config, "ld", "xcrun -sdk iphonesimulator ", "clang", "the linker") + checker.check_toolchain(config, "ar", "xcrun -sdk iphonesimulator ", "ar", "the static library archiver") + checker.check_toolchain(config, "ex", "xcrun -sdk iphonesimulator ", "ar", "the static library extractor") + checker.check_toolchain(config, "sh", "xcrun -sdk iphonesimulator ", "clang++", "the shared library linker") + checker.check_toolchain(config, "sh", "xcrun -sdk iphonesimulator ", "clang", "the shared library linker") + checker.check_toolchain(config, "sc", "xcrun -sdk iphonesimulator ", "swiftc", "the swift compiler") + else + checker.check_toolchain(config, "cc", "xcrun -sdk iphoneos ", "clang", "the c compiler") + checker.check_toolchain(config, "cxx", "xcrun -sdk iphoneos ", "clang", "the c++ compiler") + checker.check_toolchain(config, "cxx", "xcrun -sdk iphoneos ", "clang++", "the c++ compiler") + checker.check_toolchain(config, "mm", "xcrun -sdk iphoneos ", "clang", "the objc compiler") + checker.check_toolchain(config, "mxx", "xcrun -sdk iphoneos ", "clang++", "the objc++ compiler") + checker.check_toolchain(config, "mxx", "xcrun -sdk iphoneos ", "clang", "the objc++ compiler") + checker.check_toolchain(config, "as", path.join(os.toolsdir(), "utils/gas-preprocessor.pl xcrun -sdk iphoneos "), "clang", "the assember", _check_as) + checker.check_toolchain(config, "ld", "xcrun -sdk iphoneos ", "clang++", "the linker") + checker.check_toolchain(config, "ld", "xcrun -sdk iphoneos ", "clang", "the linker") + checker.check_toolchain(config, "ar", "xcrun -sdk iphoneos ", "ar", "the static library archiver") + checker.check_toolchain(config, "ex", "xcrun -sdk iphoneos ", "ar", "the static library extractor") + checker.check_toolchain(config, "sh", "xcrun -sdk iphoneos ", "clang++", "the shared library linker") + checker.check_toolchain(config, "sh", "xcrun -sdk iphoneos ", "clang", "the shared library linker") + checker.check_toolchain(config, "sc", "xcrun -sdk iphoneos ", "swiftc", "the swift compiler") + end +end + +-- check it +function main(kind) + + -- init the check list of config + _g.config = + { + { checker.check_arch, "armv7" } + , checker.check_xcode + , checker.check_xcode_sdkver + , checker.check_target_minver + , checker.check_ccache + , _check_toolchains + } + + -- init the check list of global + _g.global = + { + checker.check_xcode + , checker.check_ccache + } + + -- check it + checker.check(kind, _g) +end + diff --git a/xmake/platforms/iphoneos/checker.lua b/xmake/platforms/iphoneos/checker.lua deleted file mode 100644 index 47face8ef..000000000 --- a/xmake/platforms/iphoneos/checker.lua +++ /dev/null @@ -1,108 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- 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) 2015 - 2016, ruki All rights reserved. --- --- @author ruki --- @file checker.lua --- - --- imports -import("core.tool.tool") -import("platforms.checker", {rootdir = os.programdir()}) - --- check the as -function _check_as(shellname) - - -- make an empty tmp.S - local tmpfile = path.join(os.tmpdir(), "xmake.checker.as.S") - io.write(tmpfile, "") - - -- check it - os.run("%s -arch armv7 -o %s -c %s", shellname, os.nuldev(), tmpfile) - - -- remove this tmp.S - os.rm(tmpfile) -end - --- check the toolchains -function _check_toolchains(config) - - -- iphoneos or iphonesimulator? - local arch = config.get("arch") - if arch == "i386" or arch == "x86_64" then - checker.check_toolchain(config, "cc", "xcrun -sdk iphonesimulator ", "clang", "the c compiler") - checker.check_toolchain(config, "cxx", "xcrun -sdk iphonesimulator ", "clang", "the c++ compiler") - checker.check_toolchain(config, "cxx", "xcrun -sdk iphonesimulator ", "clang++", "the c++ compiler") - checker.check_toolchain(config, "mm", "xcrun -sdk iphonesimulator ", "clang", "the objc compiler") - checker.check_toolchain(config, "mxx", "xcrun -sdk iphonesimulator ", "clang++", "the objc++ compiler") - checker.check_toolchain(config, "mxx", "xcrun -sdk iphonesimulator ", "clang", "the objc++ compiler") - checker.check_toolchain(config, "as", "xcrun -sdk iphonesimulator ", "clang", "the assember") - checker.check_toolchain(config, "ld", "xcrun -sdk iphonesimulator ", "clang++", "the linker") - checker.check_toolchain(config, "ld", "xcrun -sdk iphonesimulator ", "clang", "the linker") - checker.check_toolchain(config, "ar", "xcrun -sdk iphonesimulator ", "ar", "the static library archiver") - checker.check_toolchain(config, "ex", "xcrun -sdk iphonesimulator ", "ar", "the static library extractor") - checker.check_toolchain(config, "sh", "xcrun -sdk iphonesimulator ", "clang++", "the shared library linker") - checker.check_toolchain(config, "sh", "xcrun -sdk iphonesimulator ", "clang", "the shared library linker") - checker.check_toolchain(config, "sc", "xcrun -sdk iphonesimulator ", "swiftc", "the swift compiler") - else - checker.check_toolchain(config, "cc", "xcrun -sdk iphoneos ", "clang", "the c compiler") - checker.check_toolchain(config, "cxx", "xcrun -sdk iphoneos ", "clang", "the c++ compiler") - checker.check_toolchain(config, "cxx", "xcrun -sdk iphoneos ", "clang++", "the c++ compiler") - checker.check_toolchain(config, "mm", "xcrun -sdk iphoneos ", "clang", "the objc compiler") - checker.check_toolchain(config, "mxx", "xcrun -sdk iphoneos ", "clang++", "the objc++ compiler") - checker.check_toolchain(config, "mxx", "xcrun -sdk iphoneos ", "clang", "the objc++ compiler") - checker.check_toolchain(config, "as", path.join(os.toolsdir(), "utils/gas-preprocessor.pl xcrun -sdk iphoneos "), "clang", "the assember", _check_as) - checker.check_toolchain(config, "ld", "xcrun -sdk iphoneos ", "clang++", "the linker") - checker.check_toolchain(config, "ld", "xcrun -sdk iphoneos ", "clang", "the linker") - checker.check_toolchain(config, "ar", "xcrun -sdk iphoneos ", "ar", "the static library archiver") - checker.check_toolchain(config, "ex", "xcrun -sdk iphoneos ", "ar", "the static library extractor") - checker.check_toolchain(config, "sh", "xcrun -sdk iphoneos ", "clang++", "the shared library linker") - checker.check_toolchain(config, "sh", "xcrun -sdk iphoneos ", "clang", "the shared library linker") - checker.check_toolchain(config, "sc", "xcrun -sdk iphoneos ", "swiftc", "the swift compiler") - end -end - --- init it -function init() - - -- init the check list of config - _g.config = - { - { checker.check_arch, "armv7" } - , checker.check_xcode - , checker.check_xcode_sdkver - , checker.check_target_minver - , checker.check_ccache - , _check_toolchains - } - - -- init the check list of global - _g.global = - { - checker.check_xcode - , checker.check_ccache - } - -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index 869ab3e60..dfbf3a1c7 100755 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -32,12 +32,12 @@ platform("iphoneos") -- set archs set_archs("armv7", "armv7s", "arm64", "i386", "x86_64") - -- set checker - set_checker("checker") - -- set tooldirs set_tooldirs("/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin") + -- on check + on_check("check") + -- on load on_load(function () diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua new file mode 100644 index 000000000..5912dc348 --- /dev/null +++ b/xmake/platforms/linux/check.lua @@ -0,0 +1,137 @@ +--!The Make-like Build Utility based on Lua +-- +-- 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) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file check.lua +-- + +-- 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", ifelse(config.get("cross"), "none", os.arch())) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + end +end + +-- check the toolchains +function _check_toolchains(config) + + -- get toolchains + local toolchains = config.get("toolchains") + if not toolchains then + local sdkdir = config.get("sdk") + if sdkdir then + toolchains = path.join(sdkdir, "bin") + end + end + + -- get cross + local cross = "" + if toolchains then + local ldpathes = os.match(path.join(toolchains, "*-ld")) + for _, ldpath in ipairs(ldpathes) do + local ldname = path.basename(ldpath) + if ldname then + cross = ldname:sub(1, -3) + end + end + end + + -- no cross toolchains? + if cross and cross:trim() == "" then + -- check from env + checker.check_toolchain_from_env(config, "cc", "CC", "the c compiler") + checker.check_toolchain_from_env(config, "cxx", "CXX", "the c++ compiler") + checker.check_toolchain_from_env(config, "mm", "MM", "the objc compiler") + checker.check_toolchain_from_env(config, "mxx", "MXX", "the objc++ compiler") + checker.check_toolchain_from_env(config, "as", "AS", "the assember") + checker.check_toolchain_from_env(config, "ld", "LD", "the linker") + checker.check_toolchain_from_env(config, "ar", "AR", "the static library archiver") + checker.check_toolchain_from_env(config, "ex", "AR", "the static library extractor") + checker.check_toolchain_from_env(config, "sh", "SH", "the shared library linker") + checker.check_toolchain_from_env(config, "sc", "SC", "the swift compiler") + checker.check_toolchain_from_env(config, "dd", "DD", "the debugger") + end + + -- check for gcc + checker.check_toolchain(config, "cc", cross, "gcc", "the c compiler") + checker.check_toolchain(config, "cxx", cross, "gcc", "the c++ compiler") + checker.check_toolchain(config, "cxx", cross, "g++", "the c++ compiler") + checker.check_toolchain(config, "mm", cross, "gcc", "the objc compiler") + checker.check_toolchain(config, "mxx", cross, "gcc", "the objc++ compiler") + checker.check_toolchain(config, "mxx", cross, "g++", "the objc++ compiler") + checker.check_toolchain(config, "as", cross, "gcc", "the assember") + checker.check_toolchain(config, "ld", cross, "g++", "the linker") + checker.check_toolchain(config, "ld", cross, "gcc", "the linker") + checker.check_toolchain(config, "ar", cross, "ar", "the static library archiver") + checker.check_toolchain(config, "ex", cross, "ar", "the static library extractor") + checker.check_toolchain(config, "sh", cross, "g++", "the shared library linker") + checker.check_toolchain(config, "sh", cross, "gcc", "the shared library linker") + checker.check_toolchain(config, "dd", cross, "gdb", "the debugger") + + -- check for clang + checker.check_toolchain(config, "cc", cross, "clang", "the c compiler") + checker.check_toolchain(config, "cxx", cross, "clang", "the c++ compiler") + checker.check_toolchain(config, "cxx", cross, "clang++", "the c++ compiler") + checker.check_toolchain(config, "mm", cross, "clang", "the objc compiler") + checker.check_toolchain(config, "mxx", cross, "clang++", "the objc++ compiler") + checker.check_toolchain(config, "mxx", cross, "clang", "the objc++ compiler") + checker.check_toolchain(config, "as", cross, "clang", "the assember") + checker.check_toolchain(config, "ld", cross, "clang++", "the linker") + checker.check_toolchain(config, "ld", cross, "clang", "the linker") + checker.check_toolchain(config, "ar", cross, "ar", "the static library archiver") + checker.check_toolchain(config, "ex", cross, "ar", "the static library extractor") + checker.check_toolchain(config, "sh", cross, "clang++", "the shared library linker") + checker.check_toolchain(config, "sh", cross, "clang", "the shared library linker") + checker.check_toolchain(config, "sc", cross, "swiftc", "the swift compiler") + checker.check_toolchain(config, "dd", cross, "lldb", "the debugger") +end + +-- check it +function main(kind) + + -- init the check list of config + _g.config = + { + __check_arch + , checker.check_ccache + , _check_toolchains + } + + -- init the check list of global + _g.global = + { + checker.check_ccache + , _check_ndk_sdkver + } + + -- check it + checker.check(kind, _g) +end + diff --git a/xmake/platforms/linux/checker.lua b/xmake/platforms/linux/checker.lua deleted file mode 100644 index b295db26a..000000000 --- a/xmake/platforms/linux/checker.lua +++ /dev/null @@ -1,142 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- 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) 2015 - 2016, ruki All rights reserved. --- --- @author ruki --- @file checker.lua --- - --- 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", ifelse(config.get("cross"), "none", os.arch())) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- check the toolchains -function _check_toolchains(config) - - -- get toolchains - local toolchains = config.get("toolchains") - if not toolchains then - local sdkdir = config.get("sdk") - if sdkdir then - toolchains = path.join(sdkdir, "bin") - end - end - - -- get cross - local cross = "" - if toolchains then - local ldpathes = os.match(path.join(toolchains, "*-ld")) - for _, ldpath in ipairs(ldpathes) do - local ldname = path.basename(ldpath) - if ldname then - cross = ldname:sub(1, -3) - end - end - end - - -- no cross toolchains? - if cross and cross:trim() == "" then - -- check from env - checker.check_toolchain_from_env(config, "cc", "CC", "the c compiler") - checker.check_toolchain_from_env(config, "cxx", "CXX", "the c++ compiler") - checker.check_toolchain_from_env(config, "mm", "MM", "the objc compiler") - checker.check_toolchain_from_env(config, "mxx", "MXX", "the objc++ compiler") - checker.check_toolchain_from_env(config, "as", "AS", "the assember") - checker.check_toolchain_from_env(config, "ld", "LD", "the linker") - checker.check_toolchain_from_env(config, "ar", "AR", "the static library archiver") - checker.check_toolchain_from_env(config, "ex", "AR", "the static library extractor") - checker.check_toolchain_from_env(config, "sh", "SH", "the shared library linker") - checker.check_toolchain_from_env(config, "sc", "SC", "the swift compiler") - checker.check_toolchain_from_env(config, "dd", "DD", "the debugger") - end - - -- check for gcc - checker.check_toolchain(config, "cc", cross, "gcc", "the c compiler") - checker.check_toolchain(config, "cxx", cross, "gcc", "the c++ compiler") - checker.check_toolchain(config, "cxx", cross, "g++", "the c++ compiler") - checker.check_toolchain(config, "mm", cross, "gcc", "the objc compiler") - checker.check_toolchain(config, "mxx", cross, "gcc", "the objc++ compiler") - checker.check_toolchain(config, "mxx", cross, "g++", "the objc++ compiler") - checker.check_toolchain(config, "as", cross, "gcc", "the assember") - checker.check_toolchain(config, "ld", cross, "g++", "the linker") - checker.check_toolchain(config, "ld", cross, "gcc", "the linker") - checker.check_toolchain(config, "ar", cross, "ar", "the static library archiver") - checker.check_toolchain(config, "ex", cross, "ar", "the static library extractor") - checker.check_toolchain(config, "sh", cross, "g++", "the shared library linker") - checker.check_toolchain(config, "sh", cross, "gcc", "the shared library linker") - checker.check_toolchain(config, "dd", cross, "gdb", "the debugger") - - -- check for clang - checker.check_toolchain(config, "cc", cross, "clang", "the c compiler") - checker.check_toolchain(config, "cxx", cross, "clang", "the c++ compiler") - checker.check_toolchain(config, "cxx", cross, "clang++", "the c++ compiler") - checker.check_toolchain(config, "mm", cross, "clang", "the objc compiler") - checker.check_toolchain(config, "mxx", cross, "clang++", "the objc++ compiler") - checker.check_toolchain(config, "mxx", cross, "clang", "the objc++ compiler") - checker.check_toolchain(config, "as", cross, "clang", "the assember") - checker.check_toolchain(config, "ld", cross, "clang++", "the linker") - checker.check_toolchain(config, "ld", cross, "clang", "the linker") - checker.check_toolchain(config, "ar", cross, "ar", "the static library archiver") - checker.check_toolchain(config, "ex", cross, "ar", "the static library extractor") - checker.check_toolchain(config, "sh", cross, "clang++", "the shared library linker") - checker.check_toolchain(config, "sh", cross, "clang", "the shared library linker") - checker.check_toolchain(config, "sc", cross, "swiftc", "the swift compiler") - checker.check_toolchain(config, "dd", cross, "lldb", "the debugger") -end - --- init it -function init() - - -- init the check list of config - _g.config = - { - __check_arch - , checker.check_ccache - , _check_toolchains - } - - -- init the check list of global - _g.global = - { - checker.check_ccache - , _check_ndk_sdkver - } - -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index 9a64b8918..bfefad521 100755 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -32,9 +32,6 @@ platform("linux") -- set archs set_archs("i386", "x86_64") - -- set checker - set_checker("checker") - -- set tooldirs set_tooldirs("/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin") @@ -44,6 +41,9 @@ platform("linux") -- on uninstall on_uninstall("uninstall") + -- on check + on_check("check") + -- on load on_load(function () diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua new file mode 100644 index 000000000..cea1708f3 --- /dev/null +++ b/xmake/platforms/macosx/check.lua @@ -0,0 +1,103 @@ +--!The Make-like Build Utility based on Lua +-- +-- 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) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.tool.tool") +import("platforms.checker", {rootdir = os.programdir()}) + +-- check the toolchains +function _check_toolchains(config) + + -- check from env + checker.check_toolchain_from_env(config, "cc", "CC", "the c compiler") + checker.check_toolchain_from_env(config, "cxx", "CXX", "the c++ compiler") + checker.check_toolchain_from_env(config, "mm", "MM", "the objc compiler") + checker.check_toolchain_from_env(config, "mxx", "MXX", "the objc++ compiler") + checker.check_toolchain_from_env(config, "sc", "SC", "the swift compiler") + checker.check_toolchain_from_env(config, "as", "AS", "the assember") + checker.check_toolchain_from_env(config, "ld", "LD", "the linker") + checker.check_toolchain_from_env(config, "ar", "AR", "the static library archiver") + checker.check_toolchain_from_env(config, "ex", "AR", "the static library extractor") + checker.check_toolchain_from_env(config, "sh", "SH", "the shared library linker") + checker.check_toolchain_from_env(config, "dd", "DD", "the debugger") + + -- check with xcrun + 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, "sc", "xcrun -sdk macosx ", "swiftc", "the swift 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 archiver") + checker.check_toolchain(config, "ex", "xcrun -sdk macosx ", "ar", "the static library extractor") + 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, "dd", "xcrun -sdk macosx ", "lldb", "the debugger") + + -- check without xcrun + checker.check_toolchain(config, "cc", "", "clang", "the c compiler") + checker.check_toolchain(config, "cxx", "", "clang", "the c++ compiler") + checker.check_toolchain(config, "cxx", "", "clang++", "the c++ compiler") + checker.check_toolchain(config, "mm", "", "clang", "the objc compiler") + checker.check_toolchain(config, "mxx", "", "clang++", "the objc++ compiler") + checker.check_toolchain(config, "mxx", "", "clang", "the objc++ compiler") + checker.check_toolchain(config, "go", "", "go", "the golang compiler") + checker.check_toolchain(config, "sc", "", "swiftc", "the swift compiler") + checker.check_toolchain(config, "as", "", "clang", "the assember") + checker.check_toolchain(config, "ld", "", "clang++", "the linker") + checker.check_toolchain(config, "ld", "", "clang", "the linker") + checker.check_toolchain(config, "ar", "", "ar", "the static library archiver") + checker.check_toolchain(config, "ex", "", "ar", "the static library extractor") + checker.check_toolchain(config, "sh", "", "clang++", "the shared library linker") + checker.check_toolchain(config, "sh", "", "clang", "the shared library linker") + checker.check_toolchain(config, "dd", "", "lldb", "the debugger") +end + +-- check it +function main(kind) + + -- init the check list of config + _g.config = + { + checker.check_arch + , checker.check_xcode + , checker.check_xcode_sdkver + , checker.check_target_minver + , checker.check_ccache + , _check_toolchains + } + + -- init the check list of global + _g.global = + { + checker.check_xcode + , checker.check_ccache + } + + -- check it + checker.check(kind, _g) +end + diff --git a/xmake/platforms/macosx/checker.lua b/xmake/platforms/macosx/checker.lua deleted file mode 100644 index bf6789733..000000000 --- a/xmake/platforms/macosx/checker.lua +++ /dev/null @@ -1,108 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- 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) 2015 - 2016, ruki All rights reserved. --- --- @author ruki --- @file checker.lua --- - --- imports -import("core.tool.tool") -import("platforms.checker", {rootdir = os.programdir()}) - --- check the toolchains -function _check_toolchains(config) - - -- check from env - checker.check_toolchain_from_env(config, "cc", "CC", "the c compiler") - checker.check_toolchain_from_env(config, "cxx", "CXX", "the c++ compiler") - checker.check_toolchain_from_env(config, "mm", "MM", "the objc compiler") - checker.check_toolchain_from_env(config, "mxx", "MXX", "the objc++ compiler") - checker.check_toolchain_from_env(config, "sc", "SC", "the swift compiler") - checker.check_toolchain_from_env(config, "as", "AS", "the assember") - checker.check_toolchain_from_env(config, "ld", "LD", "the linker") - checker.check_toolchain_from_env(config, "ar", "AR", "the static library archiver") - checker.check_toolchain_from_env(config, "ex", "AR", "the static library extractor") - checker.check_toolchain_from_env(config, "sh", "SH", "the shared library linker") - checker.check_toolchain_from_env(config, "dd", "DD", "the debugger") - - -- check with xcrun - 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, "sc", "xcrun -sdk macosx ", "swiftc", "the swift 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 archiver") - checker.check_toolchain(config, "ex", "xcrun -sdk macosx ", "ar", "the static library extractor") - 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, "dd", "xcrun -sdk macosx ", "lldb", "the debugger") - - -- check without xcrun - checker.check_toolchain(config, "cc", "", "clang", "the c compiler") - checker.check_toolchain(config, "cxx", "", "clang", "the c++ compiler") - checker.check_toolchain(config, "cxx", "", "clang++", "the c++ compiler") - checker.check_toolchain(config, "mm", "", "clang", "the objc compiler") - checker.check_toolchain(config, "mxx", "", "clang++", "the objc++ compiler") - checker.check_toolchain(config, "mxx", "", "clang", "the objc++ compiler") - checker.check_toolchain(config, "go", "", "go", "the golang compiler") - checker.check_toolchain(config, "sc", "", "swiftc", "the swift compiler") - checker.check_toolchain(config, "as", "", "clang", "the assember") - checker.check_toolchain(config, "ld", "", "clang++", "the linker") - checker.check_toolchain(config, "ld", "", "clang", "the linker") - checker.check_toolchain(config, "ar", "", "ar", "the static library archiver") - checker.check_toolchain(config, "ex", "", "ar", "the static library extractor") - checker.check_toolchain(config, "sh", "", "clang++", "the shared library linker") - checker.check_toolchain(config, "sh", "", "clang", "the shared library linker") - checker.check_toolchain(config, "dd", "", "lldb", "the debugger") -end - --- init it -function init() - - -- init the check list of config - _g.config = - { - checker.check_arch - , checker.check_xcode - , checker.check_xcode_sdkver - , checker.check_target_minver - , checker.check_ccache - , _check_toolchains - } - - -- init the check list of global - _g.global = - { - checker.check_xcode - , checker.check_ccache - } - -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index c6c3588e5..e6248e7c2 100755 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -32,12 +32,12 @@ platform("macosx") -- set archs set_archs("i386", "x86_64") - -- set checker - set_checker("checker") - -- set tooldirs set_tooldirs("/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin") + -- on check + on_check("check") + -- on install on_install("install") diff --git a/xmake/platforms/mingw/check.lua b/xmake/platforms/mingw/check.lua new file mode 100644 index 000000000..06ca8b2b4 --- /dev/null +++ b/xmake/platforms/mingw/check.lua @@ -0,0 +1,85 @@ +--!The Make-like Build Utility based on Lua +-- +-- 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) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.tool.tool") +import("platforms.checker", {rootdir = os.programdir()}) + +-- check the toolchains +function _check_toolchains(config) + + -- get toolchains + local toolchains = config.get("toolchains") + if not toolchains then + local sdkdir = config.get("sdk") + if sdkdir then + toolchains = path.join(sdkdir, "bin") + end + end + + -- get cross + local cross = "" + if toolchains then + local ldpathes = os.match(path.join(toolchains, "*-ld")) + for _, ldpath in ipairs(ldpathes) do + local ldname = path.basename(ldpath) + if ldname then + cross = ldname:sub(1, -3) + end + end + end + + -- done + checker.check_toolchain(config, "cc", cross, "gcc", "the c compiler") + checker.check_toolchain(config, "cxx", cross, "g++", "the c++ compiler") + checker.check_toolchain(config, "cxx", cross, "gcc", "the c++ compiler") + checker.check_toolchain(config, "as", cross, "gcc", "the assember") + checker.check_toolchain(config, "ld", cross, "g++", "the linker") + checker.check_toolchain(config, "ld", cross, "gcc", "the linker") + checker.check_toolchain(config, "ar", cross, "ar", "the static library archiver") + checker.check_toolchain(config, "ex", cross, "ar", "the static library extractor") + checker.check_toolchain(config, "sh", cross, "g++", "the shared library linker") + checker.check_toolchain(config, "sh", cross, "gcc", "the shared library linker") + checker.check_toolchain(config, "sc", cross, "swiftc", "the swift compiler") +end + +-- check it +function main(kind) + + -- init the check list of config + _g.config = + { + { checker.check_arch, "i386" } + , checker.check_ccache + , _check_toolchains + } + + -- init the check list of global + _g.global = + { + checker.check_ccache + } + + -- check it + checker.check(kind, _g) +end + diff --git a/xmake/platforms/mingw/checker.lua b/xmake/platforms/mingw/checker.lua deleted file mode 100644 index 0a59fe8e7..000000000 --- a/xmake/platforms/mingw/checker.lua +++ /dev/null @@ -1,90 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- 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) 2015 - 2016, ruki All rights reserved. --- --- @author ruki --- @file checker.lua --- - --- imports -import("core.tool.tool") -import("platforms.checker", {rootdir = os.programdir()}) - --- check the toolchains -function _check_toolchains(config) - - -- get toolchains - local toolchains = config.get("toolchains") - if not toolchains then - local sdkdir = config.get("sdk") - if sdkdir then - toolchains = path.join(sdkdir, "bin") - end - end - - -- get cross - local cross = "" - if toolchains then - local ldpathes = os.match(path.join(toolchains, "*-ld")) - for _, ldpath in ipairs(ldpathes) do - local ldname = path.basename(ldpath) - if ldname then - cross = ldname:sub(1, -3) - end - end - end - - -- done - checker.check_toolchain(config, "cc", cross, "gcc", "the c compiler") - checker.check_toolchain(config, "cxx", cross, "g++", "the c++ compiler") - checker.check_toolchain(config, "cxx", cross, "gcc", "the c++ compiler") - checker.check_toolchain(config, "as", cross, "gcc", "the assember") - checker.check_toolchain(config, "ld", cross, "g++", "the linker") - checker.check_toolchain(config, "ld", cross, "gcc", "the linker") - checker.check_toolchain(config, "ar", cross, "ar", "the static library archiver") - checker.check_toolchain(config, "ex", cross, "ar", "the static library extractor") - checker.check_toolchain(config, "sh", cross, "g++", "the shared library linker") - checker.check_toolchain(config, "sh", cross, "gcc", "the shared library linker") - checker.check_toolchain(config, "sc", cross, "swiftc", "the swift compiler") -end - --- init it -function init() - - -- init the check list of config - _g.config = - { - { checker.check_arch, "i386" } - , checker.check_ccache - , _check_toolchains - } - - -- init the check list of global - _g.global = - { - checker.check_ccache - } - -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - diff --git a/xmake/platforms/mingw/xmake.lua b/xmake/platforms/mingw/xmake.lua index 66f15d7ba..03e259186 100755 --- a/xmake/platforms/mingw/xmake.lua +++ b/xmake/platforms/mingw/xmake.lua @@ -32,8 +32,8 @@ platform("mingw") -- set archs set_archs("i386", "x86_64") - -- set checker - set_checker("checker") + -- on check + on_check("check") -- on load on_load(function () diff --git a/xmake/platforms/watchos/check.lua b/xmake/platforms/watchos/check.lua new file mode 100644 index 000000000..a540dfbb0 --- /dev/null +++ b/xmake/platforms/watchos/check.lua @@ -0,0 +1,103 @@ +--!The Make-like Build Utility based on Lua +-- +-- 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) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.tool.tool") +import("platforms.checker", {rootdir = os.programdir()}) + +-- check the as +function _check_as(shellname) + + -- make an empty tmp.S + local tmpfile = path.join(os.tmpdir(), "xmake.checker.as.S") + io.write(tmpfile, "") + + -- check it + os.run("%s -arch armv7 -o %s -c %s", shellname, os.nuldev(), tmpfile) + + -- remove this tmp.S + os.rm(tmpfile) +end + +-- check the toolchains +function _check_toolchains(config) + + -- watchos or watchsimulator? + local arch = config.get("arch") + if arch == "i386" then + checker.check_toolchain(config, "cc", "xcrun -sdk watchsimulator ", "clang", "the c compiler") + checker.check_toolchain(config, "cxx", "xcrun -sdk watchsimulator ", "clang", "the c++ compiler") + checker.check_toolchain(config, "cxx", "xcrun -sdk watchsimulator ", "clang++", "the c++ compiler") + checker.check_toolchain(config, "mm", "xcrun -sdk watchsimulator ", "clang", "the objc compiler") + checker.check_toolchain(config, "mxx", "xcrun -sdk watchsimulator ", "clang++", "the objc++ compiler") + checker.check_toolchain(config, "mxx", "xcrun -sdk watchsimulator ", "clang", "the objc++ compiler") + checker.check_toolchain(config, "as", "xcrun -sdk watchsimulator ", "clang", "the assember") + checker.check_toolchain(config, "ld", "xcrun -sdk watchsimulator ", "clang++", "the linker") + checker.check_toolchain(config, "ld", "xcrun -sdk watchsimulator ", "clang", "the linker") + checker.check_toolchain(config, "ar", "xcrun -sdk watchsimulator ", "ar", "the static library archiver") + checker.check_toolchain(config, "ex", "xcrun -sdk watchsimulator ", "ar", "the static library extractor") + checker.check_toolchain(config, "sh", "xcrun -sdk watchsimulator ", "clang++", "the shared library linker") + checker.check_toolchain(config, "sh", "xcrun -sdk watchsimulator ", "clang", "the shared library linker") + checker.check_toolchain(config, "sc", "xcrun -sdk watchsimulator ", "swiftc", "the swift compiler") + else + checker.check_toolchain(config, "cc", "xcrun -sdk watchos ", "clang", "the c compiler") + checker.check_toolchain(config, "cxx", "xcrun -sdk watchos ", "clang", "the c++ compiler") + checker.check_toolchain(config, "cxx", "xcrun -sdk watchos ", "clang++", "the c++ compiler") + checker.check_toolchain(config, "mm", "xcrun -sdk watchos ", "clang", "the objc compiler") + checker.check_toolchain(config, "mxx", "xcrun -sdk watchos ", "clang++", "the objc++ compiler") + checker.check_toolchain(config, "mxx", "xcrun -sdk watchos ", "clang", "the objc++ compiler") + checker.check_toolchain(config, "as", path.join(os.toolsdir(), "utils/gas-preprocessor.pl xcrun -sdk watchos "), "clang", "the assember", _check_as) + checker.check_toolchain(config, "ld", "xcrun -sdk watchos ", "clang++", "the linker") + checker.check_toolchain(config, "ld", "xcrun -sdk watchos ", "clang", "the linker") + checker.check_toolchain(config, "ar", "xcrun -sdk watchos ", "ar", "the static library archiver") + checker.check_toolchain(config, "ex", "xcrun -sdk watchos ", "ar", "the static library extractor") + checker.check_toolchain(config, "sh", "xcrun -sdk watchos ", "clang++", "the shared library linker") + checker.check_toolchain(config, "sh", "xcrun -sdk watchos ", "clang", "the shared library linker") + checker.check_toolchain(config, "sc", "xcrun -sdk watchos ", "swiftc", "the swift compiler") + end +end + +-- check it +function main(kind) + + -- init the check list of config + _g.config = + { + { checker.check_arch, "armv7k" } + , checker.check_xcode + , checker.check_xcode_sdkver + , checker.check_target_minver + , checker.check_ccache + , _check_toolchains + } + + -- init the check list of global + _g.global = + { + checker.check_xcode + , checker.check_ccache + } + + -- check it + checker.check(kind, _g) +end + diff --git a/xmake/platforms/watchos/checker.lua b/xmake/platforms/watchos/checker.lua deleted file mode 100644 index e3709ce72..000000000 --- a/xmake/platforms/watchos/checker.lua +++ /dev/null @@ -1,108 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- 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) 2015 - 2016, ruki All rights reserved. --- --- @author ruki --- @file checker.lua --- - --- imports -import("core.tool.tool") -import("platforms.checker", {rootdir = os.programdir()}) - --- check the as -function _check_as(shellname) - - -- make an empty tmp.S - local tmpfile = path.join(os.tmpdir(), "xmake.checker.as.S") - io.write(tmpfile, "") - - -- check it - os.run("%s -arch armv7 -o %s -c %s", shellname, os.nuldev(), tmpfile) - - -- remove this tmp.S - os.rm(tmpfile) -end - --- check the toolchains -function _check_toolchains(config) - - -- watchos or watchsimulator? - local arch = config.get("arch") - if arch == "i386" then - checker.check_toolchain(config, "cc", "xcrun -sdk watchsimulator ", "clang", "the c compiler") - checker.check_toolchain(config, "cxx", "xcrun -sdk watchsimulator ", "clang", "the c++ compiler") - checker.check_toolchain(config, "cxx", "xcrun -sdk watchsimulator ", "clang++", "the c++ compiler") - checker.check_toolchain(config, "mm", "xcrun -sdk watchsimulator ", "clang", "the objc compiler") - checker.check_toolchain(config, "mxx", "xcrun -sdk watchsimulator ", "clang++", "the objc++ compiler") - checker.check_toolchain(config, "mxx", "xcrun -sdk watchsimulator ", "clang", "the objc++ compiler") - checker.check_toolchain(config, "as", "xcrun -sdk watchsimulator ", "clang", "the assember") - checker.check_toolchain(config, "ld", "xcrun -sdk watchsimulator ", "clang++", "the linker") - checker.check_toolchain(config, "ld", "xcrun -sdk watchsimulator ", "clang", "the linker") - checker.check_toolchain(config, "ar", "xcrun -sdk watchsimulator ", "ar", "the static library archiver") - checker.check_toolchain(config, "ex", "xcrun -sdk watchsimulator ", "ar", "the static library extractor") - checker.check_toolchain(config, "sh", "xcrun -sdk watchsimulator ", "clang++", "the shared library linker") - checker.check_toolchain(config, "sh", "xcrun -sdk watchsimulator ", "clang", "the shared library linker") - checker.check_toolchain(config, "sc", "xcrun -sdk watchsimulator ", "swiftc", "the swift compiler") - else - checker.check_toolchain(config, "cc", "xcrun -sdk watchos ", "clang", "the c compiler") - checker.check_toolchain(config, "cxx", "xcrun -sdk watchos ", "clang", "the c++ compiler") - checker.check_toolchain(config, "cxx", "xcrun -sdk watchos ", "clang++", "the c++ compiler") - checker.check_toolchain(config, "mm", "xcrun -sdk watchos ", "clang", "the objc compiler") - checker.check_toolchain(config, "mxx", "xcrun -sdk watchos ", "clang++", "the objc++ compiler") - checker.check_toolchain(config, "mxx", "xcrun -sdk watchos ", "clang", "the objc++ compiler") - checker.check_toolchain(config, "as", path.join(os.toolsdir(), "utils/gas-preprocessor.pl xcrun -sdk watchos "), "clang", "the assember", _check_as) - checker.check_toolchain(config, "ld", "xcrun -sdk watchos ", "clang++", "the linker") - checker.check_toolchain(config, "ld", "xcrun -sdk watchos ", "clang", "the linker") - checker.check_toolchain(config, "ar", "xcrun -sdk watchos ", "ar", "the static library archiver") - checker.check_toolchain(config, "ex", "xcrun -sdk watchos ", "ar", "the static library extractor") - checker.check_toolchain(config, "sh", "xcrun -sdk watchos ", "clang++", "the shared library linker") - checker.check_toolchain(config, "sh", "xcrun -sdk watchos ", "clang", "the shared library linker") - checker.check_toolchain(config, "sc", "xcrun -sdk watchos ", "swiftc", "the swift compiler") - end -end - --- init it -function init() - - -- init the check list of config - _g.config = - { - { checker.check_arch, "armv7k" } - , checker.check_xcode - , checker.check_xcode_sdkver - , checker.check_target_minver - , checker.check_ccache - , _check_toolchains - } - - -- init the check list of global - _g.global = - { - checker.check_xcode - , checker.check_ccache - } - -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index f7a15d396..54e179e57 100755 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -32,12 +32,12 @@ platform("watchos") -- set archs set_archs("armv7k", "i386") - -- set checker - set_checker("checker") - -- set tooldirs set_tooldirs("/usr/bin", "/usr/local/bin", "/opt/bin", "/opt/local/bin") + -- on check + on_check("check") + -- on load on_load(function () diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua new file mode 100644 index 000000000..57c3c3de9 --- /dev/null +++ b/xmake/platforms/windows/check.lua @@ -0,0 +1,287 @@ +--!The Make-like Build Utility based on Lua +-- +-- 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) 2015 - 2016, ruki All rights reserved. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.tool.tool") +import("core.base.option") +import("platforms.checker", {rootdir = os.programdir()}) +import("environment") + +-- attempt to apply vs environment +function _apply_vsenv(config, vs) + + -- version => envname + local version2envname = + { + ["2015"] = "VS140COMNTOOLS" + , ["2013"] = "VS120COMNTOOLS" + , ["2012"] = "VS110COMNTOOLS" + , ["2010"] = "VS100COMNTOOLS" + , ["2008"] = "VS90COMNTOOLS" + , ["2005"] = "VS80COMNTOOLS" + , ["2003"] = "VS71COMNTOOLS" + , ["7.0"] = "VS70COMNTOOLS" + , ["6.0"] = "VS60COMNTOOLS" + , ["5.0"] = "VS50COMNTOOLS" + , ["4.2"] = "VS42COMNTOOLS" + } + + -- get the envname + local envname = version2envname[vs] + + -- attempt to get vcvarsall.bat + local vcvarsall = nil + if envname then + local envalue = os.getenv(envname) + if envalue then + vcvarsall = format("%s\\..\\..\\VC\\vcvarsall.bat", envalue) + end + end + + -- vcvarsall.bat not found + if vcvarsall == nil or not os.isfile(vcvarsall) then + if vcvarsall and option.get("verbose") then + print("not found %s", vcvarsall) + end + return + end + + -- make the genvcvars.bat + local genvcvars_bat = path.join(os.tmpdir(), "xmake.genvcvars.bat") + local genvcvars_dat = path.join(os.tmpdir(), "xmake.genvcvars.dat") + local file = io.open(genvcvars_bat, "w") + file:print("@echo off") + file:print("call \"%s\" %s > nul", vcvarsall, config.get("arch")) + file:print("echo { > %s", genvcvars_dat) + file:print("echo path = \"%%path%%\" >> %s", genvcvars_dat) + file:print("echo , lib = \"%%lib%%\" >> %s", genvcvars_dat) + file:print("echo , libpath = \"%%libpath%%\" >> %s", genvcvars_dat) + file:print("echo , include = \"%%include%%\" >> %s", genvcvars_dat) + file:print("echo , devenvdir = \"%%devenvdir%%\" >> %s", genvcvars_dat) + file:print("echo , vsinstalldir = \"%%vsinstalldir%%\" >> %s", genvcvars_dat) + file:print("echo , vcinstalldir = \"%%vcinstalldir%%\" >> %s", genvcvars_dat) + file:print("echo } >> %s", genvcvars_dat) + file:close() + + -- run genvcvars.bat + os.run(genvcvars_bat) + + -- replace "\" => "\\" + io.gsub(genvcvars_dat, "\\", "\\\\") + + -- load all envirnoment variables + local variables = io.load(genvcvars_dat) + + -- save the variables + for k, v in pairs(variables) do + config.set("__vsenv_" .. k, v) + end + + -- ok + return true +end + +-- clean temporary global configs +function _clean_global(config) + + -- clean it for global config (need not it) + config.set("arch", nil) + config.set("__vsenv_path", nil) + config.set("__vsenv_lib", nil) + config.set("__vsenv_include", nil) + config.set("__vsenv_libpath", nil) + config.set("__vsenv_devenvdir", nil) + config.set("__vsenv_vsinstalldir", nil) + config.set("__vsenv_vcinstalldir", nil) +end + +-- attempt to check complier +function _check_compiler(config, vs) + + -- apply vs envirnoment + if not _apply_vsenv(config, vs) then + return + end + + -- enter environment + environment.enter("toolchains") + + -- done + local toolpath = tool.check("cl.exe") + + -- leave environment + environment.leave("toolchains") + + -- ok? + return toolpath +end + +-- check the visual stdio +function _check_vs(config) + + -- attempt to check the given vs version first + local vs = config.get("vs") + if vs and _check_compiler(config, vs) then + return + end + + -- attempt to check them from the envirnoment variables again + vs = nil + if not vs then + for _, version in ipairs({"2015", "2013", "2012", "2010", "2008", "2005", "2003", "7.0", "6.0", "5.0", "4.2"}) do + + -- attempt to check it + if _check_compiler(config, version) then + vs = version + break + end + end + end + + -- check ok? update it + if vs then + + -- save it + config.set("vs", vs) + + -- trace + print("checking for the Microsoft Visual Studio (%s) version ... %s", config.get("arch"), vs) + else + -- failed + print("checking for the Microsoft Visual Studio (%s) version ... no", config.get("arch")) + print("please run:") + print(" - xmake config --vs=xxx") + print("or - xmake global --vs=xxx") + raise() + end +end + +-- check the toolchains +function _check_toolchains(config) + + -- apply vs envirnoment (maybe config.arch has been updated) + if not _apply_vsenv(config, config.get("vs")) then + return + end + + -- enter environment + environment.enter("toolchains") + + -- done + checker.check_toolchain(config, "cc", "", "cl.exe", "the c compiler") + checker.check_toolchain(config, "cxx", "", "cl.exe", "the c++ compiler") + checker.check_toolchain(config, "ld", "", "link.exe", "the linker") + checker.check_toolchain(config, "ar", "", "link.exe -lib", "the static library archiver") + checker.check_toolchain(config, "sh", "", "link.exe -dll", "the shared library linker") + checker.check_toolchain(config, "ex", "", "lib.exe", "the static library extractor") + if config.get("arch"):find("64") then + checker.check_toolchain(config, "as", "", "ml64.exe", "the assember") + else + checker.check_toolchain(config, "as", "", "ml.exe", "the assember") + end + + -- leave environment + environment.leave("toolchains") +end + +-- check the debugger +function _check_debugger(config) + + -- get debugger + local debugger = config.get("dd") + if debugger then + return + end + + -- query the debugger info for x64 + local info = try + { + function () + return os.iorun("reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug\" /v Debugger") + end + } + -- query the debugger info for x86 + if not info then + info = try + { + function () + return os.iorun("reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug\" /v Debugger") + end + } + end + + -- parse the debugger path + -- + -- ! REG.EXE VERSION 3.0 + -- + -- HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug + -- Debugger REG_SZ "C:\WINDOWS\system32\vsjitdebugger.exe" -p %ld -e %ld + if info then + debugger = info:match("Debugger%s+REG_SZ%s+\"(.+)\"") + if debugger then + debugger = debugger:trim() + end + end + + -- this debugger exists? + if debugger and path.is_absolute(debugger) and not os.isfile(debugger) then + debugger = nil + end + + -- check ok? update it + if debugger then + + -- save it + config.set("dd", debugger) + + -- trace + print("checking for the debugger ... %s", path.filename(debugger)) + else + -- failed + print("checking for the debugger ... no") + end +end + +-- check it +function main(kind) + + -- init the check list of config + _g.config = + { + { checker.check_arch, "x86" } + , _check_vs + , _check_toolchains + , _check_debugger + } + + -- init the check list of global + _g.global = + { + { checker.check_arch, "x86" } + , _check_vs + , _clean_global + } + + -- check it + checker.check(kind, _g) +end + diff --git a/xmake/platforms/windows/checker.lua b/xmake/platforms/windows/checker.lua deleted file mode 100644 index 44d2ac9ee..000000000 --- a/xmake/platforms/windows/checker.lua +++ /dev/null @@ -1,292 +0,0 @@ ---!The Make-like Build Utility based on Lua --- --- 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) 2015 - 2016, ruki All rights reserved. --- --- @author ruki --- @file checker.lua --- - --- imports -import("core.tool.tool") -import("core.base.option") -import("platforms.checker", {rootdir = os.programdir()}) -import("environment") - --- attempt to apply vs environment -function _apply_vsenv(config, vs) - - -- version => envname - local version2envname = - { - ["2015"] = "VS140COMNTOOLS" - , ["2013"] = "VS120COMNTOOLS" - , ["2012"] = "VS110COMNTOOLS" - , ["2010"] = "VS100COMNTOOLS" - , ["2008"] = "VS90COMNTOOLS" - , ["2005"] = "VS80COMNTOOLS" - , ["2003"] = "VS71COMNTOOLS" - , ["7.0"] = "VS70COMNTOOLS" - , ["6.0"] = "VS60COMNTOOLS" - , ["5.0"] = "VS50COMNTOOLS" - , ["4.2"] = "VS42COMNTOOLS" - } - - -- get the envname - local envname = version2envname[vs] - - -- attempt to get vcvarsall.bat - local vcvarsall = nil - if envname then - local envalue = os.getenv(envname) - if envalue then - vcvarsall = format("%s\\..\\..\\VC\\vcvarsall.bat", envalue) - end - end - - -- vcvarsall.bat not found - if vcvarsall == nil or not os.isfile(vcvarsall) then - if vcvarsall and option.get("verbose") then - print("not found %s", vcvarsall) - end - return - end - - -- make the genvcvars.bat - local genvcvars_bat = path.join(os.tmpdir(), "xmake.genvcvars.bat") - local genvcvars_dat = path.join(os.tmpdir(), "xmake.genvcvars.dat") - local file = io.open(genvcvars_bat, "w") - file:print("@echo off") - file:print("call \"%s\" %s > nul", vcvarsall, config.get("arch")) - file:print("echo { > %s", genvcvars_dat) - file:print("echo path = \"%%path%%\" >> %s", genvcvars_dat) - file:print("echo , lib = \"%%lib%%\" >> %s", genvcvars_dat) - file:print("echo , libpath = \"%%libpath%%\" >> %s", genvcvars_dat) - file:print("echo , include = \"%%include%%\" >> %s", genvcvars_dat) - file:print("echo , devenvdir = \"%%devenvdir%%\" >> %s", genvcvars_dat) - file:print("echo , vsinstalldir = \"%%vsinstalldir%%\" >> %s", genvcvars_dat) - file:print("echo , vcinstalldir = \"%%vcinstalldir%%\" >> %s", genvcvars_dat) - file:print("echo } >> %s", genvcvars_dat) - file:close() - - -- run genvcvars.bat - os.run(genvcvars_bat) - - -- replace "\" => "\\" - io.gsub(genvcvars_dat, "\\", "\\\\") - - -- load all envirnoment variables - local variables = io.load(genvcvars_dat) - - -- save the variables - for k, v in pairs(variables) do - config.set("__vsenv_" .. k, v) - end - - -- ok - return true -end - --- clean temporary global configs -function _clean_global(config) - - -- clean it for global config (need not it) - config.set("arch", nil) - config.set("__vsenv_path", nil) - config.set("__vsenv_lib", nil) - config.set("__vsenv_include", nil) - config.set("__vsenv_libpath", nil) - config.set("__vsenv_devenvdir", nil) - config.set("__vsenv_vsinstalldir", nil) - config.set("__vsenv_vcinstalldir", nil) -end - --- attempt to check complier -function _check_compiler(config, vs) - - -- apply vs envirnoment - if not _apply_vsenv(config, vs) then - return - end - - -- enter environment - environment.enter("toolchains") - - -- done - local toolpath = tool.check("cl.exe") - - -- leave environment - environment.leave("toolchains") - - -- ok? - return toolpath -end - --- check the visual stdio -function _check_vs(config) - - -- attempt to check the given vs version first - local vs = config.get("vs") - if vs and _check_compiler(config, vs) then - return - end - - -- attempt to check them from the envirnoment variables again - vs = nil - if not vs then - for _, version in ipairs({"2015", "2013", "2012", "2010", "2008", "2005", "2003", "7.0", "6.0", "5.0", "4.2"}) do - - -- attempt to check it - if _check_compiler(config, version) then - vs = version - break - end - end - end - - -- check ok? update it - if vs then - - -- save it - config.set("vs", vs) - - -- trace - print("checking for the Microsoft Visual Studio (%s) version ... %s", config.get("arch"), vs) - else - -- failed - print("checking for the Microsoft Visual Studio (%s) version ... no", config.get("arch")) - print("please run:") - print(" - xmake config --vs=xxx") - print("or - xmake global --vs=xxx") - raise() - end -end - --- check the toolchains -function _check_toolchains(config) - - -- apply vs envirnoment (maybe config.arch has been updated) - if not _apply_vsenv(config, config.get("vs")) then - return - end - - -- enter environment - environment.enter("toolchains") - - -- done - checker.check_toolchain(config, "cc", "", "cl.exe", "the c compiler") - checker.check_toolchain(config, "cxx", "", "cl.exe", "the c++ compiler") - checker.check_toolchain(config, "ld", "", "link.exe", "the linker") - checker.check_toolchain(config, "ar", "", "link.exe -lib", "the static library archiver") - checker.check_toolchain(config, "sh", "", "link.exe -dll", "the shared library linker") - checker.check_toolchain(config, "ex", "", "lib.exe", "the static library extractor") - if config.get("arch"):find("64") then - checker.check_toolchain(config, "as", "", "ml64.exe", "the assember") - else - checker.check_toolchain(config, "as", "", "ml.exe", "the assember") - end - - -- leave environment - environment.leave("toolchains") -end - --- check the debugger -function _check_debugger(config) - - -- get debugger - local debugger = config.get("dd") - if debugger then - return - end - - -- query the debugger info for x64 - local info = try - { - function () - return os.iorun("reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug\" /v Debugger") - end - } - -- query the debugger info for x86 - if not info then - info = try - { - function () - return os.iorun("reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug\" /v Debugger") - end - } - end - - -- parse the debugger path - -- - -- ! REG.EXE VERSION 3.0 - -- - -- HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug - -- Debugger REG_SZ "C:\WINDOWS\system32\vsjitdebugger.exe" -p %ld -e %ld - if info then - debugger = info:match("Debugger%s+REG_SZ%s+\"(.+)\"") - if debugger then - debugger = debugger:trim() - end - end - - -- this debugger exists? - if debugger and path.is_absolute(debugger) and not os.isfile(debugger) then - debugger = nil - end - - -- check ok? update it - if debugger then - - -- save it - config.set("dd", debugger) - - -- trace - print("checking for the debugger ... %s", path.filename(debugger)) - else - -- failed - print("checking for the debugger ... no") - end -end - --- init it -function init() - - -- init the check list of config - _g.config = - { - { checker.check_arch, "x86" } - , _check_vs - , _check_toolchains - , _check_debugger - } - - -- init the check list of global - _g.global = - { - { checker.check_arch, "x86" } - , _check_vs - , _clean_global - } - -end - --- get the property -function get(name) - - -- get it - return _g[name] -end - diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 9b8fbab26..46ae56054 100755 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -32,12 +32,12 @@ platform("windows") -- set archs set_archs("x86", "x64", "amd64", "x86_amd64") - -- set checker - set_checker("checker") - -- set environment set_environment("environment") + -- on check + on_check("check") + -- on load on_load(function () -- cgit v1.3.1