summaryrefslogtreecommitdiffstats
path: root/BaseTools/set_vsprefix_envs.bat
blob: df2c771951c30ac54a8e83bff65a1af7457aac5a (plain)
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
@REM @file
@REM   This stand-alone program is typically called by the toolsetup.bat file,
@REM   however it may be executed directly from the BaseTools project folder
@REM   if the file is not executed within a WORKSPACE\BaseTools folder.
@REM
@REM Copyright (c) 2016-2020, Intel Corporation. All rights reserved.<BR>
@REM
@REM SPDX-License-Identifier: BSD-2-Clause-Patent
@REM

@echo off
pushd .
set SCRIPT_ERROR=0
goto main

:ToolNotInstall
set SCRIPT_ERROR=1
goto :EOF

:main
if /I "%1"=="VS2022" goto SetVS2022
if /I "%1"=="VS2019" goto SetVS2019
if /I "%1"=="VS2017" goto SetVS2017
if /I "%1"=="VS2015" goto SetVS2015

if defined VS71COMNTOOLS (
  if not defined VS2003_PREFIX (
    set "VS2003_PREFIX=%VS71COMNTOOLS:~0,-14%"
  )
)

:SetVS2015
if defined VS140COMNTOOLS (
  if not defined VS2015_PREFIX (
    set "VS2015_PREFIX=%VS140COMNTOOLS:~0,-14%"
  )
  if not defined WINSDK81_PREFIX (
    if exist "%ProgramFiles%\Windows Kits\8.1\bin" (
      set "WINSDK81_PREFIX=%ProgramFiles%\Windows Kits\8.1\bin\"
    ) else if exist "%ProgramFiles(x86)%\Windows Kits\8.1\bin" (
      set "WINSDK81_PREFIX=%ProgramFiles(x86)%\Windows Kits\8.1\bin\"
    )
  )
  if not defined WINSDK81x86_PREFIX (
    if exist "%ProgramFiles(x86)%\Windows Kits\8.1\bin" (
      set "WINSDK81x86_PREFIX=%ProgramFiles(x86)%\Windows Kits\8.1\bin\"
    ) else if exist "%ProgramFiles%\Windows Kits\8.1\bin" (
      set "WINSDK81x86_PREFIX=%ProgramFiles%\Windows Kits\8.1\bin\"
    )
  )
) else (
  if /I "%1"=="VS2015" goto ToolNotInstall
)
if /I "%1"=="VS2015" goto SetWinDDK

:SetVS2017
if not defined VS150COMNTOOLS (
  @REM clear two envs so that vcvars32.bat can run successfully.
  set VSINSTALLDIR=
  set VCToolsVersion=
  if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
    if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools" (
      call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -version 15,16 > vswhereInfo
      for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do (
        if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat"
      )
      del vswhereInfo
    ) else (
      call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version 15,16 > vswhereInfo
      for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do (
        if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat"
      )
      del vswhereInfo
    )
  ) else if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" (
    if exist "%ProgramFiles%\Microsoft Visual Studio\2017\BuildTools" (
      call "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -version 15,16 > vswhereInfo
      for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do (
        if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat"
      )
      del vswhereInfo
    ) else (
      call "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -version 15,16 > vswhereInfo
      for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do (
        if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat"
      )
      del vswhereInfo
    )
  ) else (
    if /I "%1"=="VS2017" goto ToolNotInstall
    goto SetWinDDK
  )
)

if defined VCToolsInstallDir (
  if not defined VS2017_PREFIX (
    set "VS2017_PREFIX=%VCToolsInstallDir%"
  )
  if not defined WINSDK10_PREFIX (
    if defined WindowsSdkVerBinPath (
      set "WINSDK10_PREFIX=%WindowsSdkVerBinPath%"
    ) else if exist "%ProgramFiles(x86)%\Windows Kits\10\bin" (
      set "WINSDK10_PREFIX=%ProgramFiles(x86)%\Windows Kits\10\bin\"
    ) else if exist "%ProgramFiles%\Windows Kits\10\bin" (
      set "WINSDK10_PREFIX=%ProgramFiles%\Windows Kits\10\bin\"
    )
  )
)
if not defined WINSDK_PATH_FOR_RC_EXE (
  if defined WINSDK10_PREFIX (
    set "WINSDK_PATH_FOR_RC_EXE=%WINSDK10_PREFIX%x86"
  )
)

if /I "%1"=="VS2017" goto SetWinDDK

