33
44import common_compiler_flags
55import my_spawn
6- from SCons .Tool import mingw , msvc
6+ from SCons .Tool import clang , clangxx , gcc , mingw , msvc
77from SCons .Variables import BoolVariable
88
99
@@ -73,22 +73,22 @@ def spawn_capture(sh, escape, cmd, args, env):
7373
7474
7575def options (opts ):
76- mingw = os .getenv ("MINGW_PREFIX" , "" )
77-
7876 opts .Add (BoolVariable ("use_mingw" , "Use the MinGW compiler instead of MSVC - only effective on Windows" , False ))
7977 opts .Add (BoolVariable ("use_static_cpp" , "Link MinGW/MSVC C++ runtime libraries statically" , True ))
8078 opts .Add (BoolVariable ("silence_msvc" , "Silence MSVC's cl/link stdout bloat, redirecting errors to stderr." , True ))
8179 opts .Add (BoolVariable ("debug_crt" , "Compile with MSVC's debug CRT (/MDd)" , False ))
8280 opts .Add (BoolVariable ("use_llvm" , "Use the LLVM compiler (MVSC or MinGW depending on the use_mingw flag)" , False ))
83- opts .Add ("mingw_prefix" , "MinGW prefix" , mingw )
81+ opts .Add ("mingw_prefix" , "MinGW prefix" , os . getenv ( "MINGW_PREFIX" , "" ) )
8482
8583
8684def exists (env ):
8785 return True
8886
8987
9088def generate (env ):
91- if not env ["use_mingw" ] and msvc .exists (env ):
89+ env ["msystem" ] = os .getenv ("MSYSTEM" , "" )
90+
91+ if not (env ["use_mingw" ] or env ["msystem" ]) and msvc .exists (env ):
9292 if env ["arch" ] == "x86_64" :
9393 env ["TARGET_ARCH" ] = "amd64"
9494 elif env ["arch" ] == "arm64" :
@@ -130,9 +130,16 @@ def generate(env):
130130 if env ["silence_msvc" ] and not env .GetOption ("clean" ):
131131 silence_msvc (env )
132132
133- elif (sys .platform == "win32" or sys .platform == "msys" ) and not env ["mingw_prefix" ]:
134- env ["use_mingw" ] = True
135- mingw .generate (env )
133+ elif env ["msystem" ]:
134+ # default compiler is dictated by the msystem environment.
135+ match env ["msystem" ]:
136+ case "UCRT64" | "MINGW64" | "MINGW32" :
137+ gcc .generate (env )
138+ case "CLANG64" | "CLANGARM64" | "CLANG32" :
139+ env ["use_llvm" ] = True
140+ clang .generate (env )
141+ clangxx .generate (env )
142+
136143 # Don't want lib prefixes
137144 env ["IMPLIBPREFIX" ] = ""
138145 env ["SHLIBPREFIX" ] = ""
@@ -149,11 +156,14 @@ def generate(env):
149156 "-static-libstdc++" ,
150157 ]
151158 )
159+ if env ["use_llvm" ]:
160+ env .Append (LINKFLAGS = ["-lstdc++" ])
152161
153162 # Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
154163 my_spawn .configure (env )
155164
156165 else :
166+ mingw .generate (env )
157167 env ["use_mingw" ] = True
158168 # Cross-compilation using MinGW
159169 prefix = ""
@@ -198,8 +208,7 @@ def generate(env):
198208 if env ["use_llvm" ]:
199209 env .Append (LINKFLAGS = ["-lstdc++" ])
200210
201- if sys .platform == "win32" or sys .platform == "msys" :
202- my_spawn .configure (env )
211+ my_spawn .configure (env )
203212
204213 env .Append (CPPDEFINES = ["WINDOWS_ENABLED" ])
205214
0 commit comments