@echo off
if x%1 == xall goto makAll
if x%1 == xALL goto makAll
if x%1 == xAll goto makAll

set __MODEL=%1
if x%__MODEL% == x set __MODEL=%MODEL%
if x%__MODEL% == x goto errM

set ERRLIST=
if exist errlist set ERRLIST=Yes

..\..\bin\rm -fs *.obj errlist compile.tmp

call mkdynsrc.bat

if exist foreach.com goto haveFE
cc foreach.xc -fop _MICROC_=1 NDEBUG=1
if errorlevel 1 goto ende
if not exist foreach.com goto err1
:haveFE

echo Compiling memory model %__MODEL%
type compile.ccc >compile.tmp
type dyn_src >>compile.tmp
if x%ERRLIST% == x .\foreach /v compile.tmp tcc +tcc.cfg -m%__MODEL% -DNDEBUG=1 -d -r -O -Z -c %%name:
if not x%ERRLIST% == x .\foreach compile.tmp tcc +tcc.cfg -m%__MODEL% -DNDEBUG=1 -d -r -O -Z -c %%name: >errlist
if exist errlist copy errlist errlist.%__MODEL% >nul

if errorlevel 1 goto ende

if exist objlist.txt del objlist.txt
for %%x in (*.obj) do echo +%%x & >> objlist.txt
echo , suppl_%__MODEL%.lst >> objlist.txt

if exist suppl_%__MODEL%.lib del suppl_%__MODEL%.lib >nul
tlib suppl_%__MODEL%.lib /C @objlist.txt

..\..\bin\rm -fs *.obj compile.tmp
goto ende

:makAll
for %%a in (t s m c l h) do call %0 %%a
goto ende

:err1
echo Failed to make FOREACH.COM (from FOREACH.XC)
echo To compile FOREACH you need Micro-C.
goto ende

:errM
echo Script to compile the supplemental library with Turbo C
echo Useage: %0 memory_model
echo -or- define the environment variable MODEL with the memory_model
echo -or- call	%0 all
echo to create the libraries for all memory models

:ende
set __MODEL=
set ERRLIST=
