@echo off

if exist %1.cc goto cppfile
if exist %1.c  goto cfile
goto error_none

:cfile
echo --compiling c-file '%1.c'
gcc -m68332 -I%gcc%\m68k\include -I%mc%\include -ansi -pedantic -c -msoft-float %1.c 
goto link

:cppfile
if exist %1.c goto error_both
echo --compiling cpp-file '%1.cc'
gcc -m68332 -I%gcc%\m68k\include -I%mc%\include -ansi -pedantic -c -msoft-float %1.cc 

:link
echo --linking
ld  -L%mc%\lib -T%mc%\ldfiles\robi-ram.ld -o %1.I   %1.o -lmym -lmyc -lmygcc -lrobi 

echo --object-copy
objcopy -O srec %1.I %1.hex

echo --compressing '%1.hex'
srec2bin %1.hex >NUL

if exist %1.o del %1.o
if exist %1.i del %1.i
goto end

:error_both
echo Error: '%1.c' and '%1.cc' both exist, please check!
goto end

:error_none
echo Error: '%1.c' or '%1.cc' not found, please check!

:end
@echo on
