@echo off
REM ==================================================================
REM         set_dc2.bat                       Version 2.11.01
REM                  Copyright SEGA Enterprises Ltd.
REM                    Program by Tadashi Jokagi.
REM
REM  update 2.11.00 : SOJ DTS : support gmake.exe / SHC Ver6.0 
REM ==================================================================
:START
set MY_NAME=%0
set SET_DC2_VER=2.11.01

:ST_DEF
set DEF_DC_SDK_ROOT_DIR=C:\dc_sdk2
set DEF_DC_INC_DIR=%DEF_DC_SDK_ROOT_DIR%\include
set DEF_DC_LIB_DIR=%DEF_DC_SDK_ROOT_DIR%\lib
set DEF_DC_SAMPLE_DIR=%DEF_DC_SDK_ROOT_DIR%\sample
set DEF_DC_UTL_DIR=%DEF_DC_SDK_ROOT_DIR%\utl
set DEF_DC_DEV_ENV=hms

set NOW_DC_SDK_ROOT_DIR=%DEF_DC_SDK_ROOT_DIR%
set NOW_DC_INC_DIR=%DEF_DC_INC_DIR%
set NOW_DC_LIB_DIR=%DEF_DC_LIB_DIR%
set NOW_DC_SAMPLE_DIR=%DEF_DC_SAMPLE_DIR%
set NOW_DC_UTL_DIR=%DEF_DC_UTL_DIR%
set NOW_DC_DEV_ENV=%DEF_DC_DEV_ENV%
set OUT_FL_NM=

set VERBOSE=off
set ADD_PATH=off
set SOJSDK_COMPATIBLE=on
set USE_COMPILER=SHC

:ANLZ_OPT
set ARG=%1
if "%ARG%" == ""  goto END_ANLZ
shift
if "%ARG%" == "-G" goto ST_DBG_MODE
if "%ARG%" == "-h" goto SW_USAGE
if "%ARG%" == "-H" goto SW_USAGE
if "%ARG%" == "-o" goto ST_OT_FL
if "%ARG%" == "-v" goto ST_VERBOSE
if "%ARG%" == "-V" goto ST_VERBOSE
if "%ARG%" == "-j" goto ST_SOJSDK_COMPATIBLE
if "%ARG%" == "--add-path" goto ST_ADD_PATH
if "%ARG%" == "--debug-this-program" goto ST_DBG_MODE
if "%ARG%" == "--old-soj-sdk-compatible" goto ST_SOJSDK_COMPATIBLE
if "%ARG%" == "--output-file" goto ST_OT_FL
if "%ARG%" == "--copyright" goto SW_COPYRIGHT
if "%ARG%" == "--help" goto SW_USAGE
if "%ARG%" == "--verbose" goto ST_VERBOSE
if "%ARG%" == "--version" goto SW_VER
if "%ARG%" == "-SHC_AD"     goto SW_COMP
if "%ARG%" == "-6"          goto SW_COMP
if "%ARG%" == "--shc-v6ad"  goto SW_COMP

set RET_LABEL=ST_SDK_DIR
set NOW_DC_SDK_ROOT_DIR=%ARG%
goto BUILD_NOW_ENV

:ST_SDK_DIR
set NOW_DC_SDK_ROOT_DIR=%ARG%
goto ANLZ_OPT

:ST_VERBOSE
set VERBOSE=on
goto ANLZ_OPT

:ST_SOJSDK_COMPATIBLE
set SOJSDK_COMPATI=on
goto ANLZ_OPT

:ST_ADD_PATH
set ADD_PATH=on
goto ANLZ_OPT

:ST_DBG_MODE
echo on
goto ANLZ_OPT

:ST_OT_FL
set OUT_FL_NM=%1
shift
goto ANLZ_OPT

:SW_COMP
set USE_COMPILER=SHC_AD
goto ANLZ_OPT

:BUILD_NOW_ENV
if "%NOW_DC_SDK_ROOT_DIR%" == "" set NOW_DC_SDK_ROOT_DIR=%DEF_DC_SDK_ROOT_DIR%
if "%VERBOSE%" == "on" echo Set Dreamcast SDK root directory to %NOW_DC_SDK_ROOT_DIR%
set NOW_DC_INC_DIR=%NOW_DC_SDK_ROOT_DIR%\include

set NOW_DC_LIB_DIR=%NOW_DC_SDK_ROOT_DIR%\lib
set NOW_DC_SAMPLE_DIR=%NOW_DC_SDK_ROOT_DIR%\sample
set NOW_DC_UTL_DIR=%NOW_DC_SDK_ROOT_DIR%\utl
goto %RET_LABEL%

