@echo off

cls
echo THIS ONLY COPY ALL HEADER FILES "*.H" FROM THIS FOLDER
echo TO SDCC/INCLUDE SUBFOLDER
echo.
echo !WARNING!
echo ONLY USE THIS IF YOU INSTALLED SDCC (BY DEFAULT)
echo IN YOUR WINDOWS "PROGRAM FILES" FOLDER
echo.
pause

if "%ProgramFiles%" == "" GOTO FAILWINVARIABLES
set ProgRoot=%ProgramFiles%
if NOT EXIST "%ProgRoot%"\sdcc GOTO TRYTHEOTHERONE
if NOT EXIST "%ProgRoot%"\sdcc\include GOTO TRYTHEOTHERONE
if NOT EXIST "%ProgRoot%"\sdcc\bin GOTO TRYTHEOTHERONE
GOTO SUCCESS
:TRYTHEOTHERONE
if NOT "%ProgramFiles(x86)%" == "" set ProgRoot=%ProgramFiles(x86)%
if NOT EXIST "%ProgRoot%"\sdcc GOTO FAILSDCCFOLDER
if NOT EXIST "%ProgRoot%"\sdcc\include GOTO FAILSDCCFOLDER
if NOT EXIST "%ProgRoot%"\sdcc\bin GOTO FAILSDCCFOLDER
:SUCCESS
if NOT EXIST .\tools\System\objcopy.exe GOTO PASSOBJCOPY

cls
echo COPY OBJCOPY.EXE TO SDCC\BIN FOLDER
copy tools\system\objcopy.exe "%ProgRoot%"\sdcc\bin /y
pause

:PASSOBJCOPY

cls
echo THIS PART RECOMPILE LIBRARIES : COMP, GETPUT11 and LIB4KSA
echo.
pause

cls
cd comp
call build.bat
cd ..

cls
cd getput11
call build.bat
cd ..

cls
cd lib4ksa
call build.bat
cd ..

cls
REM if NOT EXIT .\*.h GOTO FAILHEADERFILES
echo COPY HEADER FILES "*.h" TO SDCC\INCLUDE FOLDER
copy *.h "%ProgRoot%"\sdcc\include /y
goto END

:FAILWINVARIABLES
echo FAIL : Windows Program Files Env. Variable doesn't exist
goto END

:FAILSDCCFOLDER
echo FAIL : SDCC is not installed in its default folder
echo ! YOU NEED TO INSTALL SDCC BEFORE RUNNING THIS FILE !
goto END

:FAILHEADERFILES
echo FAIL : NO HEADER FILES TO COPY
echo ! YOU NEED TO COMPILE LIBRARIES FIRST !
goto END

:END
pause
