Update that helps diagnose and in some cases circumvent potential issues with MSVC and GNU utilities

This commit is contained in:
Jj0YzL5nvJ 2023-01-03 16:30:19 -07:00
parent ba9a524830
commit cf8b03ba58

View file

@ -1,37 +1,56 @@
@echo off
setlocal enableextensions
:: Countermeasure vs tainted build environment by known third party utilities
set FIND=find
find /? >nul 2>&1
if errorlevel 1 (
echo WARNING: GNU utilities in PATH can break MSVC
echo.
set FIND=findstr
)
:: Anchor to the project file path, otherwise the arguments would be invalid:
::
:: * In theory this is unnecessary, but it makes the process more transparent
:: to people unfamiliar with VS's not-so-well-explained behaviors
::
pushd "%~dp0..\projects\msvc\"
if errorlevel 1 exit /b 101
:: Validating arguments passed from Visual Studio to use as variables:
::
:: * Arguments with conflicting syntax can terminate the script abruptly
:: * 'GAS_EXTRA' argument isn't used in some cases
::
set GAS_SRCDIR=
set GAS_OBJDIR=
set GAS_EXTRA=
for /f "tokens=1,2*" %%A in ('echo %*') do (
set GAS_SRCDIR=%%A
set GAS_OBJDIR=%%B
set GAS_EXTRA=%%C
set GAS_SRCDIR=%%A
set GAS_OBJDIR=%%B
set GAS_EXTRA=%%C
)
set GAS_CLARG=%GAS_OBJDIR%
if defined GAS_EXTRA set GAS_CLARG=%GAS_OBJDIR% %GAS_EXTRA%
:: "Anti-PEBCAK":
::
:: * Ensures that "Item A" and "Item B" exist, and send an error signal if not
:: * The sole purpose of this code is to make the script fail outside VS
:: * Ensure that 'GAS_SRCDIR' and 'GAS_OBJDIR' exist or are defined and send an
:: error signal if not
::
if not exist mupen64plus-core.vcxproj exit /b 202
if not exist "%GAS_SRCDIR%asm_defines.c" exit /b 303
if not exist "%GAS_SRCDIR%asm_defines.c" exit /b 202
if not defined GAS_OBJDIR exit /b 303
:: Legacy code adaptation for this script:
::
:: * Delete the libraries previously generated by 'gawk' or this script
:: * CL's stuff/witchcraft, if all goes well it will generate "Item C"
:: * CL's stuff/witchcraft, if all goes well it will generate 'asm_defines.obj'
::
del /f /q "%GAS_SRCDIR%asm_defines_*" 2>nul
cl /c /Fo%GAS_CLARG% /I ..\..\src "%GAS_SRCDIR%asm_defines.c"
:: If "Item C" does not exist, send error
:: If 'asm_defines.obj' does not exist, send error
if not exist "%GAS_OBJDIR%asm_defines.obj" exit /b 404
if "%USE_GAWK%" NEQ "1" goto native
@ -48,8 +67,8 @@ goto log
:: Adaptation of 'gen_asm_defines.awk' / 'gen_asm_script.sh':
::
:: 1. Display 'asm_defines.obj' (aka "Item C") as a list, looking only
:: for patterns '@ASM_DEFINE'
:: 1. Display 'asm_defines.obj' as a list, looking only for patterns
:: '@ASM_DEFINE'
:: 2. Sort for easy reading, the result is interpreted as an array
:: with ' ' as default delimiter in the 'for' command
:: 3. The for's 'tokens=2,3' ignores pattern "1" (@ASM_DEFINE) and anything
@ -57,9 +76,9 @@ goto log
:: 4. Print current values and repeat steps 3 and 4 on the next line
:: until EOL is reached
::
for /f "tokens=2,3" %%J in ('type "%GAS_OBJDIR%asm_defines.obj" ^| find "@ASM_DEFINE" ^| sort') do (
echo %%define %%J ^(%%K^)>>"%GAS_SRCDIR%asm_defines_nasm.h"
echo #define %%J ^(%%K^)>>"%GAS_SRCDIR%asm_defines_gas.h"
for /f "tokens=2,3" %%J in ('type "%GAS_OBJDIR%asm_defines.obj" ^| %FIND% "@ASM_DEFINE" ^| sort') do (
echo %%define %%J ^(%%K^)>>"%GAS_SRCDIR%asm_defines_nasm.h"
echo #define %%J ^(%%K^)>>"%GAS_SRCDIR%asm_defines_gas.h"
)
:log