rem end of analyze
:END_ANLZ

rem Setting of environment variable
:ST_ENV
set DC_SDK_ROOT_DIR=%NOW_DC_SDK_ROOT_DIR%
set DC_INC_DIR=%NOW_DC_INC_DIR%
set DC_LIB_DIR=%NOW_DC_LIB_DIR%
set DC_SAMPLE_DIR=%NOW_DC_SAMPLE_DIR%
set DC_UTL_DIR=%NOW_DC_UTL_DIR%
set DC_DEV_ENV=%NOW_DC_DEV_ENV%
::: for GNU make :::
set KATANA_ROOT=%DC_SDK_ROOT_DIR%

if "%USE_COMPILER%" == "SHC_AD" goto SET_SHC_AD

set SHC_LIB=%DC_UTL_DIR%\dev\hitachi
set SHC_TMP=%TEMP%
set SHC_INC=%DC_UTL_DIR%\dev\hitachi\include;%DC_INC_DIR%
set HLNK_LIBRARY1=%DC_LIB_DIR%\SH4NLFZN.LIB
goto END_SHC_AD

:SET_SHC_AD
set SHC_LIB=%DC_UTL_DIR%\dev\hitachi_ad
set SHC_TMP=%TEMP%
set SHC_INC=%DC_UTL_DIR%\dev\hitachi_ad\include;%DC_INC_DIR%
set HLNK_LIBRARY1=%DC_LIB_DIR%\hitachi\SH4NLFZN.LIB
SET ADRIA_CMD_CONFIGFILE_C=%SHC_LIB%\we2_c_shcross.cfg.ver3

:END_SHC_AD
set CYGROOT=%DC_UTL_DIR%\dev\gnu
set GCC_EXEC_PREFIX=%CYGROOT%\lib\gcc-lib\
set CYGREL=progressive-97r2a

if "%SOJSDK_COMPATIBLE%" == "on" set SEGALIB_DIR=%DC_SDK_ROOT_DIR%
if "%SOJSDK_COMPATIBLE%" == "on" set SEGALIB_INC_DIR=%DC_INC_DIR%
if "%USE_COMPILER%" == "SHC_AD" goto SEG_SHC_AD
if "%SOJSDK_COMPATIBLE%" == "on" set SEGALIB_LIB_DIR=%DC_LIB_DIR%
goto SED_SHC_AD
:SEG_SHC_AD
if "%SOJSDK_COMPATIBLE%" == "on" set SEGALIB_LIB_DIR=%DC_LIB_DIR%\hitachi
:SED_SHC_AD

set DC_UTL_PATH=%DC_UTL_DIR%\dev\make

if "%USE_COMPILER%" == "SHC_AD" goto AD_SET_PATH
set DC_UTL_PATH=%DC_UTL_PATH%;%DC_UTL_DIR%\dev\hitachi
goto END_SET_PATH 
:AD_SET_PATH
set DC_UTL_PATH=%DC_UTL_PATH%;%DC_UTL_DIR%\dev\hitachi_ad
:END_SET_PATH

set DC_UTL_PATH=%DC_UTL_PATH%;%DC_UTL_DIR%\dev\gnu\bin
set DC_UTL_PATH=%DC_UTL_PATH%;%DC_UTL_DIR%\dev\codewarrior\tools\command_line_tools

if "%VERBOSE%" == "on" if "%ADD_PATH%" == "on" echo Add DC_UTL_PATH to PATH.
if "%ADD_PATH%" == "on" set PATH=%DC_UTL_PATH%;%PATH%

:SW_ENV
if not "%VERBOSE%" == "on" goto SW_ENV_END
set RET_LABEL=SW_ENV_END
goto SW_CUR
:SW_ENV_END

