@echo off
@REM ===============================================================
@REM    Copyright (C) 2013 BizStation Corp All rights reserved.
@REM 
@REM    This program is free software; you can redistribute it and/or
@REM    modify it under the terms of the GNU General Public License
@REM    as published by the Free Software Foundation; either version 2
@REM    of the License, or (at your option) any later version.
@REM 
@REM    This program is distributed in the hope that it will be useful,
@REM    but WITHOUT ANY WARRANTY; without even the implied warranty of
@REM    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@REM    GNU General Public License for more details.
@REM 
@REM    You should have received a copy of the GNU General Public License
@REM    along with this program; if not, write to the Free Software 
@REM    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
@REM    02111-1307, USA.
@REM ===============================================================

setlocal enabledelayedexpansion
cd "%~dp0"

set BLDMSG=buildmsg.log
set INSMSG=..\..\..\install.log
set ERRMSG=errormsg.log

@REM BUILD
echo BUILD TransactdRubyClient.sln %date% %time% >> "%BLDMSG%"
msbuild TransactdRubyClient.sln /p:Configuration=Release /m:2 >> "%BLDMSG%" 2>&1
if ERRORLEVEL 1 (
  echo ************************************************************** 1>&2
  echo EROOR MESSAGE 1>&2
  echo Failed to Build. Please check log. 1>&2
  echo %~dp0%BLDMSG%
  echo %~dp0cmake_generate.log
  echo ************************************************************** 1>&2
  exit /b 1
)

if "%~1" == "install" goto :INSTALLCMD
if "%~1" == "site-install" goto :INSTALLCMD
if "%~2" == "install" goto :INSTALLCMD
if "%~2" == "site-install" goto :INSTALLCMD
exit /b 0

:INSTALLCMD
echo Install %date% %time% >> "%INSMSG%"
cmake -P cmake_install.cmake >> "%INSMSG%" 2>> "%ERRMSG%"
call :getsize "%ERRMSG%"
if !getsize_ret! GTR 0 (
  type "%ERRMSG%" >> "%INSMSG%"
  findstr /C:"Failed to Install." "%ERRMSG%" > "%ERRMSG%.tmp"
  call :getsize "%ERRMSG%.tmp"
  del "%ERRMSG%.tmp"
  if !getsize_ret! GTR 0 (
    type "%ERRMSG%" 1>&2
    exit /b 1
  )
)
exit /b 0

:getsize
  set /a getsize_ret=%~z1
  exit /b 0

endlocal