Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 79 additions & 4 deletions scripts/template_setup_win
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ REM # Check dependencies

call :check_command cmake 90
if [%ERRORLEVEL%] neq [0] goto end
call :check_command wget 91
if [%ERRORLEVEL%] neq [0] goto end

call :check_command 7z 92
if [%ERRORLEVEL%] neq [0] goto end

Expand All @@ -81,6 +80,17 @@ if /i [%1] equ [/t] (
)
set DO_GNU_TOOLCHAIN=y
shift
) else if /i [%1] equ [/dl] (
if /i [%2] equ [curl] (
set DL_FORCE=curl
) else if /i [%2] equ [wget] (
set DL_FORCE=wget
) else (
echo ERROR: /dl expects ^<curl^|wget^>
set EXITCODE=3
goto end
)
shift
) else if /i [%1] equ [/l] (
set DO_LLVM_TOOLCHAIN=y
) else if /i [%1] equ [/h] (
Expand Down Expand Up @@ -144,7 +154,71 @@ if [%ERRORLEVEL%] equ [1] set DO_CMAKE_PKG=y

echo.

REM # Download helper
REM # usage: call :download URL OUTFILE
:download
setlocal ENABLEDELAYEDEXPANSION
set _URL=%~1
set _OUT=%~2

if /i [%DL_TOOL%] equ [wget] (
REM Emulate quiet+progress+timestamping:
wget -q --show-progress -N -O "!_OUT!" "!_URL!"
endlocal & exit /b %ERRORLEVEL%
) else (
REM curl: -f fail on HTTP errors; -L follow redirects
REM --remote-time preserves Last-Modified on the file
REM -z OUTFILE does conditional GET (only download if newer)
REM Replace the --progress-bar with an -sS to make it quiet if needed
if exist "!_OUT!" (
curl.exe -fL --retry 5 --retry-delay 2 --progress-bar --remote-time -z "!_OUT!" -o "!_OUT!" "!_URL!"
) else (
curl.exe -fL --retry 5 --retry-delay 2 --progress-bar --remote-time -o "!_OUT!" "!_URL!"
)
endlocal & exit /b %ERRORLEVEL%
)

:process
REM # Choose downloader (default: wget; fallback to curl). Allow /dl override.
set DL_TOOL=

if /i [%DL_FORCE%] equ [curl] (
call :check_command curl 91
if [%ERRORLEVEL%] equ [0] (
set DL_TOOL=curl
) else (
echo ERROR: /dl curl requested but 'curl' not found in PATH.
set EXITCODE=91
goto end
)
) else if /i [%DL_FORCE%] equ [wget] (
call :check_command wget 91
if [%ERRORLEVEL%] equ [0] (
set DL_TOOL=wget
) else (
echo ERROR: /dl wget requested but 'wget' not found in PATH.
set EXITCODE=91
goto end
)
) else (
REM Default behavior: prefer wget, else curl
call :check_command wget 91
if [%ERRORLEVEL%] equ [0] (
set DL_TOOL=wget
) else (
call :check_command curl 91
if [%ERRORLEVEL%] equ [0] (
set DL_TOOL=curl
)
)
)

if [%DL_TOOL%] equ [] (
echo Zephyr SDK setup requires either 'wget' or 'curl' in PATH.
set EXITCODE=91
goto end
)

REM # Install GNU toolchains
if [%DO_GNU_TOOLCHAIN%] neq [] (
if not exist gnu\ mkdir gnu
Expand All @@ -158,7 +232,7 @@ if [%DO_GNU_TOOLCHAIN%] neq [] (
echo Installing '%%t' GNU toolchain ...

REM # Download toolchain archive
wget -q --show-progress -N -O !TOOLCHAIN_FILENAME! !TOOLCHAIN_URI!
call :download !TOOLCHAIN_URI! !TOOLCHAIN_FILENAME!
if [!ERRORLEVEL!] neq [0] (
del /q !TOOLCHAIN_FILENAME!
echo ERROR: GNU toolchain download failed
Expand Down Expand Up @@ -190,7 +264,7 @@ if [%DO_LLVM_TOOLCHAIN%] neq [] (
set TOOLCHAIN_URI=%DL_REL_BASE%/!TOOLCHAIN_FILENAME!

REM # Download toolchain archive
wget -q --show-progress -N -O !TOOLCHAIN_FILENAME! !TOOLCHAIN_URI!
call :download !TOOLCHAIN_URI! !TOOLCHAIN_FILENAME!
if [!ERRORLEVEL!] neq [0] (
del /q !TOOLCHAIN_FILENAME!
echo ERROR: LLVM toolchain download failed
Expand Down Expand Up @@ -243,6 +317,7 @@ echo all Install all GNU toolchains
echo /l Install LLVM toolchain
echo /h Install host tools
echo /c Register Zephyr SDK CMake package
echo /dl ^<curl^|wget^> Force downloader (default: wget, fallback to curl)
echo.
echo Supported GNU Toolchains:
echo.
Expand Down
Loading