@echo off
echo BUILD - Build Maximus 1.02 With Microsoft C 5.10 for MS-DOS.
echo.
echo Testing environment...
set _T=This is a string to test space in the environment
if not "%_T%"=="This is a string to test space in the environment" goto DIE

set _T=
if "%lib%"=="" echo Missing LIB environment variable!
if "%lib%"=="" set _L=1

if "%include%"=="" echo Missing INCLUDE environment variable!
if "%include%"=="" set _I=1

if "%_L%"=="1" goto L2

for %%i in (%lib%) do if exist %%i\MLIBCE.LIB set _F=A
if not "%_F%"=="A" echo Missing file "MLIBCE.LIB" in LIB path!
if not "%_F%"=="A" set _L=1

for %%i in (%lib%) do if exist %%i\SETARGV.OBJ set _V=%%i
if "%_V%"=="" echo Missing file "SETARGV.OBJ" in LIB path!
if "%_V%"=="" set _L=1

:L2
for %%i in (%path%) do if exist %%i\MAKE.EXE set _F=B
if not "%_F%"=="B" echo Missing file "MAKE.EXE" in PATH!
if not "%_F%"=="B" set _P=1

for %%i in (%path%) do if exist %%i\CL.EXE set _F=C
if not "%_F%"=="C" echo Missing file "CL.EXE" in PATH!
if not "%_F%"=="C" set _P=1

for %%i in (%path%) do if exist %%i\LINK.EXE set _F=D
if not "%_F%"=="D" echo Missing file "LINK.EXE" in PATH!
if not "%_F%"=="D" set _P=1

for %%i in (%path%) do if exist %%i\MASM.EXE set _F=E
if not "%_F%"=="E" echo Missing file "MASM.EXE" in PATH!
if not "%_F%"=="E" set _P=1

for %%i in (%path%) do if exist %%i\LIB.EXE set _F=F
if not "%_F%"=="F" echo Missing file "LIB.EXE" in PATH!
if not "%_F%"=="F" set _P=1

if not exist slib\*.c echo Missing SLIB directory!
if not exist slib\*.c set _M=1
if not exist prot\*.c echo Missing PROT directory!
if not exist prot\*.c set _M=1
if not exist max\*.c  echo Missing MAX directory!
if not exist max\*.c  set _M=1

if not exist slibdos.mak echo Missing SLIBDOS.MAK!
if not exist slibdos.mak set _M=1
if not exist protdos.mak echo Missing PROTDOS.MAK!
if not exist protdos.mak set _M=1
if not exist maxdos.mak  echo Missing MAXDOS.MAK!
if not exist maxdos.mak  set _M=1
if not exist movlr.lnk   echo Missing MOVLR.LNK!
if not exist movlr.lnk   set _M=1

if "%_L%%_I%%_P%%_M%"=="" goto L3
:DIE
echo.
echo The build has been aborted due to the above error(s)!
set _T=
set _L=
set _I=
set _P=
set _M=
goto END

:L3
echo Creating working directories...
for %%i in (slib prot max) do if not exist %%i\r\nul md %%i\r
if not exist slib\r\m\nul md slib\r\m

set _C=%cl%
set cl=
set _M=%masm%
set masm=
set _L=%link%
set link=

echo Building support library...
cd slib
make model=M mode=R clib=%_V% ..\slibdos.mak
cd ..
if errorlevel 1 goto OOPS

echo Building protocol modules...
cd prot
make model=M mode=R ..\protdos.mak
cd ..
if errorlevel 1 goto OOPS

echo Building maximus program...
cd max
make model=M mode=R ..\maxdos.mak
cd ..
if errorlevel 1 goto OOPS

echo.
echo Build completed successfully!
goto DONE

:OOPS
echo.
echo Fatal error in Build!  Correct problem and restart!

:DONE
set cl=%_C%
set _C=
set masm=%_M%
set _M=
set link=%_L%
set _L=

:END
set _F=
set _V=
echo.
