This repository was archived by the owner on Jan 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSYSWithMSVCVars.bat
More file actions
328 lines (299 loc) · 10.2 KB
/
Copy pathMSYSWithMSVCVars.bat
File metadata and controls
328 lines (299 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
@ECHO OFF
setlocal enabledelayedexpansion
REM The MSYS location variable
SET MSYSDIR=C:\SDKs\msys64\
REM SET MSYSDIR=C:\SDKs\mingw\msys\1.0
SET USEBASH=1
REM Store current directory and ensure working directory is the location of current .bat
set CALLDIR=%CD%
set SCRIPTDIR=%~dp0
echo Choose Operation:
echo 1) Update
echo 2) Build
echo 3) Open Shell
SET /P useroper=Enter selection:
SET OPER=
if "%useroper%"=="1" (
SET OPER="Update"
SET ARCH="X86"
goto MSVCVARS
) else if "%useroper%"=="2" (
SET OPER="Build"
) else if "%useroper%"=="3" (
SET OPER="Shell"
) else (
echo Invalid selection. Terminating!
goto Terminate
)
echo Choose Build Type:
echo 1) x86
echo 2) x64
SET /P userarch=Enter selection:
SET ARCH=
if "%userarch%"=="1" (
SET ARCH="X86"
) else if "%userarch%"=="2" (
SET ARCH="X86_64"
) else (
echo Invalid selection. Terminating!
goto Terminate
)
REM Check for icl vars
if exist "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017\windows\bin\ipsxe-comp-vars.bat" (
goto ICLSETVARS
)
if exist "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2016\windows\bin\ipsxe-comp-vars.bat" (
goto ICLSETVARS
)
if exist "C:\Program Files (x86)\Intel\Composer XE 2015\bin\ipsxe-comp-vars.bat" (
goto ICLSETVARS
)
if exist "C:\Program Files (x86)\Intel\Composer XE 2013 SP1\bin\ipsxe-comp-vars.bat" (
goto ICLSETVARS
)
if exist "C:\Program Files (x86)\Intel\Composer XE 2013\bin\ipsxe-comp-vars.bat" (
goto ICLSETVARS
)
goto MSVCVARS
:ICLSETVARS
echo Choose Compiler Type:
echo 1) Intel Compiler (icl)
echo 2) Microsoft Compiler (msvc)
SET /P usercomp=Enter selection:
if "%usercomp%"=="1" (
goto ICLVARS
)
if "%usercomp%"=="2" (
goto MSVCVARS
)
echo Invalid selection. Terminating!
goto Terminate
:ICLVARS
echo Setting up ICL Vars...
REM Detect what version of VS is to be used
SET VSVERS=vs2013
if exist "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" (
SET VSVERS=vs2015
)
if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat" (
SET VSVERS=vs2017
)
REM Set the ICL system variables
if %ARCH%=="X86" (
goto ICLVARSX86
)
if %ARCH%=="X86_64" (
goto ICLVARSX64
)
echo "Error: Invalid vars (%ARCH%)"
goto Terminate
:ICLVARSX86
echo Using 32 bit x86 vars
echo Using Intel compiler environment
if exist "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017\windows\bin\ipsxe-comp-vars.bat" (
call "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017\windows\bin\ipsxe-comp-vars.bat" ia32 %VSVERS%
goto MSVCVarsDone
)
if exist "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2016\windows\bin\ipsxe-comp-vars.bat" (
call "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2016\windows\bin\ipsxe-comp-vars.bat" ia32 %VSVERS%
goto MSVCVarsDone
)
if exist "C:\Program Files (x86)\Intel\Composer XE 2015\bin\ipsxe-comp-vars.bat" (
call "C:\Program Files (x86)\Intel\Composer XE 2015\bin\ipsxe-comp-vars.bat" ia32 %VSVERS%
goto MSVCVarsDone
)
if exist "C:\Program Files (x86)\Intel\Composer XE 2013 SP1\bin\ipsxe-comp-vars.bat" (
call "C:\Program Files (x86)\Intel\Composer XE 2013 SP1\bin\ipsxe-comp-vars.bat" ia32 %VSVERS%
goto MSVCVarsDone
)
if exist "C:\Program Files (x86)\Intel\Composer XE 2013\bin\ipsxe-comp-vars.bat" (
call "C:\Program Files (x86)\Intel\Composer XE 2013\bin\ipsxe-comp-vars.bat" ia32 %VSVERS%
goto MSVCVarsDone
)
goto Terminate32VSVars
:ICLVARSX64
echo Using 64 bit x86 vars
echo Using Intel compiler environment
if exist "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017\windows\bin\ipsxe-comp-vars.bat" (
call "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2017\windows\bin\ipsxe-comp-vars.bat" intel64 %VSVERS%
goto MSVCVarsDone
)
if exist "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2016\windows\bin\ipsxe-comp-vars.bat" (
call "C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2016\windows\bin\ipsxe-comp-vars.bat" intel64 %VSVERS%
goto MSVCVarsDone
)
if exist "C:\Program Files (x86)\Intel\Composer XE 2015\bin\ipsxe-comp-vars.bat" (
call "C:\Program Files (x86)\Intel\Composer XE 2015\bin\ipsxe-comp-vars.bat" intel64 %VSVERS%
goto MSVCVarsDone
)
if exist "C:\Program Files (x86)\Intel\Composer XE 2013 SP1\bin\ipsxe-comp-vars.bat" (
call "C:\Program Files (x86)\Intel\Composer XE 2013 SP1\bin\ipsxe-comp-vars.bat" intel64 %VSVERS%
goto MSVCVarsDone
)
if exist "C:\Program Files (x86)\Intel\Composer XE 2013\bin\ipsxe-comp-vars.bat" (
call "C:\Program Files (x86)\Intel\Composer XE 2013\bin\ipsxe-comp-vars.bat" intel64 %VSVERS%
goto MSVCVarsDone
)
goto Terminate64VSVars
:MSVCVARS
echo Setting up MSVC Vars...
REM Check if already running in an environment with VS setup
if defined VCINSTALLDIR (
if defined VisualStudioVersion (
echo Existing Visual Studio environment detected...
if "%VisualStudioVersion%"=="16.0" (
set MSVC_VER=16
goto MSVCVarsDone
) else if "%VisualStudioVersion%"=="15.0" (
set MSVC_VER=15
goto MSVCVarsDone
) else if "%VisualStudioVersion%"=="14.0" (
set MSVC_VER=14
goto MSVCVarsDone
) else if "%VisualStudioVersion%"=="12.0" (
set MSVC_VER=12
goto MSVCVarsDone
) else (
echo Unknown Visual Studio environment detected '%VisualStudioVersion%', Creating a new one...
)
)
)
REM First check for a environment variable to help locate the VS installation
if defined VS140COMNTOOLS (
if exist "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" (
echo Visual Studio 2015 environment detected...
call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" >nul 2>&1
set MSVC_VER=14
goto MSVCVarsDone
)
)
if defined VS120COMNTOOLS (
if exist "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" (
echo Visual Studio 2013 environment detected...
call "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" >nul 2>&1
set MSVC_VER=12
goto MSVCVarsDone
)
)
REM Check for default install locations based on current system architecture
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
echo Detected 64 bit system...
set SYSARCH=64
) else if "%PROCESSOR_ARCHITECTURE%"=="x86" (
if "%PROCESSOR_ARCHITEW6432%"=="AMD64" (
echo Detected 64 bit system running 32 bit shell...
set SYSARCH=64
) else (
echo Detected 32 bit system...
set SYSARCH=32
)
) else (
echo Error: Could not detect current platform architecture!"
goto Terminate
)
if "%SYSARCH%"=="32" (
set MSVCVARSDIR=
set WOWNODE=
) else if "%SYSARCH%"=="64" (
set MSVCVARSDIR=\amd64
set WOWNODE=\WOW6432Node
) else (
goto Terminate
)
if %ARCH%=="X86" (
set SELARCH=32
) else if %ARCH%=="X86_64" (
set SELARCH=64
) else (
goto Terminate
)
reg.exe query "HKLM\SOFTWARE%WOWNODE%\Microsoft\VisualStudio\SxS\VS7" /v 15.0 >nul 2>&1
if not ERRORLEVEL 1 (
echo Visual Studio 2017 installation detected...
for /f "skip=2 tokens=2,*" %%a in ('reg.exe query "HKLM\SOFTWARE%WOWNODE%\Microsoft\VisualStudio\SxS\VS7" /v 15.0') do (set VSINSTALLDIR=%%b)
call "!VSINSTALLDIR!VC\Auxiliary\Build\vcvars%SELARCH%.bat" >nul 2>&1
set MSVC_VER=15
goto MSVCVarsDone
)
reg.exe query "HKLM\Software%WOWNODE%\Microsoft\VisualStudio\14.0" /v "InstallDir" >nul 2>&1
if not ERRORLEVEL 1 (
echo Visual Studio 2015 installation detected...
for /f "skip=2 tokens=2,*" %%a in ('reg.exe query "HKLM\Software%WOWNODE%\Microsoft\VisualStudio\14.0" /v "InstallDir"') do (set VSINSTALLDIR=%%b)
call "!VSINSTALLDIR!\VC\bin%MSVCVARSDIR%\vcvars%SELARCH%.bat" >nul 2>&1
set MSVC_VER=14
goto MSVCVarsDone
)
reg.exe query "HKLM\Software%WOWNODE%\Microsoft\VisualStudio\12.0" /v "InstallDir" >nul 2>&1
if not ERRORLEVEL 1 (
echo Visual Studio 2013 installation detected...
for /f "skip=2 tokens=2,*" %%a in ('reg.exe query "HKLM\Software%WOWNODE%\Microsoft\VisualStudio\12.0" /v "InstallDir"') do (set VSINSTALLDIR=%%b)
call "!VSINSTALLDIR!\VC\bin%MSVCVARSDIR%\vcvars%SELARCH%.bat" >nul 2>&1
set MSVC_VER=12
goto MSVCVarsDone
)
echo Error: Could not find valid Visual Studio installation!
goto Terminate
:MSVCVarsDone
pushd %SCRIPTDIR%
if %USEBASH%==1 (
goto BASH
)
:MSYS
echo Configuring MSVC Link...
REM When using msvc we need to rename the coreutils link.exe so that it does not interfere with the msvc linker in $PATH
if exist %MSYSDIR%\usr\bin\link.exe (
move %MSYSDIR%\usr\bin\link.exe %MSYSDIR%\usr\bin\link_dontuse.exe
)
if exist %MSYSDIR%\bin\link.exe (
move %MSYSDIR%\bin\link.exe %MSYSDIR%\bin\link_dontuse.exe
)
echo Calling MSYS environment...
REM Need to be in the MSYS dir to call the bat file
pushd "%MSYSDIR%"
if exist msys2_shell.bat (
goto MSYS2
)
if exist msys2_shell.cmd (
goto MSYS2CMD
)
call "msys.bat"
goto FINISH
:MSYS2
call "msys2_shell.bat"
goto FINISH
:MSYS2CMD
REM Currently we need to backup INCLUDE and pass as an alternative as mintty stomps it
if %ARCH%=="X86" (
set COMMAND=mingw32
) else if %ARCH%=="X86_64" (
set COMMAND=mingw64
)
set TINCLUDE=%INCLUDE%
set TLIB=%LIB%
if %OPER%=="Update" (
call "msys2_shell.cmd" -%COMMAND% -use-full-path -where %SCRIPTDIR% -full-path %SCRIPTDIR%\UpdateDependencies.sh
) else if %OPER%=="Build" (
call "msys2_shell.cmd" -%COMMAND% -use-full-path -where %SCRIPTDIR% -full-path %SCRIPTDIR%\BuildDependenciesScript.sh
) else if %OPER%=="Shell" (
call "msys2_shell.cmd" -%COMMAND% -use-full-path -where %SCRIPTDIR%
)
echo Returning MSVC Link...
REM When using the msvc toolchain then we need to reset the coreutils link.exe
if exist %MSYSDIR%\bin\link_dontuse.exe (
move %MSYSDIR%\bin\link_dontuse.exe %MSYSDIR%\bin\link.exe
)
popd
goto FINISH
:BASH
if %OPER%=="Update" (
call bash -c ./UpdateDependencies.sh
) else if %OPER%=="Build" (
call bash -c ./BuildDependenciesScript.sh
) else if %OPER%=="Shell" (
call bash
)
:FINISH
echo Done
pushd %CALLDIR%
:Terminate
pause