-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathvstools.cmd
148 lines (116 loc) · 3.66 KB
/
vstools.cmd
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
@if defined TRACEON (@echo on) else (@echo off)
REM If this batch file works, then it was written by Fish.
REM If it doesn't then I don't know who the heck wrote it.
setlocal
set "TRACE=if defined DEBUG echo"
goto :BEGIN
::-----------------------------------------------------------------------------
:: VSTOOLS.CMD
::-----------------------------------------------------------------------------
:HELP
echo.
echo NAME
echo.
echo %~n0 -- Initialize Visual Studio build environment
echo.
echo SYNOPSIS
echo.
echo %~nx0 { 32 ^| 64 }
echo.
echo ARGUMENTS
echo.
echo 32 ^| 64 Defines the desired target architecture.
echo.
echo OPTIONS
echo.
echo (NONE)
echo.
echo NOTES
echo.
echo Some flavor of Visual Studio must obviously be installed.
echo Supported versions are Visual Studio 2005 through 2015.
echo.
echo EXIT STATUS
echo.
echo 0 Success
echo 1 Error
echo.
echo AUTHOR
echo.
echo "Fish" (David B. Trout)
echo.
echo VERSION
echo.
echo 1.0 (June 13, 2016)
endlocal && exit /b 1
::-----------------------------------------------------------------------------
:: BEGIN
::-----------------------------------------------------------------------------
:BEGIN
if /i "%~1" == "" goto :HELP
if /i "%~1" == "?" goto :HELP
if /i "%~1" == "/?" goto :HELP
if /i "%~1" == "-?" goto :HELP
if /i "%~1" == "--help" goto :HELP
if not "%~1" == "32" (
if not "%~1" == "64" (
goto :HELP
) else (
set "vstarget=amd64"
)
) else (
set "vstarget=x86"
)
set "VSVERSIONS=140 120 110 100 90 80"
set "VSTOOLSDIR="
:VSTOOLSDIR_loop
for /f "tokens=1*" %%a in ("%VSVERSIONS%") do (
call :try_VSTOOLSDIR "%%a"
if defined VSTOOLSDIR goto :got_VSTOOLSDIR
if "%%b" == "" goto :VSTOOLSDIR_error
set "VSVERSIONS=%%b"
goto :VSTOOLSDIR_loop
)
:try_VSTOOLSDIR
set "nnn=%~1"
setlocal enabledelayedexpansion
if not "!VS%nnn%COMNTOOLS!" == "" (
if exist "!VS%nnn%COMNTOOLS!..\..\VC\vcvarsall.bat" (
set "VSTOOLSDIR=!VS%nnn%COMNTOOLS!"
)
)
endlocal && set "VSTOOLSDIR=%VSTOOLSDIR%"
goto :EOF
:got_VSTOOLSDIR
if /i "%PROCESSOR_ARCHITECTURE%" == "x86" set "vshost=x86"
if /i "%PROCESSOR_ARCHITECTURE%" == "AMD64" set "vshost=amd64"
:: Since Microsoft doesn't have an X64 build of their compiler,
:: if targeting x86 we must use their x86 compiler under WOW64.
:: This is called cross compiling.
if /i "%vstarget%" == "x86" set "vshost=x86"
if /i not "%vshost%" == "%vstarget%" goto :cross_compile
:: Host architecture matches target architecture
set "vshost="
if not exist "%VSTOOLSDIR%..\..\VC\bin\vcvars32.bat" (
goto :targ_arch_error
)
goto :set_VSTOOLS
:cross_compile
:: Targeting x86 but running under x64! (WOW64)
set "vshost=x86_" && REM (even though our ACTUAL host arch is x64!)
if not exist "%VSTOOLSDIR%..\..\VC\bin\%vshost%%vstarget%\vcvars%vshost%%vstarget%.bat" (
goto :targ_arch_error
)
:set_VSTOOLS
endlocal && set "VSTOOLSDIR=%VSTOOLSDIR%" && set "vshost=%vshost%" && set "vstarget=%vstarget%"
call "%VSTOOLSDIR%..\..\VC\vcvarsall.bat" %vshost%%vstarget%
exit /b 0
:VSTOOLSDIR_error
echo %~nx0: ERROR: No supported version of Visual Studio is installed
endlocal
exit /b 1
:targ_arch_error
echo %~nx0: ERROR: Build support for target architecture %vstarget% is not installed
endlocal
exit /b 1
::-----------------------------------------------------------------------------