diff options
| author | ruki <[email protected]> | 2018-12-19 22:48:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-12-19 10:49:18 +0800 |
| commit | 1758e5f01e5684bf8da0187bb5b6ee7ac93fd4e6 (patch) | |
| tree | e5879bdf6d8f98432fd0e34912864b6b57998f6e /xmake/modules | |
| parent | 998aedba0b07b6b7605272b99e6dc0d59e5c8ac6 (diff) | |
improve mingw
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/detect/sdks/find_cross_toolchain.lua | 63 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_mingw.lua | 116 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_ndk.lua | 6 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_qt.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_wdk.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_xcode.lua | 2 |
6 files changed, 160 insertions, 31 deletions
diff --git a/xmake/modules/detect/sdks/find_cross_toolchain.lua b/xmake/modules/detect/sdks/find_cross_toolchain.lua index 107d7c916..915189d50 100644 --- a/xmake/modules/detect/sdks/find_cross_toolchain.lua +++ b/xmake/modules/detect/sdks/find_cross_toolchain.lua @@ -26,50 +26,63 @@ import("core.project.config") import("lib.detect.find_file") +-- find bin directory and cross +function _find_bindir(sdkdir, opt) + + -- init bin directories + local bindirs = {} + if opt.bindir then + table.insert(bindirs, opt.bindir) + end + table.insert(bindirs, path.join(sdkdir, "bin")) + table.insert(bindirs, path.join(sdkdir, "**", "bin")) + + -- attempt to find *-ld + local ldname = is_host("windows") and "ld.exe" or "ld" + local ldpath = find_file((opt.cross or '*-') .. ldname, bindirs) + if ldpath then + return path.directory(ldpath), path.basename(ldpath):sub(1, -3) + end + + -- find ld + ldpath = find_file(ldname, bindirs) + if ldpath then + return path.directory(ldpath), "" + end +end + -- find cross toolchain -- --- @param rootdir the root directory of cross toolchain --- @param opt the argument options --- .e.g {bin = .., cross = ..} +-- @param sdkdir the root sdk directory of cross toolchain +-- @param opt the argument options +-- .e.g {bindir = .., cross = ..} -- --- @return the toolchain .e.g {bin = .., cross = ..} +-- @return the toolchain .e.g {sdkdir = .., bindir = .., cross = ..} -- -- @code -- -- local toolchain = find_cross_toolchain("/xxx/android-cross-r10e") -- local toolchain = find_cross_toolchain("/xxx/android-cross-r10e", {cross = "arm-linux-androideabi-"}) --- local toolchain = find_cross_toolchain("/xxx/android-cross-r10e", {cross = "arm-linux-androideabi-", bin = ..}) +-- local toolchain = find_cross_toolchain("/xxx/android-cross-r10e", {cross = "arm-linux-androideabi-", bindir = ..}) -- -- @endcode -- -function main(rootdir, opt) +function main(sdkdir, opt) -- init arguments opt = opt or {} -- get root directory - if not rootdir or not os.isdir(rootdir) then + if not sdkdir or not os.isdir(sdkdir) then return end - -- init pathes - local pathes = {} - if opt.bin then - table.insert(pathes, opt.bin) + -- find bin directory and cross + local bindir, cross = _find_bindir(sdkdir, opt) + if not bindir then + return end - table.insert(pathes, path.join(rootdir, "bin")) - table.insert(pathes, path.join(rootdir, "**", "bin")) - -- attempt to find *-ld - local ldname = os.host() == "windows" and "ld.exe" or "ld" - local ldpath = find_file((opt.cross or '*-') .. ldname, pathes) - if ldpath then - return {bin = path.directory(ldpath), cross = path.basename(ldpath):sub(1, -3)} - end - - -- find ld - ldpath = find_file(ldname, pathes) - if ldpath then - return {bin = path.directory(ldpath), cross = ""} - end + -- found + return {sdkdir = sdkdir, bindir = bindir, cross = cross} end diff --git a/xmake/modules/detect/sdks/find_mingw.lua b/xmake/modules/detect/sdks/find_mingw.lua new file mode 100644 index 000000000..bca84c80f --- /dev/null +++ b/xmake/modules/detect/sdks/find_mingw.lua @@ -0,0 +1,116 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you 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 - 2018, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_mingw.lua +-- + +-- imports +import("lib.detect.cache") +import("core.base.option") +import("core.base.global") +import("core.project.config") +import("detect.sdks.find_cross_toolchain") + +-- find mingw directory +function _find_mingwdir(sdkdir) + + -- get mingw directory + if not sdkdir then + if is_host("macosx") then + sdkdir = "/usr/local/opt/mingw-w64" + end + end + + -- get mingw directory + if sdkdir and os.isdir(sdkdir) then + return sdkdir + end +end + +-- find the mingw toolchain +function _find_mingw(sdkdir, bindir, cross) + + -- find mingw root directory + sdkdir = _find_mingwdir(sdkdir) + if not sdkdir then + return {} + end + + -- find cross toolchain + local toolchain = find_cross_toolchain(sdkdir or bindir, {bindir = bindir, cross = cross}) + if toolchain then + return {sdkdir = toolchain.sdkdir, bindir = toolchain.bindir, cross = toolchain.cross} + end +end + +-- find mingw toolchains +-- +-- @param sdkdir the mingw directory +-- @param opt the argument options +-- .e.g {verbose = true, force = false, bindir = .., cross = ...} +-- +-- @return the mingw toolchains. .e.g {sdkdir = .., bindir = .., cross = ..} +-- +-- @code +-- +-- local toolchain = find_mingw("/xxx/android-mingw-r10e") +-- local toolchain = find_mingw("/xxx/android-mingw-r10e", {force = true, verbose = true}) +-- +-- @endcode +-- +function main(sdkdir, opt) + + -- init arguments + opt = opt or {} + + -- attempt to load cache first + local key = "detect.sdks.find_mingw" + local cacheinfo = cache.load(key) + if not opt.force and cacheinfo.mingw and cacheinfo.mingw.sdkdir and os.isdir(cacheinfo.mingw.sdkdir) then + return cacheinfo.mingw + end + + -- find mingw + local mingw = _find_mingw(sdkdir or config.get("mingw") or global.get("mingw") or config.get("sdk"), opt.bindir or config.get("bin"), opt.cross or config.get("cross")) + if mingw and mingw.sdkdir then + + -- save to config + config.set("mingw", mingw.sdkdir, {force = true, readonly = true}) + + -- trace + if opt.verbose or option.get("verbose") then + cprint("checking for the mingw directory ... ${green}%s", mingw.sdkdir) + end + else + + -- trace + if opt.verbose or option.get("verbose") then + cprint("checking for the mingw directory ... ${red}no") + end + end + + -- save to cache + cacheinfo.mingw = mingw or false + cache.save(key, cacheinfo) + + -- ok? + return mingw +end diff --git a/xmake/modules/detect/sdks/find_ndk.lua b/xmake/modules/detect/sdks/find_ndk.lua index 13909e2ce..a378dd6d6 100644 --- a/xmake/modules/detect/sdks/find_ndk.lua +++ b/xmake/modules/detect/sdks/find_ndk.lua @@ -142,9 +142,9 @@ function main(sdkdir, opt) opt = opt or {} -- attempt to load cache first - local key = "detect.sdks.find_ndk." .. (sdkdir or "") + local key = "detect.sdks.find_ndk" local cacheinfo = cache.load(key) - if not opt.force and cacheinfo.ndk then + if not opt.force and cacheinfo.ndk and cacheinfo.ndk.sdkdir and os.isdir(cacheinfo.ndk.sdkdir) then return cacheinfo.ndk end @@ -152,7 +152,7 @@ function main(sdkdir, opt) local arch = opt.arch or config.get("arch") or "armv7-a" -- find ndk - local ndk = _find_ndk(sdkdir or config.get("ndk") or global.get("ndk"), arch, opt.sdkver or config.get("ndk_sdkver"), opt.toolchains_ver or config.get("ndk_toolchains_ver")) + local ndk = _find_ndk(sdkdir or config.get("ndk") or global.get("ndk") or config.get("sdk"), arch, opt.sdkver or config.get("ndk_sdkver"), opt.toolchains_ver or config.get("ndk_toolchains_ver")) if ndk and ndk.sdkdir then -- save to config diff --git a/xmake/modules/detect/sdks/find_qt.lua b/xmake/modules/detect/sdks/find_qt.lua index 4bdfc9e4d..00b752824 100644 --- a/xmake/modules/detect/sdks/find_qt.lua +++ b/xmake/modules/detect/sdks/find_qt.lua @@ -154,7 +154,7 @@ function main(sdkdir, opt) end -- find qt - local qt = _find_qt(sdkdir or config.get("qt") or global.get("qt"), opt.version or config.get("qt_sdkver")) + local qt = _find_qt(sdkdir or config.get("qt") or global.get("qt") or config.get("sdk"), opt.version or config.get("qt_sdkver")) if qt then -- save to config diff --git a/xmake/modules/detect/sdks/find_wdk.lua b/xmake/modules/detect/sdks/find_wdk.lua index bd2e8b887..876a7b896 100644 --- a/xmake/modules/detect/sdks/find_wdk.lua +++ b/xmake/modules/detect/sdks/find_wdk.lua @@ -171,7 +171,7 @@ function main(sdkdir, opt) end -- find wdk - local wdk = _find_wdk(sdkdir or config.get("wdk") or global.get("wdk"), opt.version or config.get("wdk_sdkver")) + local wdk = _find_wdk(sdkdir or config.get("wdk") or global.get("wdk") or config.get("sdk"), opt.version or config.get("wdk_sdkver")) if wdk then -- save to config diff --git a/xmake/modules/detect/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua index 3d381f665..e9a806c68 100644 --- a/xmake/modules/detect/sdks/find_xcode.lua +++ b/xmake/modules/detect/sdks/find_xcode.lua @@ -117,7 +117,7 @@ function main(sdkdir, opt) local arch = opt.arch or config.get("arch") or "x86_64" -- find xcode - local xcode = _find_vscode(sdkdir or config.get("xcode") or global.get("xcode"), opt.sdkver or config.get("xcode_sdkver"), plat, arch) + local xcode = _find_vscode(sdkdir or config.get("xcode") or global.get("xcode") or config.get("sdk"), opt.sdkver or config.get("xcode_sdkver"), plat, arch) if xcode and xcode.sdkdir then -- save to config |
