rem @echo off
if "%MPLIB%x" == "x" set MPLIB=C:\METAPOST
if "%TEXFONTS%x" == "x" set TEXFONTS=.;c:/emtex/tfm!
if "%MPTEX%x" == "x" set MPTEX=tex

%MPLIB%\newer %1 %2
if errorlevel 1 goto older
goto succex
:older
%MPLIB%\mptotex %1 mpx__tmp.tex 
if errorlevel 1 goto err1

%MPTEX% \batchmode\input mpx__tmp > NUL
if errorlevel 1 goto err2

%MPLIB%\dvitomp mpx__tmp.dvi %2 > mpx__tmp.log
if errorlevel 1 goto err3

DEL mpx__tmp.*
goto succex

:err1
echo Command failed: %MPLIB%\mptotex %1
goto errorex

:err2
echo Command failed: tex mpx__tmp.tex. See mpx__tmp.log
goto errorex

:err3
echo Command failed: %MPLIB%\dvitomp mpx__tmp.dvi
type mpx__tmp.log

:errorex
if exist %2 move %2 mpx__tmp.mpx
exit 1

:succex