11@ echo OFF
2- setlocal enabledelayedexpansion
2+ setlocal
33
44REM Defined cript variables
55set NASMDL = http://www.nasm.us/pub/nasm/releasebuilds
@@ -12,7 +12,14 @@ set CALLDIR=%CD%
1212set SCRIPTDIR = %~dp0
1313
1414REM Initialise error check value
15- SET ERROR = 0
15+ set ERROR = 0
16+ REM Check if being called from another instance
17+ if not " %~1 " == " " (
18+ set MSVC_VER = %~1
19+ set VSINSTANCEDIR = %2
20+ set ISINSTANCE = 1
21+ goto MSVCCALL
22+ )
1623
1724REM Check what architecture we are installing on
1825if " %PROCESSOR_ARCHITECTURE% " == " AMD64" (
@@ -71,110 +78,167 @@ if not exist "%SCRIPTDIR%\vswhere.exe" (
7178:VSwhereDetection
7279REM Use vswhere to list detected installs
7380for /f " usebackq tokens=1* delims=: " %%i in (`vswhere -prerelease -requires Microsoft.Component.MSBuild`) do (
74- if /i " %%i " == " installationPath" set VSINSTALLDIR = %%j
75- )
76- if not " !VSINSTALLDIR! " == " " (
77- for /f " delims=" %%a in ('echo !VSINSTALLDIR! ^ | find " 2019" ') do ( set VCVER = %%a )
78- if not " !VCVER! " == " " (
79- echo Visual Studio 2019 environment detected...
80- set MSVC_VER = 16
81- )
82- set VCVER =
83- for /f " delims=" %%a in ('echo !VSINSTALLDIR! ^ | find " 2017" ') do ( set VCVER = %%a )
84- if not " !VCVER! " == " " (
85- echo Visual Studio 2017 environment detected...
86- set MSVC_VER = 15
81+ if /i " %%i " == " installationPath" (
82+ for /f " delims=" %%a in ('echo %%j ^ | find " 2019" ') do (
83+ if not " %%a " == " " (
84+ echo Visual Studio 2019 environment detected...
85+ call " %~0 " " 16" " %%j "
86+ if not ERRORLEVEL 1 (
87+ set MSVC16 = 1
88+ set MSVCFOUND = 1
89+ )
90+ )
91+ )
92+ for /f " delims=" %%a in ('echo %%j ^ | find " 2017" ') do (
93+ if not " %%a " == " " (
94+ echo Visual Studio 2017 environment detected...
95+ call " %~0 " " 15" " %%j "
96+ if not ERRORLEVEL 1 (
97+ set MSVC15 = 1
98+ set MSVCFOUND = 1
99+ )
100+ )
101+ )
87102 )
88- call " !VSINSTALLDIR! \VC\Auxiliary\Build\vcvars%SYSARCH% .bat" > nul 2 >& 1
89- goto MSVCVarsDone
90103)
91104
92105REM Try and use vswhere to detect legacy installs
106+ for /f " usebackq tokens=1* delims=: " %%i in (`vswhere -legacy`) do (
107+ if /i " %%i " == " installationPath" (
108+ for /f " delims=" %%a in ('echo %%j ^ | find " 2015" ') do (
109+ if not " %%a " == " " (
110+ echo Visual Studio 2015 environment detected...
111+ call " %~0 " " 13" " %%j "
112+ if not ERRORLEVEL 1 (
113+ set MSVC13 = 1
114+ set MSVCFOUND = 1
115+ )
116+ )
117+ )
118+ for /f " delims=" %%a in ('echo %%j ^ | find " 2013" ') do (
119+ if not " %%a " == " " (
120+ echo Visual Studio 2013 environment detected...
121+ call " %~0 " " 12" " %%j "
122+ if not ERRORLEVEL 1 (
123+ set MSVC12 = 1
124+ set MSVCFOUND = 1
125+ )
126+ )
127+ )
128+ )
129+ )
130+ if not defined MSVCFOUND (
131+ echo Error: Failed to detect VS installations using vswhere!
132+ echo Now trying fallback detection...
133+ ) else (
134+ goto Exit
135+ )
136+
137+ :MSVCRegDetection
93138if " %SYSARCH% " == " 32" (
94139 set MSVCVARSDIR =
140+ set WOWNODE =
95141) else if " %SYSARCH% " == " 64" (
96142 set MSVCVARSDIR = \amd64
143+ set WOWNODE = \WOW6432Node
97144) else (
98145 goto Terminate
99146)
100- for /f " usebackq tokens=1* delims=: " %%i in (`vswhere -legacy`) do (
101- if /i " %%i " == " installationPath" set VSINSTALLDIR = %%j
102- )
103- if not " !VSINSTALLDIR! " == " " (
104- for /f " delims=" %%a in ('echo !VSINSTALLDIR! ^ | find " 2015" ') do ( set VCVER = %%a )
105- if not " !VCVER! " == " " (
106- echo Visual Studio 2015 environment detected...
107- set MSVC_VER = 13
108- )
109- set VCVER =
110- for /f " delims=" %%a in ('echo !VSINSTALLDIR! ^ | find " 2013" ') do ( set VCVER = %%a )
111- if not " !VCVER! " == " " (
112- echo Visual Studio 2013 environment detected...
113- set MSVC_VER = 12
114- )
115- call " !VSINSTALLDIR! \VC\bin%MSVCVARSDIR% \vcvars%SYSARCH% .bat" > nul 2 >& 1
116- goto MSVCVarsDone
117- ) else (
118- echo Error: Failed to detect VS installations using vswhere!
119- echo Now trying fallback detection..."
120- )
121-
122- :MSVCRegDetection
123147REM First check for a environment variable to help locate the VS installation
124148if defined VS140COMNTOOLS (
125- if exist " %VS140COMNTOOLS% \..\..\VC\vcvarsall .bat" (
149+ if exist " %VS140COMNTOOLS% \..\..\VC\bin %MSVCVARSDIR% \vcvars %SYSARCH% .bat" (
126150 echo Visual Studio 2015 environment detected...
127- call " %VS140COMNTOOLS% \..\..\VC\vcvarsall.bat" > nul 2 >& 1
128- set MSVC_VER = 14
129- goto MSVCVarsDone
151+ call " %~0 " " 14" " %VS140COMNTOOLS% \..\..\"
152+ if not ERRORLEVEL 1 (
153+ set MSVC14 = 1
154+ set MSVCFOUND = 1
155+ )
130156 )
131157)
132158if defined VS120COMNTOOLS (
133- if exist " %VS120COMNTOOLS% \..\..\VC\vcvarsall .bat" (
159+ if exist " %VS120COMNTOOLS% \..\..\VC\bin %MSVCVARSDIR% \vcvars %SYSARCH% .bat" (
134160 echo Visual Studio 2013 environment detected...
135- call " %VS120COMNTOOLS% \..\..\VC\vcvarsall.bat" > nul 2 >& 1
136- set MSVC_VER = 12
137- goto MSVCVarsDone
161+ call " %~0 " " 12" " %VS120COMNTOOLS% \..\..\"
162+ if not ERRORLEVEL 1 (
163+ set MSVC12 = 1
164+ set MSVCFOUND = 1
165+ )
138166 )
139167)
140168
141169REM Check for default install locations based on current system architecture
170+ if not defined MSVC15 (
171+ reg.exe query " HKLM\SOFTWARE%WOWNODE% \Microsoft\VisualStudio\SxS\VS7" /v 15.0 > nul 2 >& 1
172+ if not ERRORLEVEL 1 (
173+ echo Visual Studio 2017 installation detected...
174+ for /f " skip=2 tokens=2,*" %%i in ('reg.exe query " HKLM\SOFTWARE%WOWNODE% \Microsoft\VisualStudio\SxS\VS7" /v 15.0') do (
175+ call " %~0 " " 15" " %%j "
176+ if not ERRORLEVEL 1 (
177+ set MSVC15 = 1
178+ set MSVCFOUND = 1
179+ )
180+ )
181+ )
182+ )
183+ if not defined MSVC14 (
184+ reg.exe query " HKLM\Software%WOWNODE% \Microsoft\VisualStudio\14.0" /v " InstallDir" > nul 2 >& 1
185+ if not ERRORLEVEL 1 (
186+ echo Visual Studio 2015 installation detected...
187+ for /f " skip=2 tokens=2,*" %%i in ('reg.exe query " HKLM\Software%WOWNODE% \Microsoft\VisualStudio\14.0" /v " InstallDir" ') do (
188+ call " %~0 " " 14" " %%j "
189+ if not ERRORLEVEL 1 (
190+ set MSVC14 = 1
191+ set MSVCFOUND = 1
192+ )
193+ )
194+ )
195+ )
196+ if not defined MSVC12 (
197+ reg.exe query " HKLM\Software%WOWNODE% \Microsoft\VisualStudio\12.0" /v " InstallDir" > nul 2 >& 1
198+ if not ERRORLEVEL 1 (
199+ echo Visual Studio 2013 installation detected...
200+ for /f " skip=2 tokens=2,*" %%i in ('reg.exe query " HKLM\Software%WOWNODE% \Microsoft\VisualStudio\12.0" /v " InstallDir" ') do (
201+ call " %~0 " " 12" " %%j "
202+ if not ERRORLEVEL 1 (
203+ set MSVC12 = 1
204+ set MSVCFOUND = 1
205+ )
206+ )
207+ )
208+ )
209+ if not defined MSVCFOUND (
210+ echo Error: Could not find valid Visual Studio installation!
211+ goto Terminate
212+ )
213+ goto Exit
214+
215+ :MSVCCALL
142216if " %SYSARCH% " == " 32" (
143217 set MSVCVARSDIR =
144- set WOWNODE =
145218) else if " %SYSARCH% " == " 64" (
146219 set MSVCVARSDIR = \amd64
147- set WOWNODE = \WOW6432Node
148220) else (
149221 goto Terminate
150222)
151-
152- reg.exe query " HKLM\SOFTWARE%WOWNODE% \Microsoft\VisualStudio\SxS\VS7" /v 15.0 > nul 2 >& 1
153- if not ERRORLEVEL 1 (
154- echo Visual Studio 2017 installation detected...
155- 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 )
156- call " !VSINSTALLDIR! VC\Auxiliary\Build\vcvars%SYSARCH% .bat" > nul 2 >& 1
157- set MSVC_VER = 15
158- goto MSVCVarsDone
159- )
160- reg.exe query " HKLM\Software%WOWNODE% \Microsoft\VisualStudio\14.0" /v " InstallDir" > nul 2 >& 1
161- if not ERRORLEVEL 1 (
162- echo Visual Studio 2015 installation detected...
163- for /f " skip=2 tokens=2,*" %%a in ('reg.exe query " HKLM\Software%WOWNODE% \Microsoft\VisualStudio\14.0" /v " InstallDir" ') do (set VSINSTALLDIR=%%b )
164- call " !VSINSTALLDIR! \VC\bin%MSVCVARSDIR% \vcvars%SYSARCH% .bat" > nul 2 >& 1
165- set MSVC_VER = 14
166- goto MSVCVarsDone
223+ REM Call the required vcvars file in order to setup up build locations
224+ if " %MSVC_VER% " == " 16" (
225+ set VCVARS = %VSINSTANCEDIR% \VC\Auxiliary\Build\vcvars%SYSARCH% .bat
226+ ) else if " %MSVC_VER% " == " 15" (
227+ set VCVARS = %VSINSTANCEDIR% \VC\Auxiliary\Build\vcvars%SYSARCH% .bat
228+ ) else if " %MSVC_VER% " == " 14" (
229+ set VCVARS = %VSINSTANCEDIR% \VC\bin%MSVCVARSDIR% \vcvars%SYSARCH% .bat
230+ ) else if " %MSVC_VER% " == " 12" (
231+ set VCVARS = %VSINSTANCEDIR% \VC\bin%MSVCVARSDIR% \vcvars%SYSARCH% .bat
232+ ) else (
233+ echo Error: Invalid MSVC version!
234+ goto Terminate
167235)
168- reg.exe query " HKLM\Software%WOWNODE% \Microsoft\VisualStudio\12.0" /v " InstallDir" > nul 2 >& 1
169- if not ERRORLEVEL 1 (
170- echo Visual Studio 2013 installation detected...
171- for /f " skip=2 tokens=2,*" %%a in ('reg.exe query " HKLM\Software%WOWNODE% \Microsoft\VisualStudio\12.0" /v " InstallDir" ') do (set VSINSTALLDIR=%%b )
172- call " !VSINSTALLDIR! \VC\bin%MSVCVARSDIR% \vcvars%SYSARCH% .bat" > nul 2 >& 1
173- set MSVC_VER = 12
174- goto MSVCVarsDone
236+ if exist %VCVARS% (
237+ call %VCVARS% > nul 2 >& 1
238+ ) else (
239+ echo Error: Invalid VS install location detected!
240+ goto Terminate
175241)
176- echo Error: Could not find valid Visual Studio installation!
177- goto Terminate
178242
179243:MSVCVarsDone
180244REM Get the location of the current msbuild
@@ -188,14 +252,14 @@ if not ERRORLEVEL 1 (
188252set /p MSBUILDDIR = < " %SCRIPTDIR% \msbuild.txt"
189253del /F /Q " %SCRIPTDIR% \msbuild.txt" > nul 2 >& 1
190254if " %MSVC_VER% " == " 16" (
191- set VCTargetsPath = " ..\..\..\Common7\IDE\ VC\VCTargets "
255+ set VCTargetsPath = " ..\..\Microsoft\ VC\v160\BuildCustomizations "
192256) else if " %MSVC_VER% " == " 15" (
193- set VCTargetsPath = " ..\..\..\Common7\IDE\VC\VCTargets"
257+ set VCTargetsPath = " ..\..\..\Common7\IDE\VC\VCTargets\BuildCustomizations "
194258) else (
195259 if " %MSBUILDDIR% " == " %MSBUILDDIR:amd64 =% " (
196- set VCTargetsPath = " ..\..\Microsoft.Cpp\v4.0\V%MSVC_VER% 0"
260+ set VCTargetsPath = " ..\..\Microsoft.Cpp\v4.0\V%MSVC_VER% 0\BuildCustomizations "
197261 ) else (
198- set VCTargetsPath = " ..\..\..\Microsoft.Cpp\v4.0\V%MSVC_VER% 0"
262+ set VCTargetsPath = " ..\..\..\Microsoft.Cpp\v4.0\V%MSVC_VER% 0\BuildCustomizations "
199263 )
200264)
201265
@@ -213,8 +277,8 @@ if not "%CURRDIR%"=="%CD%" (
213277
214278REM copy the BuildCustomizations to VCTargets folder
215279echo Installing build customisations...
216- del /F /Q " %VCTargetsPath% \BuildCustomizations\ nasm.*" > nul 2 >& 1
217- copy /B /Y /V " %SCRIPTDIR% \nasm.*" " %VCTargetsPath% \BuildCustomizations\ " > nul 2 >& 1
280+ del /F /Q " %VCTargetsPath% \nasm.*" > nul 2 >& 1
281+ copy /B /Y /V " %SCRIPTDIR% \nasm.*" " %VCTargetsPath% \" > nul 2 >& 1
218282if %ERRORLEVEL% neq 0 (
219283 echo Error: Failed to copy build customisations!
220284 echo Ensure that this script is run in a shell with the necessary write privileges
@@ -257,11 +321,13 @@ echo Finished Successfully
257321goto Exit
258322
259323:Terminate
260- SET ERROR = 1
324+ set ERROR = 1
261325
262326:Exit
263327cd %CALLDIR%
264- IF " %APPVEYOR% " == " " (
265- pause
328+ if " %APPVEYOR% " == " " (
329+ if not defined ISINSTANCE (
330+ pause
331+ )
266332)
267- exit /b %ERROR%
333+ endlocal & exit /b %ERROR%
0 commit comments