Fix build support for both ruby 1.8.x and 1.9.x.

Thanks to Francois Andriot.
pull/1/head
Darrell Anderson 13 years ago
parent e061a3e9ee
commit 8f79beaace

@ -14,15 +14,51 @@ if( NOT RUBY_EXECUTABLE )
tde_message_fatal( "ruby is required, but was not found on your system" ) tde_message_fatal( "ruby is required, but was not found on your system" )
endif( ) endif( )
# In ruby 1.9.x, ruby.h is located in a different location than previous releases.
execute_process( execute_process(
COMMAND ${RUBY_EXECUTABLE} -rrbconfig -e "puts Config.expand( Config::MAKEFILE_CONFIG['archdir'] )" COMMAND ${RUBY_EXECUTABLE} -rrbconfig -e "puts Config.expand( Config::MAKEFILE_CONFIG['MAJOR'] )"
OUTPUT_VARIABLE RUBY_INCLUDE_DIR OUTPUT_VARIABLE RUBY_VERSION_MAJOR
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['MINOR'] )"
OUTPUT_VARIABLE RUBY_VERSION_MINOR
RESULT_VARIABLE _result
OUTPUT_STRIP_TRAILING_WHITESPACE )
if( _result )
tde_message_fatal( "Unable to run ${RUBY_EXECUTABLE}!\n RUBY is correctly installed?" )
endif( )
set( RUBY_VERSION ${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR} )
if ( "${RUBY_VERSION}" GREATER "18" )
execute_process(
COMMAND ${RUBY_EXECUTABLE} -rrbconfig -e "puts Config.expand( Config::MAKEFILE_CONFIG['rubyhdrdir'] )"
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( )
else( )
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( )
endif( )
execute_process(
COMMAND ${RUBY_EXECUTABLE} -rrbconfig -e "puts Config.expand( Config::MAKEFILE_CONFIG['arch'] )"
OUTPUT_VARIABLE RUBY_ARCH
RESULT_VARIABLE _result RESULT_VARIABLE _result
OUTPUT_STRIP_TRAILING_WHITESPACE ) OUTPUT_STRIP_TRAILING_WHITESPACE )
if( _result ) if( _result )
tde_message_fatal( "Unable to run ${RUBY_EXECUTABLE}!\n RUBY is correctly installed?" ) tde_message_fatal( "Unable to run ${RUBY_EXECUTABLE}!\n RUBY is correctly installed?" )
endif( ) endif( )
execute_process( execute_process(
COMMAND ${RUBY_EXECUTABLE} -rrbconfig -e "puts Config.expand( Config::MAKEFILE_CONFIG['LIBRUBYARG_SHARED'] )" COMMAND ${RUBY_EXECUTABLE} -rrbconfig -e "puts Config.expand( Config::MAKEFILE_CONFIG['LIBRUBYARG_SHARED'] )"
OUTPUT_VARIABLE RUBY_LDFLAGS OUTPUT_VARIABLE RUBY_LDFLAGS
@ -36,4 +72,11 @@ if( RUBY_INCLUDE_DIR AND RUBY_LDFLAGS )
message( STATUS "Found RUBY: ${RUBY_EXECUTABLE}" ) message( STATUS "Found RUBY: ${RUBY_EXECUTABLE}" )
message( STATUS " RUBY_INCLUDE_DIR: ${RUBY_INCLUDE_DIR}" ) message( STATUS " RUBY_INCLUDE_DIR: ${RUBY_INCLUDE_DIR}" )
message( STATUS " RUBY_LDFLAGS: ${RUBY_LDFLAGS}" ) message( STATUS " RUBY_LDFLAGS: ${RUBY_LDFLAGS}" )
message( STATUS " RUBY_VERSION_MAJOR: ${RUBY_VERSION_MAJOR}")
message( STATUS " RUBY_VERSION_MINOR: ${RUBY_VERSION_MINOR}")
message( STATUS " RUBY_ARCH: ${RUBY_ARCH}")
endif( )
if ( "${RUBY_VERSION_MAJOR}${RUBY_VERSION_MINOR}" VERSION_LESS "19" )
message( STATUS " You have an older version of Ruby! (<1.9)")
set ( HAVE_OLD_RUBY 1 CACHE INTERNAL "" )
endif( ) endif( )

@ -15,6 +15,8 @@ add_definitions(
) )
include_directories( include_directories(
${CMAKE_BINARY_DIR}
${RUBY_INCLUDE_DIR}/${RUBY_ARCH}
${RUBY_INCLUDE_DIR} ${RUBY_INCLUDE_DIR}
) )

@ -2,6 +2,7 @@
* Copyright (c) 2005 Zed A. Shaw * Copyright (c) 2005 Zed A. Shaw
* You can redistribute it and/or modify it under the same terms as Ruby. * You can redistribute it and/or modify it under the same terms as Ruby.
*/ */
#include "config.h"
#include "ruby.h" #include "ruby.h"
#include "ext_help.h" #include "ext_help.h"
#include <assert.h> #include <assert.h>
@ -74,7 +75,11 @@ void http_field(void *data, const char *field, size_t flen, const char *value, s
f = rb_str_dup(global_http_prefix); f = rb_str_dup(global_http_prefix);
f = rb_str_buf_cat(f, field, flen); f = rb_str_buf_cat(f, field, flen);
for(ch = RSTRING(f)->ptr, end = ch + RSTRING(f)->len; ch < end; ch++) { #ifdef HAVE_OLD_RUBY
for(ch = RSTRING(f)->ptr, end = ch + RSTRING(f)->len; ch < end; ch++) {
#else
for(ch = RSTRING_PTR(f), end = ch + RSTRING_LEN(f); ch < end; ch++) {
#endif
if(*ch == '-') { if(*ch == '-') {
*ch = '_'; *ch = '_';
} else { } else {
@ -157,12 +162,25 @@ void header_done(void *data, const char *at, size_t length)
rb_hash_aset(req, global_gateway_interface, global_gateway_interface_value); rb_hash_aset(req, global_gateway_interface, global_gateway_interface_value);
if((temp = rb_hash_aref(req, global_http_host)) != Qnil) { if((temp = rb_hash_aref(req, global_http_host)) != Qnil) {
colon = strchr(RSTRING(temp)->ptr, ':'); #ifdef HAVE_OLD_RUBY
colon = strchr(RSTRING(temp)->ptr, ':');
#else
colon = strchr(RSTRING_PTR(temp), ':');
#endif
if(colon != NULL) { if(colon != NULL) {
rb_hash_aset(req, global_server_name, rb_str_substr(temp, 0, colon - RSTRING(temp)->ptr)); #ifdef HAVE_OLD_RUBY
rb_hash_aset(req, global_server_name, rb_str_substr(temp, 0, colon - RSTRING(temp)->ptr));
#else
rb_hash_aset(req, global_server_name, rb_str_substr(temp, 0, colon - RSTRING_PTR(temp)));
#endif
rb_hash_aset(req, global_server_port, rb_hash_aset(req, global_server_port,
rb_str_substr(temp, colon - RSTRING(temp)->ptr+1, #ifdef HAVE_OLD_RUBY
RSTRING(temp)->len)); rb_str_substr(temp, colon - RSTRING(temp)->ptr+1,
RSTRING(temp)->len));
#else
rb_str_substr(temp, colon - RSTRING_PTR(temp)+1,
RSTRING_LEN(temp)));
#endif
} else { } else {
rb_hash_aset(req, global_server_name, temp); rb_hash_aset(req, global_server_name, temp);
rb_hash_aset(req, global_server_port, global_port_80); rb_hash_aset(req, global_server_port, global_port_80);
@ -281,8 +299,13 @@ VALUE HttpParser_execute(VALUE self, VALUE req_hash, VALUE data, VALUE start)
DATA_GET(self, http_parser, http); DATA_GET(self, http_parser, http);
from = FIX2INT(start); from = FIX2INT(start);
dptr = RSTRING(data)->ptr; #ifdef HAVE_OLD_RUBY
dlen = RSTRING(data)->len; dptr = RSTRING(data)->ptr;
dlen = RSTRING(data)->len;
#else
dptr = RSTRING_PTR(data);
dlen = RSTRING_LEN(data);
#endif
if(from >= dlen) { if(from >= dlen) {
rb_raise(eHttpParserError, "Requested start is after data buffer end."); rb_raise(eHttpParserError, "Requested start is after data buffer end.");
@ -512,7 +535,11 @@ VALUE URIClassifier_resolve(VALUE self, VALUE uri)
if(pref_len == 1 && uri_str[0] == '/') { if(pref_len == 1 && uri_str[0] == '/') {
rb_ary_push(result, uri); rb_ary_push(result, uri);
} else { } else {
rb_ary_push(result, rb_str_substr(uri, pref_len, RSTRING(uri)->len)); #ifdef HAVE_OLD_RUBY
rb_ary_push(result, rb_str_substr(uri, pref_len, RSTRING(uri)->len));
#else
rb_ary_push(result, rb_str_substr(uri, pref_len, RSTRING_LEN(uri)));
#endif
} }
rb_ary_push(result, (VALUE)handler); rb_ary_push(result, (VALUE)handler);

@ -16,3 +16,4 @@
#cmakedefine TAGLIB_15 1 #cmakedefine TAGLIB_15 1
#cmakedefine HAVE_QGLWIDGET 1 #cmakedefine HAVE_QGLWIDGET 1
#cmakedefine HAVE_OLD_RUBY @HAVE_OLD_RUBY@

@ -1162,7 +1162,14 @@ AC_CHECK_TYPES([uint8_t, u_int8_t, uint16_t, u_int16_t, uint32_t, u_int32_t, uin
AC_PATH_PROG(RUBY, ruby, no) AC_PATH_PROG(RUBY, ruby, no)
ruby_includes=[`$RUBY -rrbconfig -e 'puts Config.expand( Config::MAKEFILE_CONFIG["archdir"] )'`] if test -n "$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"rubyhdrdir"@:>@)'"; then
# Ruby 1.9
ruby_includes=`$RUBY -r rbconfig -e 'printf("%s",Config::CONFIG@<:@"rubyhdrdir"@:>@)'`
else
# not Ruby 1.9
ruby_includes=[`$RUBY -rrbconfig -e 'puts Config.expand( Config::MAKEFILE_CONFIG["archdir"] )'`]
fi
ruby_ldflags=[`$RUBY -rrbconfig -e 'puts Config.expand( Config::MAKEFILE_CONFIG["LIBRUBYARG_SHARED"] )'`] ruby_ldflags=[`$RUBY -rrbconfig -e 'puts Config.expand( Config::MAKEFILE_CONFIG["LIBRUBYARG_SHARED"] )'`]
AC_SUBST(ruby_includes) AC_SUBST(ruby_includes)

Loading…
Cancel
Save