3
3
4
4
import common_compiler_flags
5
5
import my_spawn
6
- from SCons .Tool import mingw , msvc
6
+ from SCons .Tool import clang , clangxx , gcc , mingw , msvc
7
7
from SCons .Variables import BoolVariable
8
8
9
9
@@ -73,22 +73,22 @@ def spawn_capture(sh, escape, cmd, args, env):
73
73
74
74
75
75
def options (opts ):
76
- mingw = os .getenv ("MINGW_PREFIX" , "" )
77
-
78
76
opts .Add (BoolVariable ("use_mingw" , "Use the MinGW compiler instead of MSVC - only effective on Windows" , False ))
79
77
opts .Add (BoolVariable ("use_static_cpp" , "Link MinGW/MSVC C++ runtime libraries statically" , True ))
80
78
opts .Add (BoolVariable ("silence_msvc" , "Silence MSVC's cl/link stdout bloat, redirecting errors to stderr." , True ))
81
79
opts .Add (BoolVariable ("debug_crt" , "Compile with MSVC's debug CRT (/MDd)" , False ))
82
80
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" , "" ) )
84
82
85
83
86
84
def exists (env ):
87
85
return True
88
86
89
87
90
88
def 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 ):
92
92
if env ["arch" ] == "x86_64" :
93
93
env ["TARGET_ARCH" ] = "amd64"
94
94
elif env ["arch" ] == "arm64" :
@@ -130,9 +130,16 @@ def generate(env):
130
130
if env ["silence_msvc" ] and not env .GetOption ("clean" ):
131
131
silence_msvc (env )
132
132
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
+
136
143
# Don't want lib prefixes
137
144
env ["IMPLIBPREFIX" ] = ""
138
145
env ["SHLIBPREFIX" ] = ""
@@ -149,11 +156,14 @@ def generate(env):
149
156
"-static-libstdc++" ,
150
157
]
151
158
)
159
+ if env ["use_llvm" ]:
160
+ env .Append (LINKFLAGS = ["-lstdc++" ])
152
161
153
162
# Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
154
163
my_spawn .configure (env )
155
164
156
165
else :
166
+ mingw .generate (env )
157
167
env ["use_mingw" ] = True
158
168
# Cross-compilation using MinGW
159
169
prefix = ""
@@ -198,8 +208,7 @@ def generate(env):
198
208
if env ["use_llvm" ]:
199
209
env .Append (LINKFLAGS = ["-lstdc++" ])
200
210
201
- if sys .platform == "win32" or sys .platform == "msys" :
202
- my_spawn .configure (env )
211
+ my_spawn .configure (env )
203
212
204
213
env .Append (CPPDEFINES = ["WINDOWS_ENABLED" ])
205
214
0 commit comments