-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.bat
More file actions
158 lines (120 loc) · 3.67 KB
/
build.bat
File metadata and controls
158 lines (120 loc) · 3.67 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
@echo off
setlocal EnableDelayedExpansion
set BOF_FLAGS=/nologo /O1 /Os /Oi /GS- /Zc:inline /permissive- /W3 /Gy- /GF- /D _NO_CRT_STDIO_INLINE /D _CRT_SECURE_NO_WARNINGS /D BOF
if not exist "bin" mkdir "bin"
call :SETUP_ENV
call :SET_ENV MSVC_X86
cl /c src\mybof.cc %BOF_FLAGS% /Fo"bin\mybof.x86.o"
cl /c src\mybof.cc %BOF_FLAGS% /D _DEBUG /Fo"bin\mybof.x86d.o"
call :SET_ENV MSVC_X64
cl /c src\mybof.cc %BOF_FLAGS% /Fo"bin\mybof.x64.o"
cl /c src\mybof.cc %BOF_FLAGS% /D _DEBUG /Fo"bin\mybof.x64d.o"
cl /nologo /O2 /std:c++20 /EHsc tools\fixbof.cc tools\obj.cc /Fe"tools\fixbof.exe"
tools\fixbof.exe cs4.7 tools\link ^
bin\mybof.x86.o bin\mybof.x86d.o bin\mybof.x64.o bin\mybof.x64d.o
del fixbof.obj obj.obj tools\fixbof.exe
copy /Y src\mybof.cna bin\mybof.cna
endlocal
exit /b 0
:: SETUP_ENV Function - Initializes environment variables for x86 and x64 builds
:: Usage: CALL :SETUP_ENV
:SETUP_ENV
rem Save the current environment variables
call :SAVE_ENV BASE
rem Initialize x86 environments
call :VCVARSALL x86
if errorlevel 1 echo Failed to initialize x86 environment. & exit /b 1
call :SAVE_ENV MSVC_X86
rem Initialize x64 environments
call :VCVARSALL x64
if errorlevel 1 echo Failed to initialize x64 environment. & exit /b 1
call :SAVE_ENV MSVC_X64
rem Restore the original environment variables
call :SET_ENV BASE
goto :EOF
:: SAVE_ENV Function - Backs up current environment variables with a specified name prefix
:: Usage: CALL :SAVE_ENV MyBackup
:SAVE_ENV
if "%~1"=="" (
echo Please provide a backup name.
goto :EOF
)
for /f "tokens=1,* delims==" %%A in ('set') do (
rem Check if the variable already starts with __ENV_, skip if true
set "T=%%A"
if /i "!T:~0,6!" neq "__ENV_" (
set "__ENV_%~1_%%A=%%B"
)
)
set T=
goto :EOF
:: SET_ENV Function - Clears non-__ENV_ variables, then restores from the specified name prefix
:: Usage: CALL :SET_ENV MyBackup
:SET_ENV
if "%~1"=="" (
echo Please provide a backup name.
goto :EOF
)
:: Step 1: Clear all non-__ENV_ variables
for /f "tokens=1,* delims==" %%A in ('set') do (
set "T=%%A"
if /i "!T:~0,6!" neq "__ENV_" (
set "%%A="
)
)
set T=
:: Step 2: Restore variables with the specified prefix
set "P=__ENV_%~1_"
for /f "tokens=1,* delims==" %%A in ('set %P%') do (
set "N=%%A"
set "V=%%B"
rem Extract original variable name by removing prefix
set "N=!N:%P%=!"
rem Restore the environment variable
set "!N!=!V!"
)
set P=
set N=
set V=
goto :EOF
@REM Copied from https://github.com/dotnet/runtime/blob/v8.0.0/src/coreclr/nativeaot/BuildIntegration/findvcvarsall.bat
:VCVARSALL
IF "%~1"=="" (
ECHO Usage: VCVARSALL ^<arch^>
EXIT /B 1
)
SET vswherePath=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
IF NOT EXIST "%vswherePath%" (
ECHO vswhere.exe not found.
EXIT /B 1
)
SET toolsSuffix=x86.x64
IF /I "%~1"=="arm64" SET toolsSuffix=ARM64
FOR /F "tokens=*" %%i IN (
'"%vswherePath%" -latest -prerelease -products * ^
-requires Microsoft.VisualStudio.Component.VC.Tools.%toolsSuffix% ^
-version [16^,18^) ^
-property installationPath'
) DO SET vsBase=%%i
IF "%vsBase%"=="" (
ECHO Visual Studio not found.
EXIT /B 1
)
SET procArch=%PROCESSOR_ARCHITEW6432%
IF "%procArch%"=="" SET procArch=%PROCESSOR_ARCHITECTURE%
SET vcEnvironment=%~1
IF /I "%~1"=="x64" (
SET vcEnvironment=x86_amd64
IF /I "%procArch%"=="AMD64" SET vcEnvironment=amd64
)
IF /I "%~1"=="arm64" (
SET vcEnvironment=x86_arm64
IF /I "%procArch%"=="AMD64" SET vcEnvironment=amd64_arm64
)
CALL "%vsBase%\vc\Auxiliary\Build\vcvarsall.bat" %vcEnvironment% > NUL
IF "%LIB%"=="" (
ECHO Failed to initialize VC environment.
EXIT /B 1
)
EXIT /B 0
GOTO :EOF