@echo off title Mahdi Rahi EC200U Easy Build System setlocal EnableExtensions EnableDelayedExpansion :: ========================================================== :: AUTO ADMIN ELEVATION (Robust & Argument-Preserving) :: ========================================================== @setlocal enableextensions @cd /d "%~dp0" :: بررسی دسترسی Admin net session >nul 2>&1 if %errorlevel% neq 0 ( echo Requesting Administrator privileges... ::powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -Verb RunAs" powershell -Command "Start-Process '%~f0' -Verb RunAs" exit /b ) :: اگر ادمین هستیم، ادامه می دهیم @endlocal setlocal EnableExtensions EnableDelayedExpansion echo Running with Administrator privileges... echo. :: =============================== :: ASK FOR BACKUP (WITH TIMEOUT) :: =============================== echo. echo no Backup set DO_BACKUP=N echo. :: ========================================== :: AUTO DETECT SDK ROOT (DRIVE + PATH) :: ========================================== ::set SDK_DRIVE=%~d0 ::set SDK_PATH=%~p0 ::set SDK_ROOT=%SDK_DRIVE%%SDK_PATH% set SDK_ROOT=%~dp0 :: %SDK_DRIVE% :: cd "%SDK_PATH%" cd /d "%SDK_ROOT%" echo SDK Root Detected: echo %SDK_ROOT% echo ========================================== echo EC200U Build System echo ========================================== :: =============================== :: GET DATE & TIME (24H) :: =============================== for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format yyyy.MM.dd_HH.mm.ss"') do set DATETIME=%%i :: =============================== :: PATH DEFINITIONS :: =============================== set "BASE_DIR=%SDK_ROOT%MahdiRahi_BuildArchive" set "ARCHIVE_BASE=%BASE_DIR%\%DATETIME%" set "TARGET_PREVIOUS_VERSION=%ARCHIVE_BASE%\targetPreviousVersion" set "TARGET_DIR=%SDK_ROOT%\target" set "COMPONENT_DIR=%ARCHIVE_BASE%\components" :: =============================== :: CREATE DIRECTORIES :: =============================== ::echo BASE_DIR=%BASE_DIR% ::echo ARCHIVE_BASE=%ARCHIVE_BASE% ::echo TARGET_PREVIOUS_VERSION=%TARGET_PREVIOUS_VERSION% ::echo COMPONENT_DIR=%COMPONENT_DIR% ::echo. if /I "%DO_BACKUP%"=="Y" ( if not exist "%BASE_DIR%" mkdir "%BASE_DIR%" if not exist "%ARCHIVE_BASE%" mkdir "%ARCHIVE_BASE%" if not exist "%COMPONENT_DIR%" mkdir "%COMPONENT_DIR%" if exist "%TARGET_DIR%" ( if not exist "%TARGET_PREVIOUS_VERSION%" mkdir "%TARGET_PREVIOUS_VERSION%" ) ) :: =============================== :: BACKUP :: =============================== :: FOLDER: TARGET if /I "%DO_BACKUP%"=="Y" ( if exist "%TARGET_DIR%" ( echo. echo Compressing TARGET folder... powershell -command "Compress-Archive -Path '%TARGET_DIR%' -DestinationPath '%TARGET_PREVIOUS_VERSION%\target.zip' -Force" echo Backup created: echo %TARGET_PREVIOUS_VERSION%\target.zip ) else ( echo TARGET folder not found. Skipping backup. ) ) else ( echo Backup skipped by user. ) :: FOLDER: COMPONENTS if /I "%DO_BACKUP%"=="Y" ( echo. echo Creating components archive... "BACKUP OF USER CODE"... echo Backup of: Folder components, except the folder: "ql-config" if not exist "%COMPONENT_DIR%" mkdir "%COMPONENT_DIR%" echo. echo Src: %SDK_ROOT%components ::echo %COMPONENT_DIR% echo Dest: %COMPONENT_DIR%\components.zip echo. powershell -NoProfile -Command ^ "$items = Get-ChildItem '%SDK_ROOT%components' -Exclude 'ql-config'; Compress-Archive -Path $items -DestinationPath '%COMPONENT_DIR%\components.zip' -Force" echo. echo Components archive created: echo %COMPONENT_DIR%\components.zip ) :: =============================== :: CLEAN OLD BUILD FOLDERS :: =============================== echo. echo =============================== echo CLEANING BUILD ENVIRONMENT echo =============================== echo. echo Stopping possible build processes... for %%p in ( ninja.exe cmake.exe arm-none-eabi-ar.exe arm-none-eabi-gcc.exe cc1.exe cc1plus.exe collect2.exe ld.exe ) do ( taskkill /f /im %%p >nul 2>&1 ) timeout /t 5 >nul echo Cleaning folders... echo. if exist "%SDK_ROOT%\out" ( echo Removing OUT folder... call :SAFE_DELETE "%SDK_ROOT%\out" timeout /t 5 >nul echo OUT folder removed. ) else ( echo OUT folder not found. Skipping. ) echo. if exist "%SDK_ROOT%\target" ( echo Removing TARGET folder... call :SAFE_DELETE "%SDK_ROOT%\target" timeout /t 5 >nul echo TARGET folder removed. ) else ( echo TARGET folder not found. Skipping. ) echo. echo Clean completed. echo. :: =============================== :: START BUILD :: =============================== color 0E for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format HH:mm:ss"') do set STARTTIME=%%i echo ========================================== echo Cleaning Build System (SDK Clean) echo ========================================== echo. call build_all.bat clean echo. echo ========================================== echo Starting Firmware Build echo ========================================== echo. call build_all.bat new EC200UEU_AA V01 set BUILD_RESULT=%ERRORLEVEL% for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format HH:mm:ss"') do set ENDTIME=%%i for /f %%i in ('powershell -NoProfile -Command "$s=[datetime]::Parse('%STARTTIME%');$e=[datetime]::Parse('%ENDTIME%');($e-$s).ToString()"') do set DURATION=%%i echo Build Duration: %DURATION% echo. :: =============================== :: BUILD RESULT :: =============================== IF %BUILD_RESULT% NEQ 0 ( color 0C echo ===================================== echo BUILD FAILED echo ===================================== ) ELSE ( color 0A echo ===================================== echo BUILD SUCCESSFUL echo ===================================== ) echo please click exit window "x". pause pause echo please click exit window "x". :WAIT_CLOSE timeout /t 3600 >nul goto WAIT_CLOSE :: =============================== :: =============================== :: =============================== :: =============================== :: =============================== :: =============================== :: =============================== :: =============================== :: =============================== :: =============================== :: =============================== :: =============================== :: FUNCTION: DELETE FOLDER :: =============================== :SAFE_DELETE set "TARGET=%~1" set RETRY=0 set MAX_RETRY=5 :DELETE_LOOP if exist "%TARGET%" ( rmdir /s /q "%TARGET%" 2>nul ) if exist "%TARGET%" ( set /a RETRY+=1 if !RETRY! LEQ %MAX_RETRY% ( echo Retry !RETRY! deleting %TARGET% timeout /t 3 >nul goto DELETE_LOOP ) else ( color 0C echo ===================================== echo BUILD FAILED echo ===================================== echo ERROR: Could not delete %TARGET% echo please remove manually. pause echo 4 pause echo 3 pause echo 2 pause echo 1 pause exit /b 1 ) ) exit /b 0