From c0afaacde90abf081bab19279c3ea6d4dbeae86d Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 17 May 2020 21:57:39 +0800 Subject: add toolchain check --- xmake/toolchains/xcode/check.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 xmake/toolchains/xcode/check.lua (limited to 'xmake/toolchains/xcode/check.lua') diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua new file mode 100644 index 000000000..c10fe48d9 --- /dev/null +++ b/xmake/toolchains/xcode/check.lua @@ -0,0 +1,28 @@ +--!A cross-toolchain build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("private.platform.check_xcode") + +-- main entry +function main(toolchain) + check_xcode(config, true) +end -- cgit v1.3.1 From 937bd96c26edc111a3226a4feb2a6748041ab461 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:39:36 +0800 Subject: check toolchains for macosx --- xmake/actions/global/main.lua | 5 - xmake/core/platform/platform.lua | 22 +-- .../sandbox/modules/import/core/base/global.lua | 25 --- .../sandbox/modules/import/core/project/config.lua | 7 +- xmake/core/tool/toolchain.lua | 33 ++-- xmake/platforms/android/check.lua | 155 +++++++++++++++++ xmake/platforms/android/config.lua | 155 ----------------- xmake/platforms/android/xmake.lua | 4 +- xmake/platforms/bsd/check.lua | 175 +++++++++++++++++++ xmake/platforms/bsd/config.lua | 175 ------------------- xmake/platforms/bsd/global.lua | 32 ---- xmake/platforms/bsd/xmake.lua | 7 +- xmake/platforms/cross/check.lua | 189 +++++++++++++++++++++ xmake/platforms/cross/config.lua | 189 --------------------- xmake/platforms/cross/xmake.lua | 4 +- xmake/platforms/cygwin/check.lua | 172 +++++++++++++++++++ xmake/platforms/cygwin/config.lua | 172 ------------------- xmake/platforms/cygwin/xmake.lua | 4 +- xmake/platforms/iphoneos/check.lua | 128 ++++++++++++++ xmake/platforms/iphoneos/config.lua | 128 -------------- xmake/platforms/iphoneos/global.lua | 36 ---- xmake/platforms/iphoneos/xmake.lua | 7 +- xmake/platforms/linux/check.lua | 175 +++++++++++++++++++ xmake/platforms/linux/config.lua | 175 ------------------- xmake/platforms/linux/global.lua | 32 ---- xmake/platforms/linux/xmake.lua | 7 +- xmake/platforms/macosx/check.lua | 175 +++++++++++++++++++ xmake/platforms/macosx/config.lua | 165 ------------------ xmake/platforms/macosx/global.lua | 36 ---- xmake/platforms/macosx/xmake.lua | 7 +- xmake/platforms/mingw/check.lua | 128 ++++++++++++++ xmake/platforms/mingw/config.lua | 128 -------------- xmake/platforms/mingw/xmake.lua | 4 +- xmake/platforms/msys/check.lua | 172 +++++++++++++++++++ xmake/platforms/msys/config.lua | 172 ------------------- xmake/platforms/msys/xmake.lua | 4 +- xmake/platforms/sdcc/check.lua | 114 +++++++++++++ xmake/platforms/sdcc/config.lua | 114 ------------- xmake/platforms/sdcc/xmake.lua | 4 +- xmake/platforms/watchos/check.lua | 124 ++++++++++++++ xmake/platforms/watchos/config.lua | 124 -------------- xmake/platforms/watchos/global.lua | 36 ---- xmake/platforms/watchos/xmake.lua | 7 +- xmake/platforms/windows/check.lua | 139 +++++++++++++++ xmake/platforms/windows/config.lua | 139 --------------- xmake/platforms/windows/global.lua | 49 ------ xmake/platforms/windows/xmake.lua | 7 +- xmake/toolchains/xcode/check.lua | 1 + 48 files changed, 1902 insertions(+), 2160 deletions(-) create mode 100644 xmake/platforms/android/check.lua delete mode 100644 xmake/platforms/android/config.lua create mode 100644 xmake/platforms/bsd/check.lua delete mode 100644 xmake/platforms/bsd/config.lua delete mode 100644 xmake/platforms/bsd/global.lua create mode 100644 xmake/platforms/cross/check.lua delete mode 100644 xmake/platforms/cross/config.lua create mode 100644 xmake/platforms/cygwin/check.lua delete mode 100644 xmake/platforms/cygwin/config.lua create mode 100644 xmake/platforms/iphoneos/check.lua delete mode 100644 xmake/platforms/iphoneos/config.lua delete mode 100644 xmake/platforms/iphoneos/global.lua create mode 100644 xmake/platforms/linux/check.lua delete mode 100644 xmake/platforms/linux/config.lua delete mode 100644 xmake/platforms/linux/global.lua create mode 100644 xmake/platforms/macosx/check.lua delete mode 100644 xmake/platforms/macosx/config.lua delete mode 100644 xmake/platforms/macosx/global.lua create mode 100644 xmake/platforms/mingw/check.lua delete mode 100644 xmake/platforms/mingw/config.lua create mode 100644 xmake/platforms/msys/check.lua delete mode 100644 xmake/platforms/msys/config.lua create mode 100644 xmake/platforms/sdcc/check.lua delete mode 100644 xmake/platforms/sdcc/config.lua create mode 100644 xmake/platforms/watchos/check.lua delete mode 100644 xmake/platforms/watchos/config.lua delete mode 100644 xmake/platforms/watchos/global.lua create mode 100644 xmake/platforms/windows/check.lua delete mode 100644 xmake/platforms/windows/config.lua delete mode 100644 xmake/platforms/windows/global.lua (limited to 'xmake/toolchains/xcode/check.lua') diff --git a/xmake/actions/global/main.lua b/xmake/actions/global/main.lua index 720eb0351..9472c9b24 100644 --- a/xmake/actions/global/main.lua +++ b/xmake/actions/global/main.lua @@ -59,11 +59,6 @@ function main() end end - -- check the global configure - if changed or option.get("clean") then - global.check() - end - -- load and check theme local themename = option.get("theme") if themename then diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index d80b72be5..677e36906 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -163,6 +163,14 @@ function _instance:data_add(name, data) self._DATA[name] = table.unwrap(table.join(self._DATA[name] or {}, data)) end +-- do check +function _instance:check() + local on_check = self:script("check") + if on_check then + on_check(self) + end +end + -- is builtin configuration? function _instance:_is_builtin_conf(name) @@ -219,8 +227,7 @@ function platform._apis() { -- platform.on_xxx "platform.on_load" - , "platform.on_config_check" - , "platform.on_global_check" + , "platform.on_check" , "platform.on_environment_enter" , "platform.on_environment_leave" } @@ -367,17 +374,6 @@ function platform.tool(toolkind, plat) config.set(toolkind, program, {force = true, readonly = true}) config.set("__toolname_" .. toolkind, toolname) config.save() - else - -- TODO deprecated - -- check it first - local on_check = instance:script("config_check") - if on_check then - on_check(instance, toolkind) - end - - -- get it again - program = config.get(toolkind) - toolname = config.get("__toolname_" .. toolkind) end end diff --git a/xmake/core/sandbox/modules/import/core/base/global.lua b/xmake/core/sandbox/modules/import/core/base/global.lua index 4ea5b2745..9141a2d76 100644 --- a/xmake/core/sandbox/modules/import/core/base/global.lua +++ b/xmake/core/sandbox/modules/import/core/base/global.lua @@ -68,31 +68,6 @@ function sandbox_core_base_global.clear() return global.clear() end --- check the configure -function sandbox_core_base_global.check() - - -- 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 == os.host() then - local on_check = instance:script("global_check") - if on_check then - on_check(instance) - end - break - end - end - end -end - -- get all options function sandbox_core_base_global.options() return global.options() diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua index 449fac71f..c7121a8a4 100644 --- a/xmake/core/sandbox/modules/import/core/project/config.lua +++ b/xmake/core/sandbox/modules/import/core/project/config.lua @@ -116,12 +116,7 @@ function sandbox_core_project_config.check() -- get the current platform local instance, errors = platform.load() if instance then - - -- do check - local on_check = instance:script("config_check") - if on_check then - on_check(instance) - end + instance:check() else raise(errors) end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 246d46a99..e79a32b22 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -61,6 +61,19 @@ end -- get the toolchain configuration function _instance:get(name) + + -- attempt to get the static configure value + local value = self._INFO:get(name) + if value ~= nil then + return value + end + + -- lazy loading platform if get other configuration + if not self:_is_builtin_conf(name) then + self:_load() + end + + -- get other platform info return self._INFO:get(name) end @@ -102,17 +115,21 @@ function _instance:_load() end -- do check -function _instance:_check() +function _instance:check() + local checkok = true if not self._CHECKED then local on_check = self._INFO:get("check") if on_check then - local ok, errors = sandbox.load(on_check, self) - if not ok then - os.raise(errors) + local ok, results_or_errors = sandbox.load(on_check, self) + if ok then + checkok = results_or_errors + else + os.raise(results_or_errors) end end self._CHECKED = true end + return checkok end -- get the tool description from the tool kind @@ -158,9 +175,6 @@ end -- check the given tool path function _instance:_checktool(toolkind, toolpath) - -- ensure to check this toolchain first - self:_check() - -- get find_tool local find_tool = self._find_tool if not find_tool then @@ -187,11 +201,6 @@ function _instance:_checktool(toolkind, toolpath) utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, name) end end - - -- we only load it when checking the given tool successfully - if program then - self:_load() - end return program, toolname end diff --git a/xmake/platforms/android/check.lua b/xmake/platforms/android/check.lua new file mode 100644 index 000000000..04d639483 --- /dev/null +++ b/xmake/platforms/android/check.lua @@ -0,0 +1,155 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_ndk") +import("detect.sdks.find_android_sdk") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the ndk toolchain +function _check_ndk() + local ndk = find_ndk(config.get("ndk"), {force = true, verbose = true}) + if ndk then + config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) -- maybe to global + config.set("bin", ndk.bindir, {force = true, readonly = true}) + config.set("cross", ndk.cross, {force = true, readonly = true}) + config.set("gcc_toolchain", ndk.gcc_toolchain, {force = true, readonly = true}) + else + -- failed + cprint("${bright color.error}please run:") + cprint(" - xmake config --ndk=xxx") + cprint("or - xmake global --ndk=xxx") + raise() + end +end + +-- check the android sdk +function _check_android_sdk() + local sdk = find_android_sdk(config.get("android_sdk"), {force = true, verbose = true}) + if sdk then + config.set("sdk", sdk.sdkdir, {force = true, readonly = true}) -- maybe to global + end +end + +-- get toolchains +function _toolchains() + + -- get cross + local cross = config.get("cross") + + -- get gcc toolchain bin directory + local gcc_toolchain_bin = nil + local gcc_toolchain = config.get("gcc_toolchain") + if gcc_toolchain then + gcc_toolchain_bin = path.join(gcc_toolchain, "bin") + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local ranlib = toolchain("the static library index generator") + local strip = toolchain("the symbols stripper") + local as = toolchain("the assember") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar} + + -- init the c compiler + cc:add({name = "gcc", cross = cross}, "clang") + + -- init the c++ compiler + cxx:add({name = "g++", cross = cross}, "clang++") + + -- init the c preprocessor + cpp:add({name = "gcc -E", cross = cross}, "clang -E") + + -- init the assember + as:add({name = "gcc", cross = cross}, "clang") + + -- init the linker + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add("clang++", "clang") + + -- init the shared library linker + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add("clang++", "clang") + + -- init the static library archiver + ar:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") + + -- init the static library extractor + ex:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") + + -- init the static library index generator + ranlib:add({name = "ranlib", cross = cross, pathes = gcc_toolchain_bin}, "ranlib") + + -- init the symbols stripper + strip:add({name = "strip", cross = cross, pathes = gcc_toolchain_bin}, "strip") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("android.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config, "armeabi-v7a") + + -- check android sdk + _check_android_sdk() + + -- check ndk + _check_ndk() + + -- check ld and sh, @note toolchains must be initialized after calling check_ndk() + local toolchains = singleton.get("android.toolchains", _toolchains) + check_toolchain(config, "ld", toolchains.ld) + check_toolchain(config, "sh", toolchains.sh) + end +end + diff --git a/xmake/platforms/android/config.lua b/xmake/platforms/android/config.lua deleted file mode 100644 index e99a4d14a..000000000 --- a/xmake/platforms/android/config.lua +++ /dev/null @@ -1,155 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_ndk") -import("detect.sdks.find_android_sdk") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the ndk toolchain -function _check_ndk() - local ndk = find_ndk(config.get("ndk"), {force = true, verbose = true}) - if ndk then - config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) -- maybe to global - config.set("bin", ndk.bindir, {force = true, readonly = true}) - config.set("cross", ndk.cross, {force = true, readonly = true}) - config.set("gcc_toolchain", ndk.gcc_toolchain, {force = true, readonly = true}) - else - -- failed - cprint("${bright color.error}please run:") - cprint(" - xmake config --ndk=xxx") - cprint("or - xmake global --ndk=xxx") - raise() - end -end - --- check the android sdk -function _check_android_sdk() - local sdk = find_android_sdk(config.get("android_sdk"), {force = true, verbose = true}) - if sdk then - config.set("sdk", sdk.sdkdir, {force = true, readonly = true}) -- maybe to global - end -end - --- get toolchains -function _toolchains() - - -- get cross - local cross = config.get("cross") - - -- get gcc toolchain bin directory - local gcc_toolchain_bin = nil - local gcc_toolchain = config.get("gcc_toolchain") - if gcc_toolchain then - gcc_toolchain_bin = path.join(gcc_toolchain, "bin") - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local ranlib = toolchain("the static library index generator") - local strip = toolchain("the symbols stripper") - local as = toolchain("the assember") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar} - - -- init the c compiler - cc:add({name = "gcc", cross = cross}, "clang") - - -- init the c++ compiler - cxx:add({name = "g++", cross = cross}, "clang++") - - -- init the c preprocessor - cpp:add({name = "gcc -E", cross = cross}, "clang -E") - - -- init the assember - as:add({name = "gcc", cross = cross}, "clang") - - -- init the linker - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add("clang++", "clang") - - -- init the shared library linker - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add("clang++", "clang") - - -- init the static library archiver - ar:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") - - -- init the static library extractor - ex:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") - - -- init the static library index generator - ranlib:add({name = "ranlib", cross = cross, pathes = gcc_toolchain_bin}, "ranlib") - - -- init the symbols stripper - strip:add({name = "strip", cross = cross, pathes = gcc_toolchain_bin}, "strip") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("android.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "armeabi-v7a") - - -- check android sdk - _check_android_sdk() - - -- check ndk - _check_ndk() - - -- check ld and sh, @note toolchains must be initialized after calling check_ndk() - local toolchains = singleton.get("android.toolchains", _toolchains) - check_toolchain(config, "ld", toolchains.ld) - check_toolchain(config, "sh", toolchains.sh) - end -end - diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua index 45a4eaf8d..cb7d52594 100644 --- a/xmake/platforms/android/xmake.lua +++ b/xmake/platforms/android/xmake.lua @@ -39,8 +39,8 @@ platform("android") -- set formats set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua new file mode 100644 index 000000000..1eb8834ef --- /dev/null +++ b/xmake/platforms/bsd/check.lua @@ -0,0 +1,175 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + + -- init the default architecture + config.set("arch", config.get("cross") and "none" or os.arch()) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + end +end + +-- get toolchains +function _toolchains() + + -- find cross toolchain + local cross = "" + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + cross = cross_toolchain.cross + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local gc = toolchain("the golang compiler") + local gc_ld = toolchain("the golang linker") + local gc_ar = toolchain("the golang static library archiver") + local dc = toolchain("the dlang compiler") + local dc_ld = toolchain("the dlang linker") + local dc_sh = toolchain("the dlang shared library linker") + local dc_ar = toolchain("the dlang static library archiver") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local cu = toolchain("the cuda compiler") + local cu_ld = toolchain("the cuda linker") + local cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, + mm = mm, mxx = mxx, + gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, + dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, + cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + cxx:add({name = "g++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the symbols stripper + strip:add("$(env STRIP)", {name = "strip", cross = cross}) + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add({name = "gcc", cross = cross}) + mxx:add({name = "g++", cross = cross}) + + -- init the golang compiler and linker + gc:add("$(env GC)", "go", "gccgo") + gc_ld:add("$(env GC)", "go", "gccgo") + gc_ar:add("$(env GC)", "go", "gccgo") + + -- init the dlang compiler and linker + dc:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + -- init the cuda compiler and linker + cu:add("nvcc", "clang++", "clang") + cu_ld:add("nvcc") + if not cross or cross == "" then + cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") + end + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("linux.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + end +end + diff --git a/xmake/platforms/bsd/config.lua b/xmake/platforms/bsd/config.lua deleted file mode 100644 index 69164b8b4..000000000 --- a/xmake/platforms/bsd/config.lua +++ /dev/null @@ -1,175 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.arch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, - mm = mm, mxx = mxx, - gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, - dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - cxx:add({name = "g++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("linux.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/bsd/global.lua b/xmake/platforms/bsd/global.lua deleted file mode 100644 index d74d84943..000000000 --- a/xmake/platforms/bsd/global.lua +++ /dev/null @@ -1,32 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end -end - diff --git a/xmake/platforms/bsd/xmake.lua b/xmake/platforms/bsd/xmake.lua index 3ea3ed9f6..d0cacd28a 100644 --- a/xmake/platforms/bsd/xmake.lua +++ b/xmake/platforms/bsd/xmake.lua @@ -36,11 +36,8 @@ platform("bsd") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/cross/check.lua b/xmake/platforms/cross/check.lua new file mode 100644 index 000000000..833dcb921 --- /dev/null +++ b/xmake/platforms/cross/check.lua @@ -0,0 +1,189 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + config.set("arch", "none") + end +end + +-- check the cross toolchain +function _check_cross_toolchain() + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + + -- TODO add to environment module + -- add bin search library for loading some dependent .dll files windows + if cross_toolchain.bindir and is_host("windows") then + os.addenv("PATH", cross_toolchain.bindir) + end + end +end + +-- get llvm toolchains +function _toolchains_llvm() + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local ranlib = toolchain("the static library index generator") + local as = toolchain("the assember") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} + + -- init the c compiler + cc:add("$(env CC)", "clang") + + -- init the c preprocessor + cpp:add("$(env CPP)", "clang -E") + + -- init the c++ compiler + cxx:add("$(env CXX)", "clang", "clang++") + + -- init the assember + as:add("$(env AS)", "clang") + + -- init the linker + ld:add("$(env LD)", "$(env CXX)", "clang++", "clang") + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)", "clang++", "clang") + + -- init the static library archiver + ar:add("$(env AR)", "llvm-ar") + + -- init the static library extractor + ex:add("$(env AR)", "llvm-ar") + + -- init the static library index generator + ranlib:add("$(env RANLIB)", "llvm-ranlib") + + -- init the symbols stripper + strip:add("$(env STRIP)", "llvm-strip") + return toolchains +end + +-- get toolchains +function _toolchains() + + -- get cross prefix + local cross = config.get("cross") or "" + + -- for llvm toolchains? + if cross == "" and config.get("toolchain") == "llvm" then + return _toolchains_llvm() + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local ranlib = toolchain("the static library index generator") + local as = toolchain("the assember") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the c preprocessor + cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}, {name = "clang -E", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "g++", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library index generator + ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) + + -- init the symbols stripper + strip:add("$(env STRIP)", {name = "strip", cross = cross}) + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("cross.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + + -- check cross toolchain + _check_cross_toolchain() + end +end + diff --git a/xmake/platforms/cross/config.lua b/xmake/platforms/cross/config.lua deleted file mode 100644 index b159cf5c1..000000000 --- a/xmake/platforms/cross/config.lua +++ /dev/null @@ -1,189 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - config.set("arch", "none") - end -end - --- check the cross toolchain -function _check_cross_toolchain() - -- find cross toolchain - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - if cross_toolchain.bindir and is_host("windows") then - os.addenv("PATH", cross_toolchain.bindir) - end - end -end - --- get llvm toolchains -function _toolchains_llvm() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} - - -- init the c compiler - cc:add("$(env CC)", "clang") - - -- init the c preprocessor - cpp:add("$(env CPP)", "clang -E") - - -- init the c++ compiler - cxx:add("$(env CXX)", "clang", "clang++") - - -- init the assember - as:add("$(env AS)", "clang") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)", "clang++", "clang") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)", "clang++", "clang") - - -- init the static library archiver - ar:add("$(env AR)", "llvm-ar") - - -- init the static library extractor - ex:add("$(env AR)", "llvm-ar") - - -- init the static library index generator - ranlib:add("$(env RANLIB)", "llvm-ranlib") - - -- init the symbols stripper - strip:add("$(env STRIP)", "llvm-strip") - return toolchains -end - --- get toolchains -function _toolchains() - - -- get cross prefix - local cross = config.get("cross") or "" - - -- for llvm toolchains? - if cross == "" and config.get("toolchain") == "llvm" then - return _toolchains_llvm() - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c preprocessor - cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}, {name = "clang -E", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library index generator - ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cross.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - - -- check cross toolchain - _check_cross_toolchain() - end -end - diff --git a/xmake/platforms/cross/xmake.lua b/xmake/platforms/cross/xmake.lua index 31e7f6d95..a76dde03c 100644 --- a/xmake/platforms/cross/xmake.lua +++ b/xmake/platforms/cross/xmake.lua @@ -30,8 +30,8 @@ platform("cross") -- set formats set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/cygwin/check.lua b/xmake/platforms/cygwin/check.lua new file mode 100644 index 000000000..3b1221387 --- /dev/null +++ b/xmake/platforms/cygwin/check.lua @@ -0,0 +1,172 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + + -- init the default architecture + config.set("arch", config.get("cross") and "none" or os.subarch()) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + end +end + +-- get toolchains +function _toolchains() + + -- find cross toolchain + local cross = "" + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + cross = cross_toolchain.cross + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local gc = toolchain("the golang compiler") + local gc_ld = toolchain("the golang linker") + local gc_ar = toolchain("the golang static library archiver") + local dc = toolchain("the dlang compiler") + local dc_ld = toolchain("the dlang linker") + local dc_sh = toolchain("the dlang shared library linker") + local dc_ar = toolchain("the dlang static library archiver") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local cu = toolchain("the cuda compiler") + local cu_ld = toolchain("the cuda linker") + local cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, + mm = mm, mxx = mxx, + gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, + dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, + cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "g++", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add({name = "gcc", cross = cross}) + mxx:add({name = "g++", cross = cross}) + + -- init the golang compiler and linker + gc:add("$(env GC)", "go", "gccgo") + gc_ld:add("$(env GC)", "go", "gccgo") + gc_ar:add("$(env GC)", "go", "gccgo") + + -- init the dlang compiler and linker + dc:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + -- init the cuda compiler and linker + cu:add("nvcc", "clang++", "clang") + cu_ld:add("nvcc") + if not cross or cross == "" then + cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") + end + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("cygwin.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + end +end + diff --git a/xmake/platforms/cygwin/config.lua b/xmake/platforms/cygwin/config.lua deleted file mode 100644 index 26f008970..000000000 --- a/xmake/platforms/cygwin/config.lua +++ /dev/null @@ -1,172 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.subarch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - mm = mm, mxx = mxx, - gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, - dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cygwin.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/cygwin/xmake.lua b/xmake/platforms/cygwin/xmake.lua index e43c5e35c..32ab7df58 100644 --- a/xmake/platforms/cygwin/xmake.lua +++ b/xmake/platforms/cygwin/xmake.lua @@ -36,8 +36,8 @@ platform("cygwin") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua new file mode 100644 index 000000000..94a3a9ae9 --- /dev/null +++ b/xmake/platforms/iphoneos/check.lua @@ -0,0 +1,128 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_xcode") +import("private.platform.check_toolchain") + +-- get toolchains +function _toolchains() + + -- init architecture + local arch = config.get("arch") or os.arch() + local simulator = (arch == "i386" or arch == "x86_64") + + -- init cross + local cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " + + -- init toolchains + local cc = toolchain("the c compiler") + local cpp = toolchain("the c preprocessor") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local dsymutil = toolchain("the symbols generator") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local sc = toolchain("the swift compiler") + local sc_ld = toolchain("the swift linker") + local sc_sh = toolchain("the swift shared library linker") + local toolchains = {cc = cc, cpp = cpp, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, + mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} + + -- init the c compiler + cc:add({name = "clang", cross = cross}) + + -- init the c preprocessor + cpp:add({name = "clang -arch " .. arch .. " -E", cross = cross}) + + -- init the c++ compiler + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + if simulator then + as:add({name = "clang", cross = cross}) + else + as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) + end + + -- init the linker + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add({name = "ar", cross = cross}) + + -- init the static library extractor + ex:add({name = "ar", cross = cross}) + + -- init the symbols stripper + strip:add({name = "strip", cross = cross}) + + -- init the symbols generator + dsymutil:add({name = "dsymutil", cross = cross}) + + -- init the objc compiler + mm:add({name = "clang", cross = cross}) + + -- init the objc++ compiler + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + + -- init the swift compiler and linker + sc:add({name = "swiftc", cross = cross}) + sc_ld:add({name = "swiftc", cross = cross}) + sc_sh:add({name = "swiftc", cross = cross}) + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("iphoneos.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config, "arm64") + + -- check xcode + check_xcode(config) + end +end + diff --git a/xmake/platforms/iphoneos/config.lua b/xmake/platforms/iphoneos/config.lua deleted file mode 100644 index 1e3592f45..000000000 --- a/xmake/platforms/iphoneos/config.lua +++ /dev/null @@ -1,128 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init architecture - local arch = config.get("arch") or os.arch() - local simulator = (arch == "i386" or arch == "x86_64") - - -- init cross - local cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " - - -- init toolchains - local cc = toolchain("the c compiler") - local cpp = toolchain("the c preprocessor") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - local toolchains = {cc = cc, cpp = cpp, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} - - -- init the c compiler - cc:add({name = "clang", cross = cross}) - - -- init the c preprocessor - cpp:add({name = "clang -arch " .. arch .. " -E", cross = cross}) - - -- init the c++ compiler - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - if simulator then - as:add({name = "clang", cross = cross}) - else - as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) - end - - -- init the linker - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add({name = "ar", cross = cross}) - - -- init the static library extractor - ex:add({name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}) - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}) - - -- init the objc compiler - mm:add({name = "clang", cross = cross}) - - -- init the objc++ compiler - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - - -- init the swift compiler and linker - sc:add({name = "swiftc", cross = cross}) - sc_ld:add({name = "swiftc", cross = cross}) - sc_sh:add({name = "swiftc", cross = cross}) - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("iphoneos.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "arm64") - - -- check xcode - check_xcode(config) - end -end - diff --git a/xmake/platforms/iphoneos/global.lua b/xmake/platforms/iphoneos/global.lua deleted file mode 100644 index f625eb103..000000000 --- a/xmake/platforms/iphoneos/global.lua +++ /dev/null @@ -1,36 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_xcode") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check xcode - check_xcode(global, true) -end - diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index 2f6bcf00f..6d2af82ae 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -33,11 +33,8 @@ platform("iphoneos") -- set formats set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).dSYM"} - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua new file mode 100644 index 000000000..1671ee0e9 --- /dev/null +++ b/xmake/platforms/linux/check.lua @@ -0,0 +1,175 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + + -- init the default architecture + config.set("arch", config.get("cross") and "none" or os.arch()) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + end +end + +-- get toolchains +function _toolchains() + + -- find cross toolchain + local cross = "" + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + cross = cross_toolchain.cross + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local gc = toolchain("the golang compiler") + local gc_ld = toolchain("the golang linker") + local gc_ar = toolchain("the golang static library archiver") + local dc = toolchain("the dlang compiler") + local dc_ld = toolchain("the dlang linker") + local dc_sh = toolchain("the dlang shared library linker") + local dc_ar = toolchain("the dlang static library archiver") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local cu = toolchain("the cuda compiler") + local cu_ld = toolchain("the cuda linker") + local cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, + mm = mm, mxx = mxx, + gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, + dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, + cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "g++", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the symbols stripper + strip:add("$(env STRIP)", {name = "strip", cross = cross}) + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add({name = "gcc", cross = cross}) + mxx:add({name = "g++", cross = cross}) + + -- init the golang compiler and linker + gc:add("$(env GC)", "go", "gccgo") + gc_ld:add("$(env GC)", "go", "gccgo") + gc_ar:add("$(env GC)", "go", "gccgo") + + -- init the dlang compiler and linker + dc:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + -- init the cuda compiler and linker + cu:add("nvcc", "clang++", "clang") + cu_ld:add("nvcc") + if not cross or cross == "" then + cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") + end + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("linux.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + end +end + diff --git a/xmake/platforms/linux/config.lua b/xmake/platforms/linux/config.lua deleted file mode 100644 index ac9b42931..000000000 --- a/xmake/platforms/linux/config.lua +++ /dev/null @@ -1,175 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.arch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, - mm = mm, mxx = mxx, - gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, - dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("linux.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/linux/global.lua b/xmake/platforms/linux/global.lua deleted file mode 100644 index d74d84943..000000000 --- a/xmake/platforms/linux/global.lua +++ /dev/null @@ -1,32 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end -end - diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index 53517239a..21e4d2e51 100644 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -36,11 +36,8 @@ platform("linux") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua new file mode 100644 index 000000000..ff552ad6b --- /dev/null +++ b/xmake/platforms/macosx/check.lua @@ -0,0 +1,175 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") + +--[[ +import("core.base.singleton") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_xcode") +import("private.platform.check_toolchain") + +-- get toolchains +function _toolchains() + + -- init cross + local cross = "xcrun -sdk macosx " + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local dsymutil = toolchain("the symbols generator") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local sc = toolchain("the swift compiler") + local sc_ld = toolchain("the swift linker") + local sc_sh = toolchain("the swift shared library linker") + local gc = toolchain("the golang compiler") + local gc_ld = toolchain("the golang linker") + local gc_ar = toolchain("the golang static library archiver") + local dc = toolchain("the dlang compiler") + local dc_ld = toolchain("the dlang linker") + local dc_sh = toolchain("the dlang shared library linker") + local dc_ar = toolchain("the dlang static library archiver") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local cu = toolchain("the cuda compiler") + local cu_ld = toolchain("the cuda linker") + local cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, + mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh, + gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, + dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, + cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "clang", cross = cross}, "clang", "gcc") + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + cxx:add("clang", "clang++", "gcc", "g++") + + -- init the assember + as:add("$(env AS)", {name = "clang", cross = cross}, "clang", "gcc") + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + ld:add("clang++", "g++", "clang", "gcc") + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + sh:add("clang++", "g++", "clang", "gcc") + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}, "ar") + + -- init the static library extractor + ex:add({name = "ar", cross = cross}, "ar") + + -- init the symbols stripper + strip:add({name = "strip", cross = cross}, "strip") + + -- init the symbols generator + dsymutil:add({name = "dsymutil", cross = cross}, "dsymutil") + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, "clang", "gcc") + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add("clang", "clang++", "gcc", "g++") + + -- init the swift compiler and linker + sc:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") + sc_ld:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") + sc_sh:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") + + -- init the golang compiler and linker + gc:add("$(env GC)", "go", "gccgo") + gc_ld:add("$(env GC)", "go", "gccgo") + gc_ar:add("$(env GC)", "go", "gccgo") + + -- init the dlang compiler and linker + dc:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + -- init the cuda compiler and linker + cu:add("nvcc", "clang") + cu_ld:add("nvcc") + cu_ccbin:add("$(env CXX)", "$(env CC)", "clang", "gcc") + + return toolchains +end]] + +-- check it +function main(platform) + + -- check toolchains + local toolchains = platform:toolchains() + for idx, toolchain in irpairs(toolchains) do + if not toolchain:check() then + table.remove(toolchains, idx) + end + end + + --[[ + -- only check the given config name? + if name then + local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config) + + -- check xcode + check_xcode(config, true) + end]] +end + diff --git a/xmake/platforms/macosx/config.lua b/xmake/platforms/macosx/config.lua deleted file mode 100644 index a1713a657..000000000 --- a/xmake/platforms/macosx/config.lua +++ /dev/null @@ -1,165 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init cross - local cross = "xcrun -sdk macosx " - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh, - gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, - dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - cxx:add("clang", "clang++", "gcc", "g++") - - -- init the assember - as:add("$(env AS)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - ld:add("clang++", "g++", "clang", "gcc") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - sh:add("clang++", "g++", "clang", "gcc") - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}, "ar") - - -- init the static library extractor - ex:add({name = "ar", cross = cross}, "ar") - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}, "strip") - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}, "dsymutil") - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add("clang", "clang++", "gcc", "g++") - - -- init the swift compiler and linker - sc:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - sc_ld:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - sc_sh:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang") - cu_ld:add("nvcc") - cu_ccbin:add("$(env CXX)", "$(env CC)", "clang", "gcc") - - return toolchains -end - --- check it -function main(platform, name) - - --[[ - -- only check the given config name? - if name then - local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config) - - -- check xcode - check_xcode(config, true) - end]] -end - diff --git a/xmake/platforms/macosx/global.lua b/xmake/platforms/macosx/global.lua deleted file mode 100644 index f625eb103..000000000 --- a/xmake/platforms/macosx/global.lua +++ /dev/null @@ -1,36 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_xcode") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check xcode - check_xcode(global, true) -end - diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index fc390d953..512499c7c 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -36,11 +36,8 @@ platform("macosx") -- set install directory set_installdir("/usr/local") - -- on check project configuration --- on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/mingw/check.lua b/xmake/platforms/mingw/check.lua new file mode 100644 index 000000000..9905a53cc --- /dev/null +++ b/xmake/platforms/mingw/check.lua @@ -0,0 +1,128 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_mingw") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the mingw toolchain +function _check_mingw() + local mingw = find_mingw(config.get("mingw"), {verbose = true, bindir = config.get("bin"), cross = config.get("cross")}) + if mingw then + config.set("mingw", mingw.sdkdir, {force = true, readonly = true}) + config.set("cross", mingw.cross, {readonly = true, force = true}) + config.set("bin", mingw.bindir, {readonly = true, force = true}) + else + -- failed + cprint("${bright color.error}please run:") + cprint(" - xmake config --ndk=xxx") + cprint("or - xmake global --ndk=xxx") + raise() + end +end + +-- get toolchains +function _toolchains() + + -- get cross + local cross = config.get("cross") + + -- TODO add to environment module + -- add bin search library for loading some dependent .dll files windows + local bindir = config.get("bin") + if bindir and is_host("windows") then + os.addenv("PATH", bindir) + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local ranlib = toolchain("the static library index generator") + local as = toolchain("the assember") + local mrc = toolchain("the resource compiler") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, mrc = mrc} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "g++", cross = cross}) + + -- init the c preprocessor + cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) + + -- init the resource compiler + mrc:add({name = "windres", cross = cross}) + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("mingw.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config, "x86_64") + + -- check mingw + _check_mingw() + end +end + diff --git a/xmake/platforms/mingw/config.lua b/xmake/platforms/mingw/config.lua deleted file mode 100644 index bbfc6f7f9..000000000 --- a/xmake/platforms/mingw/config.lua +++ /dev/null @@ -1,128 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_mingw") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the mingw toolchain -function _check_mingw() - local mingw = find_mingw(config.get("mingw"), {verbose = true, bindir = config.get("bin"), cross = config.get("cross")}) - if mingw then - config.set("mingw", mingw.sdkdir, {force = true, readonly = true}) - config.set("cross", mingw.cross, {readonly = true, force = true}) - config.set("bin", mingw.bindir, {readonly = true, force = true}) - else - -- failed - cprint("${bright color.error}please run:") - cprint(" - xmake config --ndk=xxx") - cprint("or - xmake global --ndk=xxx") - raise() - end -end - --- get toolchains -function _toolchains() - - -- get cross - local cross = config.get("cross") - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - local bindir = config.get("bin") - if bindir and is_host("windows") then - os.addenv("PATH", bindir) - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local mrc = toolchain("the resource compiler") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, mrc = mrc} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "g++", cross = cross}) - - -- init the c preprocessor - cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) - - -- init the resource compiler - mrc:add({name = "windres", cross = cross}) - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("mingw.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "x86_64") - - -- check mingw - _check_mingw() - end -end - diff --git a/xmake/platforms/mingw/xmake.lua b/xmake/platforms/mingw/xmake.lua index 7b5ad2624..e119f137f 100644 --- a/xmake/platforms/mingw/xmake.lua +++ b/xmake/platforms/mingw/xmake.lua @@ -33,8 +33,8 @@ platform("mingw") -- set formats set_formats {static = "$(name).lib", object = "$(name).obj", shared = "$(name).dll", binary = "$(name).exe", symbol = "$(name).pdb"} - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/msys/check.lua b/xmake/platforms/msys/check.lua new file mode 100644 index 000000000..8c5a2dcdd --- /dev/null +++ b/xmake/platforms/msys/check.lua @@ -0,0 +1,172 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + + -- init the default architecture + config.set("arch", config.get("cross") and "none" or os.subarch()) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + end +end + +-- get toolchains +function _toolchains() + + -- find cross toolchain + local cross = "" + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + cross = cross_toolchain.cross + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local gc = toolchain("the golang compiler") + local gc_ld = toolchain("the golang linker") + local gc_ar = toolchain("the golang static library archiver") + local dc = toolchain("the dlang compiler") + local dc_ld = toolchain("the dlang linker") + local dc_sh = toolchain("the dlang shared library linker") + local dc_ar = toolchain("the dlang static library archiver") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local cu = toolchain("the cuda compiler") + local cu_ld = toolchain("the cuda linker") + local cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, + mm = mm, mxx = mxx, + gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, + dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, + cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "g++", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add({name = "gcc", cross = cross}) + mxx:add({name = "g++", cross = cross}) + + -- init the golang compiler and linker + gc:add("$(env GC)", "go", "gccgo") + gc_ld:add("$(env GC)", "go", "gccgo") + gc_ar:add("$(env GC)", "go", "gccgo") + + -- init the dlang compiler and linker + dc:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + -- init the cuda compiler and linker + cu:add("nvcc", "clang++", "clang") + cu_ld:add("nvcc") + if not cross or cross == "" then + cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") + end + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("msys.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + end +end + diff --git a/xmake/platforms/msys/config.lua b/xmake/platforms/msys/config.lua deleted file mode 100644 index dbb1be255..000000000 --- a/xmake/platforms/msys/config.lua +++ /dev/null @@ -1,172 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.subarch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - mm = mm, mxx = mxx, - gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, - dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("msys.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/msys/xmake.lua b/xmake/platforms/msys/xmake.lua index b3abadbf9..69c56db22 100644 --- a/xmake/platforms/msys/xmake.lua +++ b/xmake/platforms/msys/xmake.lua @@ -36,8 +36,8 @@ platform("msys") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/sdcc/check.lua b/xmake/platforms/sdcc/check.lua new file mode 100644 index 000000000..6532ea00e --- /dev/null +++ b/xmake/platforms/sdcc/check.lua @@ -0,0 +1,114 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + config.set("arch", "stm8") + end +end + +-- check the cross toolchain +function _check_cross_toolchain() + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + + -- TODO add to environment module + -- add bin search library for loading some dependent .dll files windows + if cross_toolchain.bindir and is_host("windows") then + os.addenv("PATH", cross_toolchain.bindir) + end + end +end + +-- get toolchains +function _toolchains() + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local ranlib = toolchain("the static library index generator") + local as = toolchain("the assember") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib} + + -- init the c compiler + cc:add("$(env CC)", "sdcc") + + -- init the c preprocessor + cpp:add("$(env CPP)", "sdcpp") + + -- init the c++ compiler + cxx:add("$(env CXX)", "sdcc") + + -- init the assember + as:add("$(env AS)", "sdcc") + + -- init the linker + ld:add("$(env LD)", "$(env CXX)", "sdcc") + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)", "sdcc") + + -- init the static library archiver + ar:add("$(env AR)", "sdar") + + -- init the static library extractor + ex:add("$(env AR)", "sdar") + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("cross.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + + -- check cross toolchain + _check_cross_toolchain() + end +end + diff --git a/xmake/platforms/sdcc/config.lua b/xmake/platforms/sdcc/config.lua deleted file mode 100644 index ad2f14626..000000000 --- a/xmake/platforms/sdcc/config.lua +++ /dev/null @@ -1,114 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - config.set("arch", "stm8") - end -end - --- check the cross toolchain -function _check_cross_toolchain() - -- find cross toolchain - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - if cross_toolchain.bindir and is_host("windows") then - os.addenv("PATH", cross_toolchain.bindir) - end - end -end - --- get toolchains -function _toolchains() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib} - - -- init the c compiler - cc:add("$(env CC)", "sdcc") - - -- init the c preprocessor - cpp:add("$(env CPP)", "sdcpp") - - -- init the c++ compiler - cxx:add("$(env CXX)", "sdcc") - - -- init the assember - as:add("$(env AS)", "sdcc") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)", "sdcc") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)", "sdcc") - - -- init the static library archiver - ar:add("$(env AR)", "sdar") - - -- init the static library extractor - ex:add("$(env AR)", "sdar") - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cross.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - - -- check cross toolchain - _check_cross_toolchain() - end -end - diff --git a/xmake/platforms/sdcc/xmake.lua b/xmake/platforms/sdcc/xmake.lua index b06094f9f..ad2f02be9 100644 --- a/xmake/platforms/sdcc/xmake.lua +++ b/xmake/platforms/sdcc/xmake.lua @@ -30,8 +30,8 @@ platform("sdcc") -- set formats set_formats {static = "$(name).lib", object = "$(name).rel", binary = "$(name).bin", symbol = "$(name).sym"} - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/watchos/check.lua b/xmake/platforms/watchos/check.lua new file mode 100644 index 000000000..89086d74c --- /dev/null +++ b/xmake/platforms/watchos/check.lua @@ -0,0 +1,124 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_xcode") +import("private.platform.check_toolchain") + +-- get toolchains +function _toolchains() + + -- init architecture + local arch = config.get("arch") + local simulator = (arch == "i386") + + -- init cross + local cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local strip = toolchain("the symbols stripper") + local dsymutil = toolchain("the symbols generator") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local sc = toolchain("the swift compiler") + local sc_ld = toolchain("the swift linker") + local sc_sh = toolchain("the swift shared library linker") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, + mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} + + -- init the c compiler + cc:add({name = "clang", cross = cross}) + + -- init the c++ compiler + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + if simulator then + as:add({name = "clang", cross = cross}) + else + as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) + end + + -- init the linker + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add({name = "ar", cross = cross}) + + -- init the static library extractor + ex:add({name = "ar", cross = cross}) + + -- init the symbols stripper + strip:add({name = "strip", cross = cross}) + + -- init the symbols generator + dsymutil:add({name = "dsymutil", cross = cross}) + + -- init the objc compiler + mm:add({name = "clang", cross = cross}) + + -- init the objc++ compiler + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + + -- init the swift compiler and linker + sc:add({name = "swiftc", cross = cross}) + sc_ld:add({name = "swiftc", cross = cross}) + sc_sh:add({name = "swiftc", cross = cross}) + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("watchos.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config, "armv7k") + + -- check xcode + check_xcode(config) + end +end + diff --git a/xmake/platforms/watchos/config.lua b/xmake/platforms/watchos/config.lua deleted file mode 100644 index f16878b2e..000000000 --- a/xmake/platforms/watchos/config.lua +++ /dev/null @@ -1,124 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init architecture - local arch = config.get("arch") - local simulator = (arch == "i386") - - -- init cross - local cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} - - -- init the c compiler - cc:add({name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - if simulator then - as:add({name = "clang", cross = cross}) - else - as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) - end - - -- init the linker - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add({name = "ar", cross = cross}) - - -- init the static library extractor - ex:add({name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}) - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}) - - -- init the objc compiler - mm:add({name = "clang", cross = cross}) - - -- init the objc++ compiler - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - - -- init the swift compiler and linker - sc:add({name = "swiftc", cross = cross}) - sc_ld:add({name = "swiftc", cross = cross}) - sc_sh:add({name = "swiftc", cross = cross}) - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("watchos.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "armv7k") - - -- check xcode - check_xcode(config) - end -end - diff --git a/xmake/platforms/watchos/global.lua b/xmake/platforms/watchos/global.lua deleted file mode 100644 index f625eb103..000000000 --- a/xmake/platforms/watchos/global.lua +++ /dev/null @@ -1,36 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_xcode") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check xcode - check_xcode(global, true) -end - diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index 5c2e2a731..1311c47ba 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -33,11 +33,8 @@ platform("watchos") -- set formats set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).dSYM"} - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua new file mode 100644 index 000000000..55027ff6a --- /dev/null +++ b/xmake/platforms/windows/check.lua @@ -0,0 +1,139 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("core.platform.environment") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_vstudio") +import("private.platform.check_toolchain") + +-- get toolchains +function _toolchains() + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local mrc = toolchain("the resource compiler") + local ld = toolchain("the linker") + local sh = toolchain("the shared library linker") + local ar = toolchain("the static library archiver") + local ex = toolchain("the static library extractor") + local as = toolchain("the assember") + local gc = toolchain("the golang compiler") + local gc_ld = toolchain("the golang linker") + local gc_ar = toolchain("the golang static library archiver") + local dc = toolchain("the dlang compiler") + local dc_ld = toolchain("the dlang linker") + local dc_sh = toolchain("the dlang shared library linker") + local dc_ar = toolchain("the dlang static library archiver") + local rc = toolchain("the rust compiler") + local rc_ld = toolchain("the rust linker") + local rc_sh = toolchain("the rust shared library linker") + local rc_ar = toolchain("the rust static library archiver") + local cu = toolchain("the cuda compiler") + local cu_ld = toolchain("the cuda linker") + local toolchains = {cc = cc, cxx = cxx, mrc = mrc, as = as, ld = ld, sh = sh, ar = ar, ex = ex, + gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, + dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, + cu = cu, ["cu-ld"] = cu_ld} + + -- init the c compiler + cc:add("cl.exe") + + -- init the c++ compiler + cxx:add("cl.exe") + + -- init the resource compiler + mrc:add("rc.exe") + + -- init the assember + local arch = config.get("arch") + if arch and arch:find("64") then + as:add("ml64.exe") + else + as:add("ml.exe") + end + + -- init the linker + ld:add("link.exe") + + -- init the shared library linker + sh:add("link.exe -dll") + + -- init the static library archiver + ar:add("link.exe -lib") + + -- init the static library extractor + ex:add("lib.exe") + + -- init the golang compiler and linker + gc:add("$(env GC)", "go", "gccgo") + gc_ld:add("$(env GC)", "go", "gccgo") + gc_ar:add("$(env GC)", "go", "gccgo") + + -- init the dlang compiler and linker + dc:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") + dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") + + -- init the rust compiler and linker + rc:add("$(env RC)", "rustc") + rc_ld:add("$(env RC)", "rustc") + rc_sh:add("$(env RC)", "rustc") + rc_ar:add("$(env RC)", "rustc") + + -- init the cuda compiler and linker + cu:add("nvcc", "clang") + cu_ld:add("nvcc") + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("windows.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] + if toolchain then + environment.enter("toolchains") + check_toolchain(config, name, toolchain) + environment.leave("toolchains") + end + else + + -- check arch + check_arch(config) + + -- check vstudio + local cc = path.basename(config.get("cc") or "cl"):lower() + local cxx = path.basename(config.get("cxx") or "cl"):lower() + local mrc = path.basename(config.get("mrc") or "rc"):lower() + if cc == "cl" or cxx == "cl" or mrc == "rc" then + check_vstudio(config) + end + end +end + diff --git a/xmake/platforms/windows/config.lua b/xmake/platforms/windows/config.lua deleted file mode 100644 index c74205efe..000000000 --- a/xmake/platforms/windows/config.lua +++ /dev/null @@ -1,139 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("core.platform.environment") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_vstudio") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local mrc = toolchain("the resource compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local toolchains = {cc = cc, cxx = cxx, mrc = mrc, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, - dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, - cu = cu, ["cu-ld"] = cu_ld} - - -- init the c compiler - cc:add("cl.exe") - - -- init the c++ compiler - cxx:add("cl.exe") - - -- init the resource compiler - mrc:add("rc.exe") - - -- init the assember - local arch = config.get("arch") - if arch and arch:find("64") then - as:add("ml64.exe") - else - as:add("ml.exe") - end - - -- init the linker - ld:add("link.exe") - - -- init the shared library linker - sh:add("link.exe -dll") - - -- init the static library archiver - ar:add("link.exe -lib") - - -- init the static library extractor - ex:add("lib.exe") - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang") - cu_ld:add("nvcc") - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("windows.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - environment.enter("toolchains") - check_toolchain(config, name, toolchain) - environment.leave("toolchains") - end - else - - -- check arch - check_arch(config) - - -- check vstudio - local cc = path.basename(config.get("cc") or "cl"):lower() - local cxx = path.basename(config.get("cxx") or "cl"):lower() - local mrc = path.basename(config.get("mrc") or "rc"):lower() - if cc == "cl" or cxx == "cl" or mrc == "rc" then - check_vstudio(config) - end - end -end - diff --git a/xmake/platforms/windows/global.lua b/xmake/platforms/windows/global.lua deleted file mode 100644 index 9ef580bef..000000000 --- a/xmake/platforms/windows/global.lua +++ /dev/null @@ -1,49 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-2020, TBOOX Open Source Group. --- --- @author ruki --- @file global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_arch") -import("private.platform.check_vstudio") - --- clean temporary global configs -function _clean_global() - global.set("arch", nil) - global.set("__vcvarsall", nil) -end - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check arch - check_arch(global) - - -- check vstudio - check_vstudio(global, {try = true}) - - -- clean temporary global configs - _clean_global() -end - diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 43c7acccb..3bc2bf0cf 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -33,11 +33,8 @@ platform("windows") -- set formats set_formats {static = "$(name).lib", object = "$(name).obj", shared = "$(name).dll", binary = "$(name).exe", symbol = "$(name).pdb"} - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on environment enter on_environment_enter("environment.enter") diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index c10fe48d9..0e34232a6 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -25,4 +25,5 @@ import("private.platform.check_xcode") -- main entry function main(toolchain) check_xcode(config, true) + return true end -- cgit v1.3.1 From 8405406c0519338e1cfb75746e4b31ca5b6c3cc7 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:41:04 +0800 Subject: improve to check xcode toolchain --- xmake/platforms/macosx/check.lua | 1 + xmake/toolchains/xcode/check.lua | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'xmake/toolchains/xcode/check.lua') diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index ff552ad6b..2158dc25a 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -155,6 +155,7 @@ function main(platform) table.remove(toolchains, idx) end end + assert(#toolchains > 0, "toolchains not found!") --[[ -- only check the given config name? diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index 0e34232a6..925db3870 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -19,11 +19,33 @@ -- -- imports +import("core.base.option") import("core.project.config") -import("private.platform.check_xcode") +import("detect.sdks.find_xcode") -- main entry function main(toolchain) - check_xcode(config, true) + + -- find xcode + local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, plat = config.get("plat"), arch = config.get("arch")}) + if xcode then + config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) + else + return false + end + + -- save target minver + local xcode_sdkver = config.get("xcode_sdkver") + local target_minver = config.get("target_minver") + if xcode_sdkver and not target_minver then + target_minver = xcode_sdkver + if is_plat("macosx") then + local macos_ver = macos.version() + if macos_ver then + target_minver = macos_ver:major() .. "." .. macos_ver:minor() + end + end + config.set("target_minver", target_minver) + end return true end -- cgit v1.3.1