@echo off
REM %NDC6%

if (%1)==() goto test_command
if (%1)==(start) goto start
goto endok

:test_command
if (%COMSPEC%)==() goto no_command
%COMSPEC% /E:9216 /C %0 start %1 %2 %3
goto endok

:no_command
echo No Command Interpreter found
goto endok

:start
call clean.bat
computil SetupC6
if exist setenv.bat call setenv.bat
if not exist ..\C6\*.* md ..\C6 >nul
if exist ..\C6\*.* call clean.bat ..\C6\

if (%NDC6%)==() goto enderror
if (%NDWINSYS%)==() goto enderror

CD System
ECHO ****************
ECHO  Compile System 
ECHO ****************
%NDC6%\Bin\dcc32.exe -B -M -DBCB -N..\..\C6 -U..\..\C6 -H -W -Z IndySystem60.dpk -$d-l-
if errorlevel 1 goto enderror

%NDC6%\Bin\dcc32.exe -B -M -DBCB -N..\..\C6 -U..\..\C6 -H -W -Z /JPHN IndySystem60.dpk -$d-l-
REM ***************************************************
REM Create .LIB file
REM ***************************************************
echo Creating IndySystem60.LIB file, please wait...
..\LspFix IndySystem60.lsp
%NDC6%\bin\tlib.exe IndySystem60.lib /P32 @IndySystem60.lsp
Move *.lib ..\..\C6 >> nul
Move *.hpp ..\..\C6 >> nul
Move *.obj ..\..\C6 >> nul
Move /Y IndySystem60.bpl %NDWINSYS% >> nul
Move /Y IndySystem60.bpi %NDWINSYS% >> nul
Move *.dcp ..\..\C6 >> nul
if exist ..\C6\IndySystem60.bak del ..\C6\IndySystem60.bak >nul

CD ..
CD Core
ECHO **************
ECHO  Compile Core    
ECHO **************
%NDC6%\Bin\dcc32.exe -B -M -DBCB -N..\..\C6 -U..\..\C6 -H -W -Z IndyCore60.dpk -$d-l-
if errorlevel 1 goto enderror

%NDC6%\Bin\dcc32.exe -B -M -DBCB -N..\..\C6 -U..\..\C6 -H -W -Z /JPHN IndyCore60.dpk -$d-l-
REM ***************************************************
REM Create .LIB file
REM ***************************************************
echo Creating IndyCore60.LIB file, please wait...
..\LspFix IndyCore60.lsp
%NDC6%\bin\tlib.exe IndyCore60.lib /P32 @IndyCore60.lsp
Move *.lib ..\..\C6 >> nul
Move *.hpp ..\..\C6 >> nul
Move *.obj ..\..\C6 >> nul
Move /Y IndyCore60.bpl %NDWINSYS% >> nul
Move /Y IndyCore60.bpi %NDWINSYS% >> nul
Move *.dcp ..\..\C6 >> nul
if exist ..\C6\IndyCore60.bak del ..\C6\IndyCore60.bak >nul


%NDC6%\Bin\dcc32.exe -B -M -DBCB -N..\..\C6 -U..\..\C6 -H -W -Z dclIndyCore60.dpk -$d-l-
if errorlevel 1 goto enderror

%NDC6%\Bin\dcc32.exe -B -M -DBCB -N..\..\C6 -U..\..\C6 -H -W -Z /JPHN dclIndyCore60.dpk -$d-l-
REM ***************************************************
REM Create .LIB file
REM ***************************************************
echo Creating dclIndyCore60.LIB file, please wait...
..\LspFix dclIndyCore60.lsp
%NDC6%\bin\tlib.exe dclIndyCore60.lib /P32 @dclIndyCore60.lsp
Move *.lib ..\..\C6 >> nul
Move *.hpp ..\..\C6 >> nul
Move *.obj ..\..\C6 >> nul
Move *.bpl ..\..\C6 >> nul
Move *.dcp ..\..\C6 >> nul
if exist ..\C6\dclIndyCore60.bak del ..\C6\dclIndyCore60.bak >nul

CD ..
ECHO *******************
ECHO  Compile Protocols
ECHO *******************
CD Protocols
ECHO ************************
ECHO  IdCompressionIntercept
ECHO ************************
%NDC6%\Bin\dcc32.exe -B -M -DBCB -N..\..\C6 -U..\..\C6 -H -W -Z IdCompressionIntercept.pas -$d-l-
if errorlevel 1 goto enderror
%NDC6%\Bin\dcc32.exe -B -M -DBCB -N..\..\C6 -U..\..\C6 -H -W -Z /JPHN IdCompressionIntercept.pas -$d-l-
ECHO *************************
ECHO  Compile IndyProtocols60  
ECHO *************************
%NDC6%\Bin\dcc32.exe -B -M -DBCB -N..\..\C6 -U..\..\C6 -H -W -Z IndyProtocols60.dpk -$d-l-
if errorlevel 1 goto enderror
%NDC6%\Bin\dcc32.exe -B -M -DBCB -N..\..\C6 -U..\..\C6 -H -W -Z /JPHN IndyProtocols60.dpk -$d-l-

REM ***************************************************
REM Create .LIB file
REM ***************************************************
echo Creating IndyProtocols60.LIB file, please wait...
..\LspFix IndyProtocols60.lsp
%NDC6%\bin\tlib.exe IndyProtocols60.lib /P32 @IndyProtocols60.lsp
Move *.lib ..\..\C6 >> nul
Move *.hpp ..\..\C6 >> nul
Move id*.obj ..\..\C6 >> nul
Move /Y IndyProtocols60.bpl %NDWINSYS% >> nul
Move /Y IndyProtocols60.bpi %NDWINSYS% >> nul
Move *.dcp ..\..\C6 >> nul
if exist ..\C6\IndyProtocols60.bak del ..\C6\IndyProtocols60.bak >nul

ECHO ****************************
ECHO  Compile dclIndyProtocols60 
ECHO ****************************
%NDC6%\Bin\dcc32.exe -B -M -DBCB -N..\..\C6 -U..\..\C6 -H -W -Z dclIndyProtocols60.dpk -$d-l-
if errorlevel 1 goto enderror

%NDC6%\Bin\dcc32.exe -B -M -DBCB -N..\..\C6 -U..\..\C6 -H -W -Z /JPHN dclIndyProtocols60.dpk -$d-l-
REM ***************************************************
REM Create .LIB file
REM ***************************************************
echo Creating dclIndyProtocols60.LIB file, please wait...
..\LspFix dclIndyProtocols60.lsp
%NDC6%\bin\tlib.exe dclIndyProtocols60.lib /P32 @dclIndyProtocols60.lsp
Move *.lib ..\..\C6 >> nul
Move *.hpp ..\..\C6 >> nul
Move *.obj ..\..\C6 >> nul
Move *.bpl ..\..\C6 >> nul
Move *.dcp ..\..\C6 >> nul
if exist ..\C6\dclIndyProtocols60.bak del ..\C6\dclIndyProtocols60.bak >nul

CD ..
CD ..
ECHO.
goto ok
:ok
ECHO Adding compile_ok file
if exist compile_fail del compile_fail
ECHO Compile_OK > compile_ok
goto end
:enderror
CD ..
CD ..
ECHO Compile_Failed > compile_fail
del compile_run >> nul
ECHO ! Error occured 
:end
del compile_run >> nul

goto endok
:enderror
call clean
echo Error!
:endok
