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

:usage
echo usage: mkdll BC4_library_directory
echo example: mkdll c:\bc4\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 .\bcrtdll4.dll goto dolink1
del bcrtdll4.dll
:dolink1
echo linking bcrtdll4.dll...

echo bcrtobj.lib fpdmy.obj >__tmp.lnk
echo bcrtdll4.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 bcrtdll4.def >>__tmp.lnk

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

:doimplib
implib bcrtdll.lib bcrtdll4.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 bcrtdll4.dll ..\..\bin
if not exist ..\..\bin\bcrtdll4.dll goto nocopy
echo Borland C++ 4.0 CRT DLL installation completed
goto done

:nocopy
echo Sorry, COPY failed.  Please make sure BCRTDLL4.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
