@echo off
echo.
echo   Run-Time Library Build Script                 (C) 2000 vpascal.com
echo.
echo   This file builds the VP21 RTL, including the OS/2 and Win32 specific
echo   units and the Turbo Vision Library files.
echo.
echo   Under NT, it must be run in a separate session ("cmd.exe /e:2048") to
echo   make environment space available; in Win95/98, run "command.com /e:2048".
echo.
pause

rem ********************************************************************
rem vpascal=1 - compile private sources (vpascal.com use only)
rem ********************************************************************

rem if debug=1, display additional lines and pause after each compile
set debug=0
set vpbase={BASEDIR}
set vpopt=-$D- -$I- -$S- -$V- -$X+ -$SmartLink+
if exist "%vpbase%\bin.os2\vpc.exe" goto gettarget

echo   Cannot execute; VPBase setting is probably incorrect.  Please modify this
echo   script to contain the correct location of your VP installation.
echo.
goto end

rem ********************************************************************
rem The following settings should work without adjustment:
rem ********************************************************************

:GetTarget
if "%1"=="D32" goto DPMI32Target
if "%1"=="d32" goto DPMI32Target
if "%1"=="lnx" goto LinuxTarget
if "%1"=="LNX" goto LinuxTarget
if "%1"=="OS2" goto Os2Target
if "%1"=="os2" goto Os2Target
if "%1"=="W32" goto Win32Target
if "%1"=="w32" goto Win32Target

rem ********************************************************************
rem Display error message if target OS is not specified
rem ********************************************************************

echo * Run with OS2 parameter to build the OS/2 RTL
echo * Run with W32 parameter to build the Win32 RTL
echo * Run with D32 parameter to build the DPMI RTL
echo * Run with LNX parameter to build the Linux RTL
goto End

rem ********************************************************************
rem Determine current OS and run appropriate compiler
rem ********************************************************************

:DPMI32Target
  set TARGET=D32
goto CheckOS

:LinuxTarget
  set TARGET=LNX
goto CheckOS

:Os2Target
  set TARGET=OS2
goto CheckOS

:Win32Target
  set TARGET=W32

:CheckOS
  %vpbase%\bin.os2\vpc.exe 1>nul 2>&1
  if errorlevel 255 goto IsWin32
  if errorlevel 254 goto IsOs2
goto IsWin32

:IsOs2
  set PLATFORM=OS2
goto Continue

:IsWin32
  set PLATFORM=W32

rem ********************************************************************
rem Set up environment variables with path and option settings
rem ********************************************************************

:Continue
  set vpc=
  set vpcparams=
  set vpprivsrc=%master%\private
  set vpprivrtl=%vpprivsrc%\rtl
  set vppubsrc=%vpbase%\source
  set vppubrtl=%vppubsrc%\rtl
  if .%vpascal% == .1 set vpsrctv=%vpprivsrc%\tv
  if not .%vpascal% == .1 set vpsrctv=%vppubsrc%\tv
  set vpbin=%vpbase%\bin.%platform%
  set vplib=%vpbase%\lib.%target%;%vpbase%\units.%target%

  set vpunits=
  if .%vpascal% == .1 set vpunits=%vpprivrtl%
  set vpunits=%vpunits%;%vppubrtl%;%vpsrctv%;%vpbase%\units.%target%;%vppubsrc%\%%p

  if .%debug% == .1 goto NotQuiet
  set vpopt=-Q %vpopt%
:NotQuiet

  set vpres=%vpbase%\res.%target%
  set vpinc=%vppubrtl%
  if .%vpascal% == .1 set vpinc=%vpprivrtl%;%vpinc%
  set vpout=%vpbase%\units.%target%

  set vpalias=@%vpbase%\source\rtl\alias.cfg

if not .%debug% == .1 goto :noSetDis
  echo.
  echo   DEBUG MODE: Please check the environment setup:
  echo   vpbase=%vpbase%
  echo   vpprivsrc=%vpprivsrc%
  echo   vpprivrtl=%vpprivrtl%
  echo   vppubsrc=%vppubsrc%
  echo   vppubrtl=%vppubrtl%
  echo   vpsrctv=%vpsrctv%
  echo   vpbin=%vpbin%
  echo   vplib=%vplib%
  echo   vpunits=%vpunits%
  echo   vpres=%vpres%
  echo   vpinc=%vpinc%
  echo   vpout=%vpout%
  pause
:noSetDis

if "%target%" == "LNX" set vpcparams=-CW:lnx:LINUX
if "%target%" == "D32" set vpcparams=-CW:D32:DPMI32
if "%target%" == "OS2" set vpcparams=-CO
if "%target%" == "W32" set vpcparams=-CW

set vpcparams=%vpcparams% "-L%vplib%" "-O%vpout%" "-R%vpres%" "-U%vpunits%" "-I%vpinc%" "%vpalias%"

if not .%debug% == .1 goto noOptDisp
  echo.
  echo   DEBUG MODE: Please check the compiler setup:
  echo   vpcparams=%vpcparams%
  echo   vpopt=%vpopt%
  pause
:noOptDisp

set path=%vpbin%;%path%
if .%platform% == .OS2 set beginlibpath=%vpbin%

set vpc="%vpbin%\vpc.exe" -B %vpcparams% %vpopt%

rem ********************************************************************
rem Execute the build
rem ********************************************************************

cd %vpbase%

echo.
echo   ** Building Run-Time Library **
echo.
  %vpc% "%vppubrtl%\bldrtl.pas"
echo.
echo   ** Run-Time Library Built    **
echo.
if .%debug% == .1 pause

echo.
echo   ** About to build Turbo Vision library **
echo.
  %vpc% "%vpsrctv%\buildtv.pas"
echo.
echo   ** Turbo Vision Library Built          **
echo.

rem Delete unneeded temporary files
  del "%vpbase%\units.%target%\*.lnk"
  del "%vpbase%\units.%target%\buildtv.*"
  del "%vpbase%\units.%target%\bldrtl.*"

echo   Compilation complete.  Please check for error messages above.
echo.
:end

cd "%vpbase%\source\rtl"
