summaryrefslogtreecommitdiff
path: root/xmake/modules/detect
diff options
context:
space:
mode:
authorruki <[email protected]>2020-10-05 23:12:52 +0800
committerruki <[email protected]>2020-10-05 13:17:45 +0800
commit5fb2bcc38583f830e064082024212c061f055b99 (patch)
tree24198cdd2d4c7a6093584074933a4ae08d651225 /xmake/modules/detect
parent8e6f673fe1eb57a5f5535d9bac663868a3922caf (diff)
improve find_mingw
Diffstat (limited to 'xmake/modules/detect')
-rw-r--r--xmake/modules/detect/sdks/find_mingw.lua26
1 files changed, 21 insertions, 5 deletions
diff --git a/xmake/modules/detect/sdks/find_mingw.lua b/xmake/modules/detect/sdks/find_mingw.lua
index cf6cfcc8c..a5bf55932 100644
--- a/xmake/modules/detect/sdks/find_mingw.lua
+++ b/xmake/modules/detect/sdks/find_mingw.lua
@@ -33,11 +33,27 @@ function _find_mingwdir(sdkdir)
if not sdkdir then
if is_host("macosx", "linux") and os.isdir("/opt/llvm-mingw") then
sdkdir = "/opt/llvm-mingw"
- else
- if is_host("macosx") then
- sdkdir = "/usr/local/opt/mingw-w64"
- elseif is_host("linux") then
- sdkdir = "/usr"
+ elseif is_host("macosx") and os.isdir("/usr/local/opt/mingw-w64") then
+ sdkdir = "/usr/local/opt/mingw-w64"
+ elseif is_host("linux") then
+ sdkdir = "/usr"
+ elseif is_subhost("msys") then
+ local mingw_prefix = os.getenv("MINGW_PREFIX")
+ if mingw_prefix and os.isdir(mingw_prefix) then
+ sdkdir = mingw_prefix
+ end
+ end
+ -- attempt to get it from $PATH
+ -- @see https://github.com/xmake-io/xmake/issues/977
+ if not sdkdir then
+ local pathenv = os.getenv("PATH")
+ if pathenv then
+ for _, p in ipairs(path.splitenv(pathenv)) do
+ if p:find("mingw[%w%-%_%+]+[\\/]bin") and path.filename(p) == "bin" and os.isdir(p) then
+ sdkdir = path.directory(p)
+ break
+ end
+ end
end
end
end