echo off
rem This batch file prepares a shell for use with the Dreamcast development tools.

echo %0: Setting environment variables..

rem Set the location of the Katana installation.
rem Default: C:\Katana

if not !%KATANA_ROOT%==%KATANA_ROOT%! goto katanarootalreadyset
SET KATANA_ROOT=Z:\KATANA\R9
:katanarootalreadyset
if !%KATANA_ROOT%==%KATANA_ROOT%! goto error_nokatanaroot

rem Check for the existence of a compatible shell.  At this time, only
rem Microsoft-designed COMMAND.COM is acceptable.

ver | find "Windows"
if errorlevel 1 goto error_notcompatibleshell

rem Add gmake, Hitachi, and GNU compiler tools to the current path.
SET PATH=%PATH%;%KATANA_ROOT%\Utl\Dev\Make;%KATANA_ROOT%\Utl\Dev\Hitachi;%KATANA_ROOT%\Utl\Dev\Gnu\Bin

rem Verify the existence of gmake.

gmake -v > chk_2397.tmp
if not exist chk_2397.tmp goto error_nonmake
del chk_2397.tmp

rem Set include and library directories used by Hitachi and GNU compiler tools.
rem Edit these lines to change the default installation.

SET SHC_LIB=%KATANA_ROOT%\Utl\Dev\Hitachi
SET SHC_INC=%KATANA_ROOT%\Include
SET SHCPP_LIB=%SHC_LIB%
SET SHCPP_INC=%SHC_INC%
SET CYGROOT=%KATANA_ROOT%\Utl\Dev\Gnu
SET GCC_EXEC_PREFIX=%CYGROOT%\lib\gcc-lib\
SET CYGREL=progressive-97r2a

rem Verify Hitachi and GNU tool paths.

if !%SHC_LIB%==%SHC_LIB%! goto error_toolpathsnotset
if !%SHC_INC%==%SHC_INC%! goto error_toolpathsnotset
if !%SHCPP_LIB%==%SHCPP_LIB%! goto error_toolpathsnotset
if !%SHCPP_INC%==%SHCPP_INC%! goto error_toolpathsnotset
if !%CYGROOT%==%CYGROOT%! goto error_toolpathsnotset
if !%GCC_EXEC_PREFIX%==%GCC_EXEC_PREFIX%! goto error_toolpathsnotset
if !%CYGREL%==%CYGREL%! goto error_toolpathsnotset

if not exist %SHC_LIB%\nul goto error_toolpathsnotset
if not exist %SHC_INC%\nul goto error_toolpathsnotset
if not exist %SHCPP_LIB%\nul goto error_toolpathsnotset
if not exist %SHCPP_INC%\nul goto error_toolpathsnotset
if not exist %CYGROOT%\nul goto error_toolpathsnotset
if not exist %GCC_EXEC_PREFIX%nul goto error_toolpathsnotset

rem Set location of temporary files created during compilation.
rem These files (.tmp) may be left behind when a compile is interrupted.
rem Default:  SET SHC_TMP=.

SET SHC_TMP=.
SET SHCPP_TMP=%SHC_TMP%

rem Set default library for Hitachi C/C++.
rem Default: SET HLNK_LIBRARY1=C:\Katana\Lib\sh4nlfzz.lib

SET HLNK_LIBRARY1=%KATANA_ROOT%\Lib\sh4nlfzz.lib

rem Verify the existence of HLNK_LIBRARY1

if !%HLNK_LIBRARY1%==%HLNK_LIBRARY1%! goto error_hlnknotset
if not exist %HLNK_LIBRARY1% goto error_hlnknotset

rem Verify the existence of the Hitachi tools.

shc > chk_2397.tmp
if not exist chk_2397.tmp goto error_cmd
del chk_2397.tmp

gcc -v > chk_2397.tmp
if not exist chk_2397.tmp goto error_cmd
del chk_2397.tmp

echo Cygnus GNUPro2.0 %CYGREL%

goto success

rem -------------------------------------------------------------------
rem ! Error handling
rem -------------------------------------------------------------------

:error_nokatanaroot
echo Error: The path specified by the KATANA_ROOT variable does not
echo exist.  Please edit SETPATHS.BAT.
goto done

:error_notcompatibleshell
echo Error: The default shell is not compatible with SetPaths.bat.
echo Please make COMMAND.COM your default shell and try again.
goto done

:error_nonmake
echo Error: GMAKE could not be found on the default path.  Please
echo edit SETPATHS.BAT.
goto done

:error_cmd
echo Error: The Hitachi and Gnu command line tools could not be found.
echo Please edit SETPATHS.BAT.
goto done

:error_toolpathsnotset
echo Error: Environmental variables required by the SH-C and GCC compilers
echo could not be set, or do not point to valid directories.  Please
echo edit SETPATHS.BAT.
goto done

:error_hlnknotset
echo Error: Environmental variable HLNK_LIBRARY1 is required and
echo could not be determined, or target file does not exist.  Please
echo edit SETPATHS.BAT.
goto done

:success
echo.
echo Paths successfully set and verified.
:done

