@echo off
cd %~dp0

rem # make sure seabios is at the expected location
if not exist coreboot\payloads\external\SeaBIOS\seabios-0.6.2 (
   echo.
   echo.
   echo === Cound not find coreboot\payloads\external\SeaBIOS\seabios-0.6.2 ===
   echo.
   pause
   exit 1
   )

rem # make sure msys can be found from environment variable %msys_for_coreboot%
if not exist %msys_for_coreboot%\bin (
   echo.
   echo.
   echo ------------------------------------------------
   echo =         Unable to find msys directory        =
   echo =  Set environment variable msys_for_coreboot  =
   echo ------------------------------------------------
   echo.
   pause
   exit 1
   )

rem # Set the bash startup dirctory (need a better way, for now pass it to etc/profile).
set COREBOOT_PROJECT_DIR=%cd%\coreboot\payloads\external\SeaBIOS\seabios-0.6.2
cd %COREBOOT_PROJECT_DIR%
rem # convert windows path format to msys path format (example, c:\tmp becomes /c/tmp)
set COREBOOT_PROJECT_DIR=%COREBOOT_PROJECT_DIR:\=/%
set COREBOOT_PROJECT_DIR=%COREBOOT_PROJECT_DIR::=%
set COREBOOT_PROJECT_DIR=/%COREBOOT_PROJECT_DIR%

rem # manually set locations for cross compiler component (gcc444 or gcc452)
set xgccpath=/gcc452/xgcc/bin

echo # elf32-i386 toolchain> .xcompile
echo AS:=%xgccpath%/i386-elf-as>> .xcompile 
echo CC:=%xgccpath%/i386-elf-gcc -Wa,--divide -fno-stack-protector -Wl,--build-id=none>> .xcompile 
echo CPP:=%xgccpath%/i386-elf-cpp>> .xcompile
echo AR:=%xgccpath%/i386-elf-ar>> .xcompile
echo LD:=%xgccpath%/i386-elf-ld>> .xcompile 
echo STRIP:=%xgccpath%/i386-elf-strip>> .xcompile
echo NM:=%xgccpath%/i386-elf-nm>> .xcompile
echo OBJCOPY:=%xgccpath%/i386-elf-objcopy>> .xcompile
echo OBJDUMP:=%xgccpath%/i386-elf-objdump>> .xcompile
echo.>> .xcompile
echo # native toolchain>> .xcompile
echo HOSTCC:=gcc>> .xcompile


rem # add tools directory to the path (for iasl.exe)
set path=%msys_for_coreboot%\tools

rem # add python to the path (needed to build seabios)
set path=%path%;%msys_for_coreboot%\tools\Python27

rem # optional: add your subversion path so that the svnversion command will work
rem #

rem # start msys build environment
%msys_for_coreboot%\msys.bat


