@echo off
echo Compiling mkfirm ...

REM ------------------------------------------
REM Mkfirm Saturn loader.
cd loader
REM Add SaturnOrbit to environment.
set pathtmp=%path%
set C_INCLUDE_PATH_TMP=%C_INCLUDE_PATH%
set CPLUS_INCLUDE_PATH_TMP=%CPLUS_INCLUDE_PATH%

IF NOT EXIST C:\Saturn~1\SET_ELF.BAT goto satorb_alternate

REM Set SaturnOrbit environment from normal installation directory (C:\SaturnOrbit\)
COPY C:\Saturn~1\SET_ELF.BAT .\TMP.BAT
goto satorb_end

:satorb_alternate
REM Set SaturnOrbit environment from alternate installation directory (D:\dev\SaturnOrbit\)
REM Useful when your C: drive is nearly full.
COPY D:\dev\Saturn~1\SET_ELF.BAT .\TMP.BAT
goto satorb_end

:satorb_end
IF NOT EXIST TMP.BAT exit
CALL TMP.BAT
DEL TMP.BAT

REM Compile.
del /Q loader.bin
sh-elf-gcc -Wall -Werror -m2 -Os -fomit-frame-pointer -nostartfiles crt0.S mf_loader.c -Xlinker -T -Xlinker bart.link -o loader.bin

REM Remove SaturnOrbit from environment (needed, because it interferes with MinGW environment).
set path=%pathtmp%
set C_INCLUDE_PATH=%C_INCLUDE_PATH_TMP%
set CPLUS_INCLUDE_PATH=%CPLUS_INCLUDE_PATH_TMP%
cd ..


REM ------------------------------------------
REM Mkfirm executable.
echo Compiling mkfirm PC Executable
..\bin2c.exe IP_BIN\ip.bin loader\loader.bin data.c
gcc -c data.c
gcc -c ..\..\satcom_lib\sc_common.c
gcc -c mkfirm.c
gcc -o ..\mkfirm sc_common.o mkfirm.o data.o
del /Q sc_common.o mkfirm.o data.o

