summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-12-19 22:48:13 +0800
committerruki <[email protected]>2018-12-19 10:49:18 +0800
commit1758e5f01e5684bf8da0187bb5b6ee7ac93fd4e6 (patch)
treee5879bdf6d8f98432fd0e34912864b6b57998f6e
parent998aedba0b07b6b7605272b99e6dc0d59e5c8ac6 (diff)
improve mingw
-rw-r--r--CHANGELOG.md2
-rw-r--r--xmake/modules/detect/sdks/find_cross_toolchain.lua63
-rw-r--r--xmake/modules/detect/sdks/find_mingw.lua116
-rw-r--r--xmake/modules/detect/sdks/find_ndk.lua6
-rw-r--r--xmake/modules/detect/sdks/find_qt.lua2
-rw-r--r--xmake/modules/detect/sdks/find_wdk.lua2
-rw-r--r--xmake/modules/detect/sdks/find_xcode.lua2
-rw-r--r--xmake/platforms/cross/check.lua8
-rw-r--r--xmake/platforms/cross/load.lua10
-rw-r--r--xmake/platforms/linux/check.lua4
-rw-r--r--xmake/platforms/linux/load.lua10
-rw-r--r--xmake/platforms/mingw/check.lua52
-rw-r--r--xmake/platforms/mingw/load.lua7
-rw-r--r--xmake/platforms/mingw/xmake.lua14
14 files changed, 223 insertions, 75 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7e4074cc9..7a103c208 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@
* Improve to switch version and debug mode for the dependent packages
* [#264](https://github.com/tboox/xmake/issues/264): Support `xmake update dev` on windows
+* [#293](https://github.com/tboox/xmake/issues/293): Add `xmake f/g --mingw=xxx` configuration option and improve to find_mingw
### Bugs fixed
@@ -544,6 +545,7 @@
* 针对远程依赖包,改进版本和调试模式切换
* [#264](https://github.com/tboox/xmake/issues/264): 支持在windows上更新dev/master版本,`xmake update dev`
+* [#293](https://github.com/tboox/xmake/issues/293): 添加`xmake f/g --mingw=xxx` 配置选线,并且改进find_mingw检测
### Bugs修复
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
diff --git a/xmake/platforms/cross/check.lua b/xmake/platforms/cross/check.lua
index 0508eae17..90592b3a5 100644
--- a/xmake/platforms/cross/check.lua
+++ b/xmake/platforms/cross/check.lua
@@ -46,17 +46,17 @@ function _toolchains(config)
-- find cross toolchain
local cross = ""
- local toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bin = config.get("bin"), cross = config.get("cross")})
+ local toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")})
if toolchain then
-- save toolchain
config.set("cross", toolchain.cross, {readonly = true, force = true})
- config.set("bin", toolchain.bin, {readonly = true, force = true})
+ config.set("bin", toolchain.bindir, {readonly = true, force = true})
cross = toolchain.cross
-- add bin search library for loading some dependent .dll files windows
- if toolchain.bin and is_host("windows") then
- os.addenv("PATH", toolchain.bin)
+ if toolchain.bindir and is_host("windows") then
+ os.addenv("PATH", toolchain.bindir)
end
end
diff --git a/xmake/platforms/cross/load.lua b/xmake/platforms/cross/load.lua
index 576925931..2869541a1 100644
--- a/xmake/platforms/cross/load.lua
+++ b/xmake/platforms/cross/load.lua
@@ -31,8 +31,14 @@ function main(platform)
-- init linkdirs and includedirs
local sdkdir = config.get("sdk")
if sdkdir then
- platform:add("includedirs", path.join(sdkdir, "include"))
- platform:add("linkdirs", path.join(sdkdir, "lib"))
+ local includedir = path.join(sdkdir, "include")
+ if os.isdir(includedir) then
+ platform:add("includedirs", includedir)
+ end
+ local linkdir = path.join(sdkdir, "lib")
+ if os.isdir(linkdir) then
+ platform:add("linkdirs", linkdir)
+ end
end
-- add bin search library for loading some dependent .dll files windows
diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua
index 87a225eec..b226ab206 100644
--- a/xmake/platforms/linux/check.lua
+++ b/xmake/platforms/linux/check.lua
@@ -51,10 +51,10 @@ function _toolchains(config)
-- find cross toolchain
local cross = ""
- local toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bin = config.get("bin"), cross = config.get("cross")})
+ local toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")})
if toolchain then
config.set("cross", toolchain.cross, {readonly = true, force = true})
- config.set("bin", toolchain.bin, {readonly = true, force = true})
+ config.set("bin", toolchain.bindir, {readonly = true, force = true})
cross = toolchain.cross
end
diff --git a/xmake/platforms/linux/load.lua b/xmake/platforms/linux/load.lua
index e6af9a61a..72e48e096 100644
--- a/xmake/platforms/linux/load.lua
+++ b/xmake/platforms/linux/load.lua
@@ -34,8 +34,14 @@ function main(platform)
-- init linkdirs and includedirs
local sdkdir = config.get("sdk")
if sdkdir then
- platform:add("includedirs", path.join(sdkdir, "include"))
- platform:add("linkdirs", path.join(sdkdir, "lib"))
+ local includedir = path.join(sdkdir, "include")
+ if os.isdir(includedir) then
+ platform:add("includedirs", includedir)
+ end
+ local linkdir = path.join(sdkdir, "lib")
+ if os.isdir(linkdir) then
+ platform:add("linkdirs", linkdir)
+ end
end
-- ok
diff --git a/xmake/platforms/mingw/check.lua b/xmake/platforms/mingw/check.lua
index dfb9fe5d9..b5b6d90bf 100644
--- a/xmake/platforms/mingw/check.lua
+++ b/xmake/platforms/mingw/check.lua
@@ -23,9 +23,25 @@
--
-- imports
-import("detect.sdks.find_cross_toolchain")
+import("detect.sdks.find_mingw")
import("platforms.checker", {rootdir = os.programdir()})
+-- check the mingw toolchain
+function _check_mingw(config)
+ 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}) -- maybe to global
+ config.set("cross", mingw.cross, {readonly = true, force = true})
+ config.set("bin", mingw.bindir, {readonly = true, force = true})
+ else
+ -- failed
+ cprint("${bright red}please run:")
+ cprint("${red} - xmake config --ndk=xxx")
+ cprint("${red}or - xmake global --ndk=xxx")
+ raise()
+ end
+end
+
-- get toolchains
function _toolchains(config)
@@ -34,32 +50,13 @@ function _toolchains(config)
return _g.TOOLCHAINS
end
- -- init arch
- local arch = config.get("arch")
- if not arch or arch == "i386" then
- arch = "i686"
- end
-
- -- get sdk directory, TODO add detect.sdks.find_mingw
- local sdk = config.get("sdk")
- if os.host() == "macosx" and not sdk then
- sdk = "/usr/local/opt/mingw-w64"
- end
-
- -- find cross toolchain
- local cross = ""
- local toolchain = find_cross_toolchain(sdk or config.get("bin"), {bin = config.get("bin"), cross = config.get("cross")})
- if toolchain then
-
- -- save toolchain
- config.set("cross", toolchain.cross, {readonly = true, force = true})
- config.set("bin", toolchain.bin, {readonly = true, force = true})
- cross = toolchain.cross
+ -- get cross
+ local cross = config.get("cross")
- -- add bin search library for loading some dependent .dll files windows
- if toolchain.bin and is_host("windows") then
- os.addenv("PATH", toolchain.bin)
- end
+ -- 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
-- make toolchains
@@ -94,7 +91,8 @@ function main(kind, toolkind)
-- init the check list of config
_g.config =
{
- { checker.check_arch, "i386" }
+ { checker.check_arch, "x86_64" }
+ , _check_mingw
}
-- init the check list of global
diff --git a/xmake/platforms/mingw/load.lua b/xmake/platforms/mingw/load.lua
index d37977143..d419032dc 100644
--- a/xmake/platforms/mingw/load.lua
+++ b/xmake/platforms/mingw/load.lua
@@ -44,13 +44,6 @@ function main(platform)
platform:add("shflags", archflags)
end
- -- init linkdirs and includedirs
- local sdkdir = config.get("sdk")
- if sdkdir then
- platform:add("includedirs", path.join(sdkdir, "include"))
- platform:add("linkdirs", path.join(sdkdir, "lib"))
- end
-
-- add bin search library for loading some dependent .dll files windows
local bindir = config.get("bin")
if bindir and is_host("windows") then
diff --git a/xmake/platforms/mingw/xmake.lua b/xmake/platforms/mingw/xmake.lua
index da19c2fbb..e1cd53207 100644
--- a/xmake/platforms/mingw/xmake.lua
+++ b/xmake/platforms/mingw/xmake.lua
@@ -43,3 +43,17 @@ platform("mingw")
-- on load
on_load("load")
+ -- set menu
+ set_menu {
+ config =
+ {
+ {category = "MingW Configuration" }
+ , {nil, "mingw", "kv", nil, "The MingW SDK Directory" }
+ }
+
+ , global =
+ {
+ {category = "MingW Configuration" }
+ , {nil, "mingw", "kv", nil, "The MingW SDK Directory" }
+ }
+ }