@echo off


REM DCIDE Path
 Set arg1=%~dpn1
 If "%arg1%"=="" goto err

REM DMD version (1 or 2)
 If "%2"=="" goto err

REM Command to call
 If %3=="" goto err2


REM It will be for example: C:/DCIDE
 Set DCIDE_ROOT=%arg1%

REM It willl be for example: C:/DCIDE/dmd2
 Set DMD_ROOT=%DCIDE_ROOT%/dmd%2

REM Important settings for compiler
 Set DFLAGS="-I%DMD_ROOT%/src/phobos" "-I%DMD_ROOT%/src/druntime/import"
 Set PATH=%DMD_ROOT%/bin;%PATH%
 Set LIB=%DMD_ROOT%/lib
 REM Set LINKCMD=%DMD_ROOT%/bin/link.exe


 echo Environment configured for DMD%2/Phobos
 echo Compiling...
 echo.
 goto compile

 :err2
 echo Error! You have Not given command to compile program!

 :err
 echo Error while configuring for DMD1/Tango!

 :compile
 cmd /C %3
 echo.

 If %errorlevel% equ 0 echo Compiled successfully!
 If not %errorlevel% equ 0 echo Compilation failed!
 
 If %errorlevel% neq 0 goto end

 If "%4"=="" goto end
 
 :run
 echo Running application "%4"
 cmd /C %4

 If "%5"=="" goto ex
 
 :end
 echo Press any key to exit.
 pause > nul

 :ex
exit