-
-
Notifications
You must be signed in to change notification settings - Fork 618
/
Bootstrap.bat
executable file
·181 lines (125 loc) · 4.53 KB
/
Bootstrap.bat
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
@ECHO OFF
SETLOCAL
SETLOCAL ENABLEDELAYEDEXPANSION
REM ===========================================================================
SET SelfPath="%0"
SET VsWherePath="C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe"
REM ===========================================================================
SET "PlatformArg="
SET "ConfigArg="
IF NOT "%PLATFORM%" == "" (
SET "PlatformArg=PLATFORM=%PLATFORM%"
)
IF NOT "%CONFIG%" == "" (
SET "ConfigArg=CONFIG=%CONFIG%"
)
SET vsversion=%1
IF "%vsversion%" == "" (
CALL :BootstrapLatest
EXIT /B %ERRORLEVEL%
)
IF "%vsversion%" == "vs2010" (
CALL :LegacyVisualBootstrap "%vsversion%" "100"
) ELSE IF "%vsversion%" == "vs2012" (
CALL :LegacyVisualBootstrap "%vsversion%" "110"
) ELSE IF "%vsversion%" == "vs2013" (
CALL :LegacyVisualBootstrap "%vsversion%" "120"
) ELSE IF "%vsversion%" == "vs2015" (
CALL :LegacyVisualBootstrap "%vsversion%" "140"
) ELSE IF "%vsversion%" == "vs2017" (
CALL :VsWhereVisualBootstrap "%vsversion%" "15.0" "16.0"
) ELSE IF "%vsversion%" == "vs2019" (
CALL :VsWhereVisualBootstrap "%vsversion%" "16.0" "17.0"
) ELSE IF "%vsversion%" == "vs2022" (
CALL :VsWhereVisualBootstrap "%vsversion%" "17.0" "18.0"
) ELSE (
ECHO Unrecognized Visual Studio version %vsversion%
EXIT /B 2
)
REM On error, pause to allow user to notice it if script was launched through explorer
IF %ERRORLEVEL% NEQ 0 (
PAUSE
)
EXIT /B %ERRORLEVEL%
REM ===========================================================================
REM Utils
REM ===========================================================================
REM %1: PremakeVsVersion -> ex: vs2015
REM %2: VsVersion envvar -> ex: 140
:LegacyVisualBootstrap
SET "VsVersion_NoPoint=%~2"
SET "VsEnvVar=VS%VsVersion_NoPoint%COMNTOOLS"
SET "VsPath=!%VsEnvVar%!"
IF NOT EXIST "%VsPath%vsdevcmd.bat" (
ECHO Could not find vsdevcmd.bat to setup Visual Studio environment
EXIT /B 2
)
CALL "%VsPath%vsdevcmd.bat" && nmake MSDEV="%~1" %PlatformArg% %ConfigArg% -f Bootstrap.mak windows
EXIT /B %ERRORLEVEL%
REM :LegacyVisualBootstrap
REM ===========================================================================
REM %1: PremakeVsVersion -> ex: vs2010
REM %2: VisualStudio-style VSversionMin -> ex: 15.0
REM %3: VisualStudio-style VSversionMax -> ex: 16.0
:VsWhereVisualBootstrap
SET "PremakeVsVersion=%~1"
SET "VsVersionMin=%~2"
SET "VsVersionMax=%~3"
REM ref: https://github.com/Microsoft/vswhere/wiki/Start-Developer-Command-Prompt
IF NOT EXIST %VsWherePath% (
ECHO Could not find vswhere.exe
EXIT /B 2
)
SET VsWhereCmdLine="!VsWherePath! -nologo -latest -version [%VsVersionMin%,%VsVersionMax%) -property installationPath"
FOR /F "usebackq delims=" %%i in (`!VsWhereCmdLine!`) DO (
IF EXIST "%%i\VC\Auxiliary\Build\vcvars64.bat" (
CALL "%%i\VC\Auxiliary\Build\vcvars64.bat" && nmake MSDEV="%PremakeVsVersion%" %PlatformArg% %ConfigArg% -f Bootstrap.mak windows
EXIT /B %ERRORLEVEL%
) ELSE (
IF EXIST "%%i\VC\Auxiliary\Build\vcvars32.bat" (
CALL "%%i\VC\Auxiliary\Build\vcvars32.bat" && nmake MSDEV="%PremakeVsVersion%" %PlatformArg% %ConfigArg% -f Bootstrap.mak windows
EXIT /B %ERRORLEVEL%
)
)
)
ECHO Could not find vcvars64.bat or vcvars32.bat to setup Visual Studio environment
EXIT /B 2
REM :VsWhereVisualBootstrap
REM ===========================================================================
:BootstrapLatest
IF EXIST %VsWherePath% (
REM First try for not legacy Visual Studios ( >vs2017 )
SET VsWhereCmdLine="!VsWherePath! -nologo -latest -property catalog.productLineVersion"
FOR /F "usebackq delims=" %%i in (`!VsWhereCmdLine!`) DO (
CALL %SelfPath% vs%%i
EXIT /B %ERRORLEVEL%
)
)
SET LegacyVSVersions=
REM Get latest Visual Studio legacy version
REM For all env var starting with VS
FOR /F "usebackq delims==" %%i in (`SET VS`) DO (
REM Check if env var match pattern VS*COMNTOOLS (ie: VS140COMNTOOLS)
ECHO "%%i" | FINDSTR /R /C:VS.*COMNTOOLS >nul && (
SET "LegacyVSVersions=%%i"
)
)
REM Strip VS
SET LegacyVSVersions=%LegacyVSVersions:VS=%
REM Strip COMNTOOLS
SET LegacyVSVersions=%LegacyVSVersions:COMNTOOLS=%
SET "VsVersionMap=140-vs2015;120-vs2013;110-vs2012;100-vs2010"
CALL SET PremakeVsVersion=%%VsVersionMap:*%LegacyVSVersions%-=%%
SET PremakeVsVersion=%PremakeVsVersion:;=&REM.%
IF NOT "%PremakeVsVersion%" == "" (
CALL %SelfPath% %PremakeVsVersion%
EXIT /B %ERRORLEVEL%
)
ECHO Could not find a Visual Studio installation
EXIT /B 2
REM :BootstrapLatest
REM ===========================================================================
REM SETLOCAL ENABLEDELAYEDEXPANSION
ENDLOCAL
REM SETLOCAL
ENDLOCAL