| 1 | @setlocal EnableDelayedExpansion EnableExtensions |
| 2 | |
| 3 | @IF NOT DEFINED VERBOSE_MAKE @echo off |
| 4 | |
| 5 | REM Option flags |
| 6 | set /a shift_counter=0 |
| 7 | set /a flag_local=0 |
| 8 | |
| 9 | REM Option variables |
| 10 | set compiler= |
| 11 | set subcmd= |
| 12 | set target=build |
| 13 | |
| 14 | set V_EXE=./v.exe |
| 15 | set V_BOOTSTRAP=./v_win_bootstrap.exe |
| 16 | set V_OLD=./v_old.exe |
| 17 | set V_UPDATED=./v_up.exe |
| 18 | set V_STAGE=./v_stage.exe |
| 19 | set V_C_FILE=./vc/v_win.c |
| 20 | REM Existing vc bootstraps may predate the TCC Win64 CRT prelude fix, so keep |
| 21 | REM their cgen single-threaded while they build a fresh compiler from sources. |
| 22 | REM TODO: remove this after vc/v_win.c is regenerated with the fixed CRT prelude. |
| 23 | set V_BOOTSTRAP_VFLAGS=-no-parallel |
| 24 | set where_exe=where.exe |
| 25 | if not ["%SystemRoot%"] == [""] if exist "%SystemRoot%\System32\where.exe" set where_exe=%SystemRoot%\System32\where.exe |
| 26 | |
| 27 | REM TCC variables |
| 28 | set tcc_url=https://github.com/vlang/tccbin |
| 29 | set tcc_dir=%~dp0thirdparty\tcc |
| 30 | set tcc_exe=%tcc_dir%\tcc.exe |
| 31 | if "%PROCESSOR_ARCHITECTURE%" == "x86" ( set tcc_branch="thirdparty-windows-i386" ) else ( set tcc_branch="thirdparty-windows-amd64" ) |
| 32 | if "%~1" == "-tcc32" set tcc_branch="thirdparty-windows-i386" |
| 33 | |
| 34 | REM VC settings |
| 35 | set vc_url=https://github.com/vlang/vc |
| 36 | set vc_dir=%~dp0vc |
| 37 | |
| 38 | REM Let a particular environment specify their own TCC and VC repos (to help mirrors) |
| 39 | if /I not ["%TCC_GIT%"] == [""] set tcc_url=%TCC_GIT% |
| 40 | if /I not ["%TCC_BRANCH%"] == [""] set tcc_branch=%TCC_BRANCH% |
| 41 | |
| 42 | if /I not ["%VC_GIT%"] == [""] set vc_url=%VC_GIT% |
| 43 | |
| 44 | pushd "%~dp0" |
| 45 | |
| 46 | :verifyopt |
| 47 | REM Read stdin EOF |
| 48 | if ["%~1"] == [""] goto :init |
| 49 | |
| 50 | REM Target options |
| 51 | if !shift_counter! LSS 1 ( |
| 52 | if "%~1" == "help" ( |
| 53 | if not ["%~2"] == [""] set subcmd=%~2& shift& set /a shift_counter+=1 |
| 54 | ) |
| 55 | for %%z in (build clean cleanall check help rebuild) do ( |
| 56 | if "%~1" == "%%z" set target=%1& shift& set /a shift_counter+=1& goto :verifyopt |
| 57 | ) |
| 58 | ) |
| 59 | |
| 60 | REM Compiler option |
| 61 | for %%g in (-gcc -msvc -tcc -tcc32 -clang) do ( |
| 62 | if "%~1" == "%%g" set compiler=%~1& set compiler=!compiler:~1!& shift& set /a shift_counter+=1& goto :verifyopt |
| 63 | ) |
| 64 | |
| 65 | REM Standard options |
| 66 | if "%~1" == "--local" ( |
| 67 | if !flag_local! NEQ 0 ( |
| 68 | echo The flag %~1 has already been specified. 1>&2 |
| 69 | exit /b 2 |
| 70 | ) |
| 71 | set /a flag_local=1 |
| 72 | set /a shift_counter+=1 |
| 73 | shift |
| 74 | goto :verifyopt |
| 75 | ) |
| 76 | |
| 77 | echo Undefined option: %~1 |
| 78 | exit /b 2 |
| 79 | |
| 80 | :init |
| 81 | goto :!target! |
| 82 | |
| 83 | :check |
| 84 | echo. |
| 85 | echo Check everything |
| 86 | "%V_EXE%" test-all |
| 87 | exit /b 0 |
| 88 | |
| 89 | :cleanall |
| 90 | call :clean |
| 91 | if !ERRORLEVEL! NEQ 0 exit /b !ERRORLEVEL! |
| 92 | echo. |
| 93 | echo Cleanup vc |
| 94 | echo ^> Purge TCC binaries |
| 95 | if exist "%tcc_dir%" ( |
| 96 | rmdir /s /q "%tcc_dir%" |
| 97 | if !ERRORLEVEL! NEQ 0 exit /b !ERRORLEVEL! |
| 98 | ) |
| 99 | echo ^> Purge vc repository |
| 100 | if exist "%vc_dir%" ( |
| 101 | rmdir /s /q "%vc_dir%" |
| 102 | if !ERRORLEVEL! NEQ 0 exit /b !ERRORLEVEL! |
| 103 | ) |
| 104 | exit /b 0 |
| 105 | |
| 106 | :clean |
| 107 | echo Cleanup build artifacts |
| 108 | echo ^> Purge debug symbols |
| 109 | del *.pdb *.lib *.bak *.out *.ilk *.exp *.obj *.o *.a *.so |
| 110 | |
| 111 | echo ^> Delete old V executable(s) |
| 112 | del v*.exe |
| 113 | exit /b 0 |
| 114 | |
| 115 | :rebuild |
| 116 | call :cleanall |
| 117 | if !ERRORLEVEL! NEQ 0 exit /b !ERRORLEVEL! |
| 118 | goto :build |
| 119 | |
| 120 | :help |
| 121 | if [!subcmd!] == [] ( |
| 122 | call :usage |
| 123 | ) else ( |
| 124 | call :help_!subcmd! |
| 125 | ) |
| 126 | if !ERRORLEVEL! NEQ 0 echo Invalid subcommand: !subcmd! |
| 127 | exit /b !ERRORLEVEL! |
| 128 | |
| 129 | :build |
| 130 | if !flag_local! NEQ 1 ( |
| 131 | call :download_tcc |
| 132 | if !ERRORLEVEL! NEQ 0 goto :error |
| 133 | if exist "%vc_dir%" ( |
| 134 | pushd "%vc_dir%" |
| 135 | if !ERRORLEVEL! NEQ 0 goto :error |
| 136 | echo Updating vc... |
| 137 | echo ^> Sync with remote !vc_url! |
| 138 | git pull --rebase --quiet |
| 139 | if !ERRORLEVEL! NEQ 0 ( |
| 140 | popd |
| 141 | goto :error |
| 142 | ) |
| 143 | popd |
| 144 | ) else ( |
| 145 | call :cloning_vc |
| 146 | if !ERRORLEVEL! NEQ 0 goto :error |
| 147 | ) |
| 148 | echo. |
| 149 | ) |
| 150 | |
| 151 | echo Building V... |
| 152 | if not [!compiler!] == [] goto :!compiler!_strap |
| 153 | |
| 154 | |
| 155 | REM By default, use tcc, since we have it prebuilt: |
| 156 | :tcc_strap |
| 157 | :tcc32_strap |
| 158 | call :build_bootstrap_with_tcc |
| 159 | if !ERRORLEVEL! NEQ 0 goto :compile_error |
| 160 | call :build_fresh_v_with_tcc |
| 161 | if !ERRORLEVEL! NEQ 0 goto :tcc_retry_with_host_bootstrap |
| 162 | call :move_updated_to_v |
| 163 | goto :success |
| 164 | |
| 165 | :tcc_retry_with_host_bootstrap |
| 166 | echo ^> TCC-built bootstrap failed; retrying bootstrap with Clang/GCC before compiling "%V_EXE%" with TCC |
| 167 | call :build_bootstrap_with_clang |
| 168 | if !ERRORLEVEL! NEQ 0 call :build_bootstrap_with_gcc |
| 169 | if !ERRORLEVEL! NEQ 0 ( |
| 170 | if [!compiler!] == [] goto :clang_strap |
| 171 | goto :compile_error |
| 172 | ) |
| 173 | call :build_fresh_v_with_tcc |
| 174 | if !ERRORLEVEL! NEQ 0 ( |
| 175 | if [!compiler!] == [] goto :clang_strap |
| 176 | goto :compile_error |
| 177 | ) |
| 178 | call :move_updated_to_v |
| 179 | goto :success |
| 180 | |
| 181 | :build_fresh_v_with_tcc |
| 182 | echo ^> Compiling "%V_STAGE%" with "%V_BOOTSTRAP%" |
| 183 | REM Keep the TCC root relative here; V forwards -cflags through a response file. |
| 184 | REM An absolute -B path breaks there when the checkout path contains spaces. |
| 185 | "%V_BOOTSTRAP%" %V_BOOTSTRAP_VFLAGS% -keepc -g -showcc -cc "!tcc_exe!" -cflags -Bthirdparty/tcc -o "%V_STAGE%" cmd/v |
| 186 | set stage_error=!ERRORLEVEL! |
| 187 | if !stage_error! NEQ 0 ( |
| 188 | if exist "%V_STAGE%" del "%V_STAGE%" |
| 189 | exit /b !stage_error! |
| 190 | ) |
| 191 | echo ^> Compiling "%V_EXE%" with "%V_STAGE%" |
| 192 | "%V_STAGE%" %V_BOOTSTRAP_VFLAGS% -keepc -g -showcc -cc "!tcc_exe!" -cflags -Bthirdparty/tcc -o "%V_UPDATED%" cmd/v |
| 193 | set stage_error=!ERRORLEVEL! |
| 194 | if exist "%V_STAGE%" del "%V_STAGE%" |
| 195 | exit /b !stage_error! |
| 196 | |
| 197 | :clang_strap |
| 198 | call :build_bootstrap_with_clang |
| 199 | if !ERRORLEVEL! NEQ 0 ( |
| 200 | if not [!compiler!] == [] goto :error |
| 201 | goto :gcc_strap |
| 202 | ) |
| 203 | |
| 204 | echo ^> Compiling "%V_EXE%" with "%V_BOOTSTRAP%" |
| 205 | "%V_BOOTSTRAP%" %V_BOOTSTRAP_VFLAGS% -keepc -g -showcc -cc clang -cflags "--target=!clang_target!" -o "%V_UPDATED%" cmd/v |
| 206 | if !ERRORLEVEL! NEQ 0 goto :compile_error |
| 207 | call :move_updated_to_v |
| 208 | goto :success |
| 209 | |
| 210 | :gcc_strap |
| 211 | call :build_bootstrap_with_gcc |
| 212 | if !ERRORLEVEL! NEQ 0 ( |
| 213 | if not [!compiler!] == [] goto :error |
| 214 | goto :msvc_strap |
| 215 | ) |
| 216 | |
| 217 | echo ^> Compiling "%V_EXE%" with "%V_BOOTSTRAP%" |
| 218 | "%V_BOOTSTRAP%" %V_BOOTSTRAP_VFLAGS% -keepc -g -showcc -cc "!gcc_exe!" -o "%V_UPDATED%" cmd/v |
| 219 | if !ERRORLEVEL! NEQ 0 goto :compile_error |
| 220 | call :move_updated_to_v |
| 221 | goto :success |
| 222 | |
| 223 | :msvc_strap |
| 224 | set VsWhereDir=%ProgramFiles(x86)% |
| 225 | set HostArch=x64 |
| 226 | if "%PROCESSOR_ARCHITECTURE%" == "x86" ( |
| 227 | echo Using x86 Build Tools... |
| 228 | set VsWhereDir=%ProgramFiles% |
| 229 | set HostArch=x86 |
| 230 | ) |
| 231 | |
| 232 | if not exist "%VsWhereDir%/Microsoft Visual Studio/Installer/vswhere.exe" ( |
| 233 | echo ^> MSVC not found |
| 234 | if not [!compiler!] == [] goto :error |
| 235 | goto :compile_error |
| 236 | ) |
| 237 | |
| 238 | for /f "usebackq tokens=*" %%i in (`"%VsWhereDir%/Microsoft Visual Studio/Installer/vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do ( |
| 239 | set InstallDir=%%i |
| 240 | ) |
| 241 | |
| 242 | if exist "%InstallDir%/Common7/Tools/vsdevcmd.bat" ( |
| 243 | call "%InstallDir%/Common7/Tools/vsdevcmd.bat" -arch=%HostArch% -host_arch=%HostArch% -no_logo |
| 244 | ) else if exist "%VsWhereDir%/Microsoft Visual Studio 14.0/Common7/Tools/vsdevcmd.bat" ( |
| 245 | call "%VsWhereDir%/Microsoft Visual Studio 14.0/Common7/Tools/vsdevcmd.bat" -arch=%HostArch% -host_arch=%HostArch% -no_logo |
| 246 | ) |
| 247 | |
| 248 | set ObjFile=.v.c.obj |
| 249 | |
| 250 | echo ^> Bootstrapping "%V_BOOTSTRAP%" before compiling "%V_EXE%" with MSVC |
| 251 | set stage_vflags= |
| 252 | call :build_bootstrap_with_clang |
| 253 | if !ERRORLEVEL! EQU 0 ( |
| 254 | set stage_vflags=-cc clang -cflags "--target=!clang_target!" |
| 255 | ) else ( |
| 256 | call :build_bootstrap_with_gcc |
| 257 | if !ERRORLEVEL! EQU 0 ( |
| 258 | set stage_vflags=-cc "!gcc_exe!" |
| 259 | ) else ( |
| 260 | call :build_bootstrap_with_tcc |
| 261 | if !ERRORLEVEL! EQU 0 set stage_vflags=-cc "!tcc_exe!" -cflags -Bthirdparty/tcc |
| 262 | ) |
| 263 | ) |
| 264 | if not defined stage_vflags ( |
| 265 | echo Could not build a bootstrap compiler before compiling with MSVC |
| 266 | if exist %ObjFile% del %ObjFile% |
| 267 | goto :compile_error |
| 268 | ) |
| 269 | |
| 270 | echo ^> Compiling "%V_STAGE%" with "%V_BOOTSTRAP%" |
| 271 | "%V_BOOTSTRAP%" %V_BOOTSTRAP_VFLAGS% -keepc -g -showcc !stage_vflags! -o "%V_STAGE%" cmd/v |
| 272 | if !ERRORLEVEL! NEQ 0 ( |
| 273 | if exist %ObjFile% del %ObjFile% |
| 274 | if exist "%V_STAGE%" del "%V_STAGE%" |
| 275 | goto :compile_error |
| 276 | ) |
| 277 | |
| 278 | echo ^> Compiling "%V_EXE%" with "%V_STAGE%" |
| 279 | "%V_STAGE%" %V_BOOTSTRAP_VFLAGS% -keepc -g -showcc -cc msvc -o "%V_UPDATED%" cmd/v |
| 280 | set msvc_error=!ERRORLEVEL! |
| 281 | if exist %ObjFile% del %ObjFile% |
| 282 | if exist "%V_STAGE%" del "%V_STAGE%" |
| 283 | if %msvc_error% NEQ 0 goto :compile_error |
| 284 | call :move_updated_to_v |
| 285 | goto :success |
| 286 | |
| 287 | :download_tcc |
| 288 | if exist "%tcc_dir%" ( |
| 289 | pushd "%tcc_dir%" |
| 290 | if !ERRORLEVEL! NEQ 0 exit /b !ERRORLEVEL! |
| 291 | echo Updating TCC |
| 292 | echo ^> Syncing TCC from !tcc_url! |
| 293 | if exist "lib\advapi32.def" git checkout -- lib\advapi32.def >nul 2>nul |
| 294 | git pull --rebase --quiet |
| 295 | if !ERRORLEVEL! NEQ 0 ( |
| 296 | set tcc_update_error=!ERRORLEVEL! |
| 297 | popd |
| 298 | exit /b !tcc_update_error! |
| 299 | ) |
| 300 | popd |
| 301 | ) else ( |
| 302 | call :bootstrap_tcc |
| 303 | if !ERRORLEVEL! NEQ 0 exit /b !ERRORLEVEL! |
| 304 | ) |
| 305 | |
| 306 | call :patch_tcc_defs |
| 307 | if !ERRORLEVEL! NEQ 0 goto :error |
| 308 | |
| 309 | if not exist "%tcc_exe%" echo ^> TCC not found, even after cloning& goto :error |
| 310 | echo. |
| 311 | exit /b 0 |
| 312 | |
| 313 | :patch_tcc_defs |
| 314 | set "advapi32_def=%tcc_dir%\lib\advapi32.def" |
| 315 | if not exist "%advapi32_def%" exit /b 0 |
| 316 | for %%G in (RegEnumKeyExW RegEnumValueW RegQueryInfoKeyW) do ( |
| 317 | findstr /x /c:"%%G" "%advapi32_def%" >nul || >>"%advapi32_def%" echo %%G |
| 318 | ) |
| 319 | exit /b 0 |
| 320 | |
| 321 | :compile_error |
| 322 | echo. |
| 323 | echo Backend compiler error |
| 324 | goto :error |
| 325 | |
| 326 | :error |
| 327 | echo. |
| 328 | echo Exiting from error |
| 329 | echo ERROR: please follow the instructions in https://github.com/vlang/v/wiki/Installing-a-C-compiler-on-Windows |
| 330 | exit /b 1 |
| 331 | |
| 332 | :success |
| 333 | "%V_EXE%" run cmd/tools/detect_tcc.v |
| 334 | echo ^> V built successfully! |
| 335 | echo ^> To add V to your PATH, run `%V_EXE% symlink`. |
| 336 | echo ^> Note: Antivirus programs may sometimes tell you there is a virus in V (there aren't any). They can also slow compilation by a considerable amount. Consider adding exemptions for the V install directory as well as your V project folders. |
| 337 | |
| 338 | :version |
| 339 | echo. |
| 340 | echo | set /p="V version: " |
| 341 | "%V_EXE%" version |
| 342 | "%V_EXE%" run .github/problem-matchers/register_all.vsh |
| 343 | goto :eof |
| 344 | |
| 345 | :usage |
| 346 | echo Usage: |
| 347 | echo makev.bat [target] [compiler] [options] |
| 348 | echo. |
| 349 | echo Compiler: |
| 350 | echo -msvc ^| -gcc ^| -tcc ^| -tcc32 ^| -clang Set C compiler |
| 351 | echo. |
| 352 | echo Target: |
| 353 | echo build[default] Compiles V using the given C compiler |
| 354 | echo clean Clean build artifacts and debugging symbols |
| 355 | echo cleanall Cleanup entire ALL build artifacts and vc repository |
| 356 | echo check Check that tests pass, and the repository is in a good shape for Pull Requests |
| 357 | echo help Display help for the given target |
| 358 | echo rebuild Fully clean/reset repository and rebuild V |
| 359 | echo. |
| 360 | echo Examples: |
| 361 | echo makev.bat -msvc |
| 362 | echo makev.bat -gcc --local |
| 363 | echo makev.bat build -tcc --local |
| 364 | echo makev.bat -tcc32 |
| 365 | echo makev.bat help clean |
| 366 | echo. |
| 367 | echo Use "make help <target>" for more information about a target, for instance: "make help clean" |
| 368 | echo. |
| 369 | echo Note: Any undefined/unsupported options will be ignored |
| 370 | exit /b 0 |
| 371 | |
| 372 | :help_help |
| 373 | echo Usage: |
| 374 | echo makev.bat help [target] |
| 375 | echo. |
| 376 | echo Target: |
| 377 | echo build ^| clean ^| cleanall ^| help Query given target |
| 378 | exit /b 0 |
| 379 | |
| 380 | :help_clean |
| 381 | echo Usage: |
| 382 | echo makev.bat clean |
| 383 | echo. |
| 384 | exit /b 0 |
| 385 | |
| 386 | :help_cleanall |
| 387 | echo Usage: |
| 388 | echo makev.bat cleanall |
| 389 | echo. |
| 390 | exit /b 0 |
| 391 | |
| 392 | :help_build |
| 393 | echo Usage: |
| 394 | echo makev.bat build [compiler] [options] |
| 395 | echo. |
| 396 | echo Compiler: |
| 397 | echo -msvc ^| -gcc ^| -tcc ^| -tcc32 ^| -clang Set C compiler |
| 398 | echo. |
| 399 | echo Options: |
| 400 | echo --local Use the local vc repository without |
| 401 | echo syncing with remote |
| 402 | exit /b 0 |
| 403 | |
| 404 | :help_rebuild |
| 405 | echo Usage: |
| 406 | echo makev.bat rebuild [compiler] [options] |
| 407 | echo. |
| 408 | echo Compiler: |
| 409 | echo -msvc ^| -gcc ^| -tcc ^| -tcc32 ^| -clang Set C compiler |
| 410 | echo. |
| 411 | echo Options: |
| 412 | echo --local Use the local vc repository without |
| 413 | echo syncing with remote |
| 414 | exit /b 0 |
| 415 | |
| 416 | :bootstrap_tcc |
| 417 | echo Bootstrapping TCC... |
| 418 | echo ^> TCC not found |
| 419 | if "!tcc_branch!" == "thirdparty-windows-i386" ( echo ^> Downloading TCC32 from !tcc_url! , branch !tcc_branch! ) else ( echo ^> Downloading TCC64 from !tcc_url! , branch !tcc_branch! ) |
| 420 | git clone --filter=blob:none --quiet --branch !tcc_branch! !tcc_url! "%tcc_dir%" |
| 421 | if !ERRORLEVEL! NEQ 0 exit /b !ERRORLEVEL! |
| 422 | git --no-pager -C "%tcc_dir%" log -n3 |
| 423 | exit /b !ERRORLEVEL! |
| 424 | |
| 425 | :cloning_vc |
| 426 | echo Cloning vc... |
| 427 | echo ^> Cloning from remote !vc_url! |
| 428 | git clone --filter=blob:none --quiet "%vc_url%" |
| 429 | exit /b !ERRORLEVEL! |
| 430 | |
| 431 | :build_bootstrap_with_tcc |
| 432 | if not exist "!tcc_exe!" ( |
| 433 | echo ^> TCC not found |
| 434 | exit /b 1 |
| 435 | ) |
| 436 | echo ^> Attempting to build "%V_BOOTSTRAP%" (from %V_C_FILE%) with "!tcc_exe!" |
| 437 | "!tcc_exe!" -B"%tcc_dir%" -bt10 -g -w -o "%V_BOOTSTRAP%" "%V_C_FILE%" -ladvapi32 -lws2_32 -Wl,-stack=33554432 |
| 438 | exit /b !ERRORLEVEL! |
| 439 | |
| 440 | :build_bootstrap_with_clang |
| 441 | "%where_exe%" /q clang |
| 442 | if !ERRORLEVEL! NEQ 0 ( |
| 443 | echo ^> Clang not found |
| 444 | exit /b 1 |
| 445 | ) |
| 446 | if "%PROCESSOR_ARCHITECTURE%" == "x86" ( set clang_target=i686-w64-mingw32 ) else ( set clang_target=x86_64-w64-mingw32 ) |
| 447 | echo ^> Attempting to build "%V_BOOTSTRAP%" (from %V_C_FILE%) with Clang |
| 448 | clang --target=!clang_target! -std=c99 -municode -g -w -Wno-error=implicit-function-declaration -Wno-error=incompatible-function-pointer-types -o "%V_BOOTSTRAP%" "%V_C_FILE%" -ladvapi32 -lws2_32 -Wl,-stack=33554432 |
| 449 | if !ERRORLEVEL! NEQ 0 ( |
| 450 | echo In most cases, compile errors happen because the version of Clang installed is too old |
| 451 | clang --version |
| 452 | exit /b 1 |
| 453 | ) |
| 454 | exit /b 0 |
| 455 | |
| 456 | :build_bootstrap_with_gcc |
| 457 | call :find_gcc_exe |
| 458 | if !ERRORLEVEL! NEQ 0 ( |
| 459 | echo ^> GCC not found |
| 460 | exit /b 1 |
| 461 | ) |
| 462 | echo ^> Attempting to build "%V_BOOTSTRAP%" (from %V_C_FILE%) with GCC "!gcc_exe!" |
| 463 | "!gcc_exe!" -std=c99 -municode -g -w -o "%V_BOOTSTRAP%" "%V_C_FILE%" -ladvapi32 -lws2_32 -Wl,-stack=33554432 |
| 464 | if !ERRORLEVEL! NEQ 0 ( |
| 465 | echo In most cases, compile errors happen because the version of GCC installed is too old |
| 466 | "!gcc_exe!" --version |
| 467 | exit /b 1 |
| 468 | ) |
| 469 | exit /b 0 |
| 470 | |
| 471 | :find_gcc_exe |
| 472 | REM Prefer MinGW target-prefixed drivers when present, so PATH conflicts do not pick an unrelated gcc.exe. |
| 473 | set "gcc_exe=" |
| 474 | if "%PROCESSOR_ARCHITECTURE%" == "x86" ( |
| 475 | call :resolve_executable i686-w64-mingw32-gcc |
| 476 | if not [!resolved_exe!] == [] ( |
| 477 | set "gcc_exe=!resolved_exe!" |
| 478 | exit /b 0 |
| 479 | ) |
| 480 | ) else ( |
| 481 | call :resolve_executable x86_64-w64-mingw32-gcc |
| 482 | if not [!resolved_exe!] == [] ( |
| 483 | set "gcc_exe=!resolved_exe!" |
| 484 | exit /b 0 |
| 485 | ) |
| 486 | ) |
| 487 | call :resolve_executable gcc |
| 488 | if not [!resolved_exe!] == [] ( |
| 489 | set "gcc_exe=!resolved_exe!" |
| 490 | exit /b 0 |
| 491 | ) |
| 492 | exit /b 1 |
| 493 | |
| 494 | :resolve_executable |
| 495 | set "resolved_exe=" |
| 496 | for %%i in ("%~1") do if exist "%%~fi" ( |
| 497 | set "resolved_exe=%%~fi" |
| 498 | exit /b 0 |
| 499 | ) |
| 500 | for /f "usebackq delims=" %%i in (`where "%~1" 2^>nul`) do ( |
| 501 | set "resolved_exe=%%~fi" |
| 502 | exit /b 0 |
| 503 | ) |
| 504 | exit /b 1 |
| 505 | |
| 506 | :eof |
| 507 | popd |
| 508 | endlocal |
| 509 | exit /b 0 |
| 510 | |
| 511 | :move_updated_to_v |
| 512 | @REM del "%V_EXE%" &:: breaks if `makev.bat` is run from `v up` b/c of held file handle on `%V_EXE%` |
| 513 | if exist "%V_EXE%" move "%V_EXE%" "%V_OLD%" >nul |
| 514 | REM sleep for at most 100ms |
| 515 | ping 192.0.2.1 -n 1 -w 100 >nul |
| 516 | move "%V_UPDATED%" "%V_EXE%" >nul |
| 517 | exit /b 0 |
| 518 | |