#################################################
#
#  (C) 2010-2011 Serghei Amelian
#  serghei (DOT) amelian (AT) gmail.com
#
#  Improvements and feedback are welcome
#
#  This file is released under GPL >= 2
#
#################################################

find_program( RUBY_EXECUTABLE "ruby" )
if( NOT RUBY_EXECUTABLE )
  tde_message_fatal( "ruby is required, but was not found on your system" )
endif( )

execute_process(
  COMMAND ${RUBY_EXECUTABLE} -rrbconfig -e "puts Config.expand( Config::MAKEFILE_CONFIG['archdir'] )"
  OUTPUT_VARIABLE RUBY_INCLUDE_DIR
  RESULT_VARIABLE _result
  OUTPUT_STRIP_TRAILING_WHITESPACE )
if( _result )
  tde_message_fatal( "Unable to run ${RUBY_EXECUTABLE}!\n RUBY is correctly installed?" )
endif( )

execute_process(
  COMMAND ${RUBY_EXECUTABLE} -rrbconfig -e "puts Config.expand( Config::MAKEFILE_CONFIG['LIBRUBYARG_SHARED'] )"
  OUTPUT_VARIABLE RUBY_LDFLAGS
  RESULT_VARIABLE _result
  OUTPUT_STRIP_TRAILING_WHITESPACE )
if( _result )
  tde_message_fatal( "Unable to run ${RUBY_EXECUTABLE}!\n RUBY is correctly installed?" )
endif( )

if( RUBY_INCLUDE_DIR AND RUBY_LDFLAGS )
  message( STATUS "Found RUBY: ${RUBY_EXECUTABLE}" )
  message( STATUS "  RUBY_INCLUDE_DIR: ${RUBY_INCLUDE_DIR}" )
  message( STATUS "  RUBY_LDFLAGS: ${RUBY_LDFLAGS}" )
endif( )
