rem Compile program

set BIN_NAME=%CM_BIN_NAME%
IF NOT DEFINED CM_BIN_NAME SET BIN_NAME=run.exe

set RUN_DIR=%CM_RUN_DIR%
IF NOT DEFINED CM_RUN_DIR SET RUN_DIR=.

echo.
echo Checking compiler version ...
echo.

"%CM_C_COMPILER_WITH_PATH%" %CM_C_COMPILER_FLAG_VERSION%

echo.
echo Compiling source files ...
echo.

if not exist %RUN_DIR% mkdir %RUN_DIR%

cd %CM_SOURCE_FOLDER_PATH%
IF %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL%

if not "%CM_C_SOURCE_FILES%" == "" (
  echo %CM_C_COMPILER_WITH_PATH% %CM_C_COMPILER_FLAGS% %CM_C_INCLUDE_PATH% %CM_C_SOURCE_FILES% %CM_LD_LIBRARY_PATH% %LDCFLAGS% %CM_C_COMPILER_FLAG_OUTPUT%"%RUN_DIR%\%BIN_NAME%"
  "%CM_C_COMPILER_WITH_PATH%" %CM_C_COMPILER_FLAGS% %CM_C_INCLUDE_PATH% %CM_C_SOURCE_FILES% %CM_LD_LIBRARY_PATH% %LDCFLAGS% %CM_C_COMPILER_FLAG_OUTPUT%"%RUN_DIR%\%BIN_NAME%"
  IF %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL%
)

if not "%CM_CXX_SOURCE_FILES%" == "" (
  echo %CM_CXX_COMPILER_WITH_PATH%  %CM_CXX_SOURCE_FILES% %CM_CXX_COMPILER_FLAGS% %CM_CPLUS_INCLUDE_PATH% %CM_LD_LIBRARY_PATH% %LDCXXFLAGS% %CM_CXX_COMPILER_FLAG_OUTPUT%"%RUN_DIR%\%BIN_NAME%"
  "%CM_CXX_COMPILER_WITH_PATH%"  %CM_CXX_SOURCE_FILES% %CM_CXX_COMPILER_FLAGS% %CM_CPLUS_INCLUDE_PATH% %CM_LD_LIBRARY_PATH% %LDCXXFLAGS% %CM_CXX_COMPILER_FLAG_OUTPUT%"%RUN_DIR%\%BIN_NAME%"
  IF %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL%
)

