@ECHO OFF

ECHO INFO: Setting up GHS environment...

SET "AZRTOS_TEST_DIR=%~dp0"

IF EXIST %AZRTOS_GHS_COMP_DIR% GOTO FOUND_GHS_COMP_DIR
set AZRTOS_GHS_COMP_DIR="C:\ghs\comp_202014"
IF EXIST %AZRTOS_GHS_COMP_DIR% GOTO FOUND_GHS_COMP_DIR
set AZRTOS_GHS_COMP_DIR="C:\ghs\comp_201952"
IF EXIST %AZRTOS_GHS_COMP_DIR% GOTO FOUND_GHS_COMP_DIR
set AZRTOS_GHS_COMP_DIR="C:\ghs\comp_201914"
IF EXIST %AZRTOS_GHS_COMP_DIR% GOTO FOUND_GHS_COMP_DIR
ECHO ERROR: Green Hills Software compiler directory not found.
EXIT /B 2
:FOUND_GHS_COMP_DIR

SET AZRTOS_GHS_COMP_GBUILD=%AZRTOS_GHS_COMP_DIR%\gbuild.exe
IF NOT EXIST %AZRTOS_GHS_COMP_GBUILD% (
    ECHO ERROR: gbuild.exe not found at %AZRTOS_GHS_COMP_GBUILD%
    EXIT /B 1
) ELSE (
    ECHO INFO: gbuild.exe found at %AZRTOS_GHS_COMP_GBUILD%
)

IF EXIST %AZRTOS_GHS_MULTI_DIR% GOTO FOUND_GHS_MULTI_DIR
set AZRTOS_GHS_MULTI_DIR="C:\ghs\multi_716d"
IF EXIST %AZRTOS_GHS_MULTI_DIR% GOTO FOUND_GHS_MULTI_DIR
set AZRTOS_GHS_MULTI_DIR="C:\ghs\multi_716"
IF EXIST %AZRTOS_GHS_MULTI_DIR% GOTO FOUND_GHS_MULTI_DIR
set AZRTOS_GHS_MULTI_DIR="C:\ghs\multi_714"
IF EXIST %AZRTOS_GHS_MULTI_DIR% GOTO FOUND_GHS_MULTI_DIR
ECHO ERROR: Green Hills Software MULTI directory not found.
EXIT /B 1
:FOUND_GHS_MULTI_DIR

SET AZRTOS_GHS_MULTI_MULTI=%AZRTOS_GHS_MULTI_DIR%\multi.exe
IF NOT EXIST %AZRTOS_GHS_MULTI_MULTI% (
    ECHO ERROR: multi.exe not found at %AZRTOS_GHS_MULTI_MULTI%
    EXIT /B 1
) ELSE (
    ECHO INFO: multi.exe found at %AZRTOS_GHS_MULTI_MULTI%
)

ECHO INFO: GHS environment setup completed successfully!
