@echo off
if "%1" == "" goto usage
goto checklib

:usage
echo usage: mkdll BC3_library_directory
echo example: mkdll c:\bc3\lib
goto done

:checklib
if exist %1\emu.lib goto linkdll
echo mkdll error: cannot find %1\emu.lib - please check library argument
goto usage

:linkdll
if not exist .\bcrtdll3.dll goto dolink1
del bcrtdll3.dll
:dolink1
echo linking bcrtdll3.dll...

echo bcrtobj.lib emu286.lib >__tmp.lnk
echo bcrtdll3.dll /c /C /Twd /s /n -L. >>__tmp.lnk
echo nul >>__tmp.lnk
echo %1\emu.lib %1\mathl.lib phapi.lib bcl286.lib >>__tmp.lnk
echo bcrtdll3.def >>__tmp.lnk

tlink @__tmp.lnk >nul
if errorlevel 1 goto linkerr
if not exist bcrtdll3.dll goto linkerr
del __tmp.lnk

:doimplib
implib bcrtdll.lib bcrtdll3.def >nul
if not exist bcrtdll.lib goto impliberr

:docopy
echo copying DLL to the RUN286\BIN directory
if not exist ..\..\bin\run286.exe goto nocopy
copy bcrtdll3.dll ..\..\bin
if not exist ..\..\bin\bcrtdll3.dll goto nocopy
echo Borland C++ 3.1 CRT DLL installation completed
goto done

:nocopy
echo Sorry, COPY failed.  Please make sure BCRTDLL3.DLL is on your LIBPATH,
echo or in the \RUN286\BIN directory.
goto done

:impliberr
echo mkdll error: IMPLIB failed to create the DLL import library.
echo Please make sure all necesary files are present...
goto done

:linkerr
echo mkdll error: DLL link failed.
echo Please make sure all necesary files are present...
goto done

:done
