Files
STM32F4-Base/MDK-ARM/build.bat
T

64 lines
2.2 KiB
Batchfile

@echo off
setlocal
set PROJ=%~dp0STM32F407-Demo.uvprojx
set LOG=%~dp0build_log.txt
set TARGET=STM32F407-Demo
:: UV4 location: env var DTU_KEIL_UV4 = full path of UV4.exe.
:: Required on any MCU build machine; there is NO machine-default fallback
:: (no C:\Keil_v5 guess). Set it once per machine, user scope (no admin):
:: [Environment]::SetEnvironmentVariable('DTU_KEIL_UV4', 'D:\Tools\Keil\UV4\UV4.exe', 'User')
:: then reopen the terminal. Full contract: the DTU_* env var plan document
:: in docs/ (local tool path env vars plan).
if defined DTU_KEIL_UV4 goto uv4_set
echo BUILD_FAIL: environment variable DTU_KEIL_UV4 is not set
echo Set it to the full path of UV4.exe, e.g.:
echo [Environment]::SetEnvironmentVariable('DTU_KEIL_UV4', 'D:\Tools\Keil\UV4\UV4.exe', 'User')
exit /b 2
:uv4_set
if exist "%DTU_KEIL_UV4%" goto uv4_ok
echo ENV_ERROR: DTU_KEIL_UV4 is set but does not exist: "%DTU_KEIL_UV4%"
echo Fix the variable value. No fallback to another UV4 install is attempted.
exit /b 2
:uv4_ok
set UV4=%DTU_KEIL_UV4%
:: UV4 is single-instance: if an IDE process is alive, this -b call may be
:: forwarded to it (exit code is lost, GUI may open). Warn only; never kill.
tasklist /fi "imagename eq UV4.exe" /nh | find /i "UV4.exe" >nul
if not errorlevel 1 echo WARNING: UV4 IDE is running - this build may be forwarded to the IDE. Close it for a deterministic CLI build.
:: Remove stale log first: UV4 -o writes the log only when a build actually
:: runs. A leftover log would otherwise be misreported as this build's result.
if exist "%LOG%" del "%LOG%"
"%UV4%" -b "%PROJ%" -t%TARGET% -j0 -o "%LOG%"
if not exist "%LOG%" (
echo BUILD_FAIL: no build log produced - UV4 did not run or hung
exit /b 1
)
:: Error diagnostics in the log: ARMCC V5 "file(line): error: #NN" and
:: "no source: Error: #5" both contain "error:"; a 0E0W log never does.
findstr /I /C:"error:" "%LOG%" >nul
if not errorlevel 1 (
echo BUILD_FAIL: error diagnostics in build log
type "%LOG%"
exit /b 1
)
:: Success proof: exact 0E0W summary line (also rejects warning-only builds).
findstr /C:"0 Error(s), 0 Warning(s)" "%LOG%" >nul
if errorlevel 1 (
echo BUILD_FAIL: no 0E0W marker in build log
type "%LOG%"
exit /b 1
)
echo BUILD_OK: 0 errors, 0 warnings
exit /b 0