@echo off

set PREP=n

goto begin

:Usage
echo Usage: tc file
goto end

:nofile
echo %NAME%: no such file
goto end

:preserve
echo preserving %1.s
goto end

:error
if exist TXPP.ERR del TXPP.ERR
if exist TXTRN.ERR del TXTRN.ERR
if exist TXCG.ERR del TXCG.ERR
echo terminating.
goto end

:begin
if exist TXPP.ERR del TXPP.ERR
if exist TXTRN.ERR del TXTRN.ERR
if exist TXCG.ERR del TXCG.ERR

if x%1 == x goto Usage

if not x%1 == x-P goto noP
set PREP=y
shift
:noP

if x%1 == x goto Usage

set NAME=%1.t
if not exist %NAME% goto nofile
if exist %1.s goto preserve

if %PREP% == n goto noprep
..\compiler\txpp <%NAME% >%1.pp
if exist TXPP.ERR goto error
..\compiler\txx ..\build\txtrn.tco <%1.pp >%1.tco
if exist TXTRN.ERR goto error
del %1.pp
..\compiler\txx ..\build\txcg86t.tco <%1.tco >%1.s
if exist TXCG.ERR goto error
del %1.tco
if errorlevel == 1 goto error
goto endprep

:noprep
..\compiler\txx ..\build\txtrn.tco <%NAME% >%1.tco
if exist TXTRN.ERR goto error
..\compiler\txx ..\build\txcg86t.tco <%1.tco >%1.s
if exist TXCG.ERR goto error
del %1.tco
if errorlevel == 1 goto error

:endprep

tasm /t /ml %1.s
del %1.s
if errorlevel == 1 goto error

tlink %1.obj,%1.exe,nul,..\native\libtx.lib
del %1.obj

:end
set NAME=
set PREP=
