112 lines
2.9 KiB
Batchfile
112 lines
2.9 KiB
Batchfile
@echo off
|
|
setlocal enabledelayedexpansion
|
|
|
|
:: build.bat -- Compile the sketch using arduino-cli
|
|
::
|
|
:: Reads all settings from .anvil.toml. No Anvil binary required.
|
|
::
|
|
:: Usage:
|
|
:: build.bat Compile (verify only)
|
|
:: build.bat --clean Delete build cache first
|
|
:: build.bat --verbose Show full compiler output
|
|
|
|
set "SCRIPT_DIR=%~dp0"
|
|
set "CONFIG=%SCRIPT_DIR%.anvil.toml"
|
|
|
|
if not exist "%CONFIG%" (
|
|
echo FAIL: No .anvil.toml found in %SCRIPT_DIR%
|
|
exit /b 1
|
|
)
|
|
|
|
:: -- Parse .anvil.toml ----------------------------------------------------
|
|
:: Read file directly, skip comments and section headers
|
|
for /f "usebackq tokens=1,* delims==" %%a in ("%CONFIG%") do (
|
|
set "_K=%%a"
|
|
if not "!_K:~0,1!"=="#" if not "!_K:~0,1!"=="[" (
|
|
set "_K=!_K: =!"
|
|
set "_V=%%b"
|
|
if defined _V (
|
|
set "_V=!_V: =!"
|
|
set "_V=!_V:"=!"
|
|
)
|
|
if "!_K!"=="name" set "SKETCH_NAME=!_V!"
|
|
if "!_K!"=="fqbn" set "FQBN=!_V!"
|
|
if "!_K!"=="warnings" set "WARNINGS=!_V!"
|
|
)
|
|
)
|
|
|
|
if "%SKETCH_NAME%"=="" (
|
|
echo FAIL: Could not read project name from .anvil.toml
|
|
exit /b 1
|
|
)
|
|
|
|
set "SKETCH_DIR=%SCRIPT_DIR%%SKETCH_NAME%"
|
|
set "BUILD_DIR=%SCRIPT_DIR%.build"
|
|
|
|
:: -- Parse arguments ------------------------------------------------------
|
|
set "DO_CLEAN=0"
|
|
set "VERBOSE="
|
|
|
|
:parse_args
|
|
if "%~1"=="" goto done_args
|
|
if "%~1"=="--clean" set "DO_CLEAN=1" & shift & goto parse_args
|
|
if "%~1"=="--verbose" set "VERBOSE=--verbose" & shift & goto parse_args
|
|
if "%~1"=="--help" goto show_help
|
|
if "%~1"=="-h" goto show_help
|
|
echo FAIL: Unknown option: %~1
|
|
exit /b 1
|
|
|
|
:show_help
|
|
echo Usage: build.bat [--clean] [--verbose]
|
|
echo Compiles the sketch. Settings from .anvil.toml.
|
|
exit /b 0
|
|
|
|
:done_args
|
|
|
|
:: -- Preflight ------------------------------------------------------------
|
|
where arduino-cli >nul 2>nul
|
|
if errorlevel 1 (
|
|
echo FAIL: arduino-cli not found in PATH.
|
|
exit /b 1
|
|
)
|
|
|
|
if not exist "%SKETCH_DIR%" (
|
|
echo FAIL: Sketch directory not found: %SKETCH_DIR%
|
|
exit /b 1
|
|
)
|
|
|
|
:: -- Clean ----------------------------------------------------------------
|
|
if "%DO_CLEAN%"=="1" (
|
|
if exist "%BUILD_DIR%" (
|
|
echo Cleaning build cache...
|
|
rmdir /s /q "%BUILD_DIR%"
|
|
)
|
|
)
|
|
|
|
:: -- Build include flags --------------------------------------------------
|
|
set "BUILD_FLAGS="
|
|
for %%d in (lib\hal lib\app) do (
|
|
if exist "%SCRIPT_DIR%%%d" (
|
|
set "BUILD_FLAGS=!BUILD_FLAGS! -I%SCRIPT_DIR%%%d"
|
|
)
|
|
)
|
|
set "BUILD_FLAGS=!BUILD_FLAGS! -Werror"
|
|
|
|
:: -- Compile --------------------------------------------------------------
|
|
echo Compiling %SKETCH_NAME%...
|
|
echo Board: %FQBN%
|
|
echo Sketch: %SKETCH_DIR%
|
|
echo.
|
|
|
|
if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%"
|
|
|
|
arduino-cli compile --fqbn %FQBN% --build-path "%BUILD_DIR%" --warnings %WARNINGS% --build-property "build.extra_flags=%BUILD_FLAGS%" %VERBOSE% "%SKETCH_DIR%"
|
|
if errorlevel 1 (
|
|
echo.
|
|
echo FAIL: Compilation failed.
|
|
exit /b 1
|
|
)
|
|
|
|
echo.
|
|
echo ok Compile succeeded.
|
|
echo. |