1
+ import os
1
2
import sys
2
3
3
4
import common_compiler_flags
@@ -72,10 +73,14 @@ def spawn_capture(sh, escape, cmd, args, env):
72
73
73
74
74
75
def options (opts ):
76
+ mingw = os .getenv ("MINGW_PREFIX" , "" )
77
+
75
78
opts .Add (BoolVariable ("use_mingw" , "Use the MinGW compiler instead of MSVC - only effective on Windows" , False ))
76
79
opts .Add (BoolVariable ("use_clang_cl" , "Use the clang driver instead of MSVC - only effective on Windows" , False ))
77
80
opts .Add (BoolVariable ("use_static_cpp" , "Link MinGW/MSVC C++ runtime libraries statically" , True ))
78
81
opts .Add (BoolVariable ("silence_msvc" , "Silence MSVC's cl/link stdout bloat, redirecting errors to stderr." , True ))
82
+ opts .Add (BoolVariable ("use_llvm" , "Use the LLVM compiler" , False ))
83
+ opts .Add ("mingw_prefix" , "MinGW prefix" , mingw )
79
84
80
85
81
86
def exists (env ):
@@ -86,12 +91,22 @@ def generate(env):
86
91
if not env ["use_mingw" ] and msvc .exists (env ):
87
92
if env ["arch" ] == "x86_64" :
88
93
env ["TARGET_ARCH" ] = "amd64"
94
+ elif env ["arch" ] == "arm64" :
95
+ env ["TARGET_ARCH" ] = "arm64"
96
+ elif env ["arch" ] == "arm32" :
97
+ env ["TARGET_ARCH" ] = "arm"
89
98
elif env ["arch" ] == "x86_32" :
90
99
env ["TARGET_ARCH" ] = "x86"
100
+
101
+ env ["MSVC_SETUP_RUN" ] = False # Need to set this to re-run the tool
102
+ env ["MSVS_VERSION" ] = None
103
+ env ["MSVC_VERSION" ] = None
104
+
91
105
env ["is_msvc" ] = True
92
106
93
107
# MSVC, linker, and archiver.
94
108
msvc .generate (env )
109
+ env .Tool ("msvc" )
95
110
env .Tool ("mslib" )
96
111
env .Tool ("mslink" )
97
112
@@ -111,7 +126,7 @@ def generate(env):
111
126
if env ["silence_msvc" ] and not env .GetOption ("clean" ):
112
127
silence_msvc (env )
113
128
114
- elif sys .platform == "win32" or sys .platform == "msys" :
129
+ elif ( sys .platform == "win32" or sys .platform == "msys" ) and not env [ "mingw_prefix" ] :
115
130
env ["use_mingw" ] = True
116
131
mingw .generate (env )
117
132
# Don't want lib prefixes
@@ -137,12 +152,32 @@ def generate(env):
137
152
else :
138
153
env ["use_mingw" ] = True
139
154
# Cross-compilation using MinGW
140
- prefix = "i686" if env ["arch" ] == "x86_32" else env ["arch" ]
141
- env ["CXX" ] = prefix + "-w64-mingw32-g++"
142
- env ["CC" ] = prefix + "-w64-mingw32-gcc"
143
- env ["AR" ] = prefix + "-w64-mingw32-ar"
144
- env ["RANLIB" ] = prefix + "-w64-mingw32-ranlib"
145
- env ["LINK" ] = prefix + "-w64-mingw32-g++"
155
+ prefix = ""
156
+ if env ["mingw_prefix" ]:
157
+ prefix = env ["mingw_prefix" ] + "/bin/"
158
+
159
+ if env ["arch" ] == "x86_64" :
160
+ prefix += "x86_64"
161
+ elif env ["arch" ] == "arm64" :
162
+ prefix += "aarch64"
163
+ elif env ["arch" ] == "arm32" :
164
+ prefix += "armv7"
165
+ elif env ["arch" ] == "x86_32" :
166
+ prefix += "i686"
167
+
168
+ if env ["use_llvm" ]:
169
+ env ["CXX" ] = prefix + "-w64-mingw32-clang++"
170
+ env ["CC" ] = prefix + "-w64-mingw32-clang"
171
+ env ["AR" ] = prefix + "-w64-mingw32-llvm-ar"
172
+ env ["RANLIB" ] = prefix + "-w64-mingw32-ranlib"
173
+ env ["LINK" ] = prefix + "-w64-mingw32-clang"
174
+ else :
175
+ env ["CXX" ] = prefix + "-w64-mingw32-g++"
176
+ env ["CC" ] = prefix + "-w64-mingw32-gcc"
177
+ env ["AR" ] = prefix + "-w64-mingw32-gcc-ar"
178
+ env ["RANLIB" ] = prefix + "-w64-mingw32-ranlib"
179
+ env ["LINK" ] = prefix + "-w64-mingw32-g++"
180
+
146
181
# Want dll suffix
147
182
env ["SHLIBSUFFIX" ] = ".dll"
148
183
@@ -156,6 +191,11 @@ def generate(env):
156
191
"-static-libstdc++" ,
157
192
]
158
193
)
194
+ if env ["use_llvm" ]:
195
+ env .Append (LINKFLAGS = ["-lstdc++" ])
196
+
197
+ if sys .platform == "win32" or sys .platform == "msys" :
198
+ my_spawn .configure (env )
159
199
160
200
env .Append (CPPDEFINES = ["WINDOWS_ENABLED" ])
161
201
0 commit comments