:SetVS2019
if not defined VS160COMNTOOLS (
  @REM clear two envs so that vcvars32.bat can run successfully.
  set VSINSTALLDIR=
  set VCToolsVersion=
  if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
    if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools" (
      call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -version 16,17 > vswhereInfo
      for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do (
        if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat"
      )
      del vswhereInfo
    ) else (
      call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version 16,17 > vswhereInfo
      for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do (
        if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat"
      )
      del vswhereInfo
    )
  ) else if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" (
    if exist "%ProgramFiles%\Microsoft Visual Studio\2019\BuildTools" (
      call "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -version 16,17 > vswhereInfo
      for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do (
        if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat"
      )
      del vswhereInfo
    ) else (
      call "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -version 16,17 > vswhereInfo
      for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do (
        if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat"
      )
      del vswhereInfo
    )
  ) else (
    if /I "%1"=="VS2019" goto ToolNotInstall
    goto SetWinDDK
  )
)

if defined VCToolsInstallDir (
  if not defined VS2019_PREFIX (
    set "VS2019_PREFIX=%VCToolsInstallDir%"
  )
  if not defined WINSDK10_PREFIX (
    if defined WindowsSdkVerBinPath (
      set "WINSDK10_PREFIX=%WindowsSdkVerBinPath%"
    ) else if exist "%ProgramFiles(x86)%\Windows Kits\10\bin" (
      set "WINSDK10_PREFIX=%ProgramFiles(x86)%\Windows Kits\10\bin\"
    ) else if exist "%ProgramFiles%\Windows Kits\10\bin" (
      set "WINSDK10_PREFIX=%ProgramFiles%\Windows Kits\10\bin\"
    )
  )
)
if not defined WINSDK_PATH_FOR_RC_EXE (
  if defined WINSDK10_PREFIX (
    set "WINSDK_PATH_FOR_RC_EXE=%WINSDK10_PREFIX%x86"
  )
)

if /I "%1"=="VS2019" goto SetWinDDK

:SetVS2022
if not defined VS170COMNTOOLS (
  @REM clear two envs so that vcvars32.bat can run successfully.
  set VSINSTALLDIR=
  set VCToolsVersion=
  if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
    if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" (
      call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -version 17,18 > vswhereInfo
      for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do (
        if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat"
      )
      del vswhereInfo
    ) else (
      call "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version 17,18 > vswhereInfo
      for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do (
        if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat"
      )
      del vswhereInfo
    )
  ) else if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" (
    if exist "%ProgramFiles%\Microsoft Visual Studio\2022\BuildTools" (
      call "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -products Microsoft.VisualStudio.Product.BuildTools -version 17,18 > vswhereInfo
      for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do (
        if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat"
      )
      del vswhereInfo
    ) else (
      call "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" -version 17,18 > vswhereInfo
      for /f "usebackq tokens=1* delims=: " %%i in (vswhereInfo) do (
        if /i "%%i"=="installationPath" call "%%j\VC\Auxiliary\Build\vcvars32.bat"
      )
      del vswhereInfo
    )
  ) else (
    if /I "%1"=="VS2022" goto ToolNotInstall
    goto SetWinDDK
  )
)

if defined VCToolsInstallDir (
  if not defined VS2022_PREFIX (
    set "VS2022_PREFIX=%VCToolsInstallDir%"
  )
  if not defined WINSDK10_PREFIX (
    if defined WindowsSdkVerBinPath (
      set "WINSDK10_PREFIX=%WindowsSdkVerBinPath%"
    ) else if exist "%ProgramFiles(x86)%\Windows Kits\10\bin" (
      set "WINSDK10_PREFIX=%ProgramFiles(x86)%\Windows Kits\10\bin\"
    ) else if exist "%ProgramFiles%\Windows Kits\10\bin" (
      set "WINSDK10_PREFIX=%ProgramFiles%\Windows Kits\10\bin\"
    )
  )
)
if not defined WINSDK_PATH_FOR_RC_EXE (
  if defined WINSDK10_PREFIX (
    set "WINSDK_PATH_FOR_RC_EXE=%WINSDK10_PREFIX%x86"
  )
)

if /I "%1"=="VS2022" goto SetWinDDK

:SetWinDDK
if not defined WINDDK3790_PREFIX (
  set WINDDK3790_PREFIX=C:\WINDDK\3790.1830\bin\
)

if not defined IASL_PREFIX (
  set IASL_PREFIX=C:\ASL\
)

popd