rem output variable to file.
:OT_FILE
if "%OUT_FL_NM%" == "" goto OT_FILE_END
if "%VERBOSE%" == "on" echo Output variable to %OUT_FL_NM%
if exist "%OUT_FL_NM%" del %OUT_FL_NM%
echo DC_SDK_ROOT_DIR=%NOW_DC_SDK_ROOT_DIR%                              >> %OUT_FL_NM%
echo DC_INC_DIR=%NOW_DC_INC_DIR%                                        >> %OUT_FL_NM%
echo DC_LIB_DIR=%NOW_DC_LIB_DIR%                                        >> %OUT_FL_NM%
echo DC_SAMPLE_DIR=%NOW_DC_SAMPLE_DIR%                                  >> %OUT_FL_NM%
echo DC_UTL_DIR=%NOW_DC_UTL_DIR%                                        >> %OUT_FL_NM%
echo DC_UTL_PATH=%DC_UTL_PATH%                                          >> %OUT_FL_NM%
echo DC_DEV_ENV=%DC_DEV_ENV%                                            >> %OUT_FL_NM%
echo SHC_LIB=%SHC_LIB%                                                  >> %OUT_FL_NM%
echo SHC_TMP=%SHC_TMP%                                                  >> %OUT_FL_NM%
echo SHC_INC=%SHC_INC%                                                  >> %OUT_FL_NM%
echo CYGROOT=%CYGROOT%                                                  >> %OUT_FL_NM%
echo GCC_EXEC_PREFIX=%GCC_EXEC_PREFIX%                                  >> %OUT_FL_NM%
echo CYGREL=%CYGREL%                                                    >> %OUT_FL_NM%
echo KATANA_ROOT=%KATANA_ROOT% 	                                        >> %OUT_FL_NM%
if not "%SEGALIB_DIR%" == "" echo SEGALIB_DIR=%SEGALIB_DIR%             >> %OUT_FL_NM%
if not "%SEGALIB_INC_DIR%" == "" echo SEGALIB_INC_DIR=%SEGALIB_INC_DIR% >> %OUT_FL_NM%
if not "%SEGALIB_LIB_DIR%" == "" echo SEGALIB_LIB_DIR=%SEGALIB_LIB_DIR% >> %OUT_FL_NM%
if not  "%ADRIA_CMD_CONFIGFILE_C%" echo ADRIA_CMD_CONFIGFILE_C=%ADRIA_CMD_CONFIGFILE_C% >> %OUT_FL_NM%
:OT_FILE_END
goto EXIT

:SW_USAGE
echo Usage:%MY_NAME% [dc_sdk directory] [option] ...
echo Options:
echo    --add-path   add dc tools path to system path.
echo    --copyright  show copyright this program.
echo -G --debug-this-program
echo                 set debug mode this program.
echo -h --help       show this message.
echo -v --verbose    set verbose mode.
echo -j --old-soj-sdk-compatible
echo                 compatible old soj sdk environment.
echo -o --output-file [file name]
echo                 output variable to file.
echo    --show-current
echo                 show current variable.
echo -6 --shc-v6ad   set SHC Ver6.0AD environment.
echo    --version    show version of this program.
goto exit

:SW_VER
echo %MY_NAME% version %SET_DC2_VER%
goto exit

:SW_COPYRIGHT
echo Copyright (C) 1998-2000 SEGA Enterprises,Ltd.
echo Programmed by Tadashi Jokagi.
goto exit

:SW_CUR
echo DC_SDK_ROOT_DIR=%NOW_DC_SDK_ROOT_DIR%
echo DC_INC_DIR=%NOW_DC_INC_DIR%
echo DC_LIB_DIR=%NOW_DC_LIB_DIR%
echo DC_SAMPLE_DIR=%NOW_DC_SAMPLE_DIR%
echo DC_UTL_DIR=%NOW_DC_UTL_DIR%
echo DC_UTL_PATH=%DC_UTL_PATH%
echo DC_DEV_ENV=%DC_DEV_ENV%
echo SHC_LIB=%SHC_LIB%
echo SHC_TMP=%SHC_TMP%
echo SHC_INC=%SHC_INC%
echo CYGROOT=%CYGROOT%
echo GCC_EXEC_PREFIX=%GCC_EXEC_PREFIX%
echo CYGREL=%CYGREL%
if not "%SEGALIB_INC_DIR%" == "" echo SEGALIB_DIR=%SEGALIB_DIR%
if not "%SEGALIB_INC_DIR%" == "" echo SEGALIB_INC_DIR=%SEGALIB_INC_DIR%
if not "%SEGALIB_LIB_DIR%" == "" echo SEGALIB_LIB_DIR=%SEGALIB_LIB_DIR%
goto %RET_LABEL%

:EXIT
rem remove default parameter.
set DEF_DC_SDK_ROOT_DIR=
set DEF_DC_INC_DIR=
set DEF_DC_LIB_DIR=
set DEF_DC_SAMPLE_DIR=
set DEF_DC_UTL_DIR=
set DEF_DC_DEV_ENV=

rem remove temporary parameter.
set NOW_DC_SDK_ROOT_DIR=
set NOW_DC_INC_DIR=
set NOW_DC_LIB_DIR=
set NOW_DC_SAMPLE_DIR=
set NOW_DC_UTL_DIR=
set NOW_DC_DEV_ENV=%DEF_DC_DEV_ENV%
set OUT_FL_NM=
set SOJSDK_COMPATIBLE=
set ADD_PATH=
set VERBOSE=
set MY_NAME=
set ARG=
set RET_LABEL=
