@rem Some project-building stuff...
@rem Project build batch script

@set projname=Pinch
@set masmdir=c:\masm32
@set build_rc=0
@set app_run_on_build=0
@set debug=0

@echo off
@cls
@break on

if %debug% == 0 goto no_debug_print
echo Building %projname% [DEBUG]...
goto debug_print
:no_debug_print
echo Building %projname%...
:debug_print

time /t
echo ---------------------------------------
echo.
echo.

if exist %projname%.exe del %projname%.exe
if exist %projname%.exe goto err_common

if %build_rc% == 0 goto no_rc
rem Build resources...
brcc32.exe -32 -fo"%projname%.res" "%projname%.rc" >rc_err.txt
if not exist %projname%.res goto err_brcc

rem Link resources...
%masmdir%\bin\cvtres.exe /NOLOGO /MACHINE:ix86 /OUT:"%projname%_rc.obj" "%projname%.res" >rc_c_err.txt
if not exist %projname%_rc.obj goto err_cvtres

:no_rc

@set dodebuglnk=/RELEASE
if %debug% == 0 goto no_debug
@set dodebug=/DDEBUG 
@set dodebuglnk=/DEBUG
:no_debug

rem Compile...
%masmdir%\bin\ml /nologo %dodebug% /c /coff /Cp /WX /I%masmdir%\include\ /I%masmdir%\com\include\ %projname%.asm >ml_err.txt
if not exist %projname%.obj goto err_ml


if %build_rc% == 0 goto no_rc_link
rem Link with resources...
@set vlink=%projname%_rc.obj
goto rc_link
:no_rc_link
rem Link...
@set vlink=
:rc_link
%masmdir%\bin\link %dodebuglnk% /NOLOGO /SUBSYSTEM:WINDOWS /LIBPATH:%masmdir%\lib %projname%.obj %vlink% >l_err.txt

if exist %projname%.obj del %projname%.obj
if exist %projname%.exe goto ok

:err_link
echo -LINKER- Reported:
type l_err.txt
goto err_common

:err_brcc
echo -RESOURCE COMPILER- Reported:
type rc_err.txt
goto err_common

:err_cvtres
echo -RESOURCE LINKER- Reported:
type rc_c_err.txt
goto err_common

:err_ml
echo -COMPILER- Reported:
type ml_err.txt

:err_common
echo.
echo.
pause
goto end

:ok
if %app_run_on_build%==0 goto end
%projname%.exe

:end
rem Clean up...
if exist ml_err.txt del ml_err.txt
if exist l_err.txt del l_err.txt
if exist rc_c_err.txt del rc_c_err.txt
if exist rc_err.txt del rc_err.txt
if exist %projname%.res del %projname%.res
if exist %projname%_rc.obj del %projname%_rc.obj
if exist %projname%.ilk del %projname%.ilk
if exist %projname%.pdb del %projname%.pdb

@echo on
