# -*- ruby -*-
# $Author: nobu $
# $Date: 2002/10/01 01:32:25 $

require 'mkmf'

def msg_check(s)
  print s, "... "
  STDOUT.flush
end

msg_check "checking for block_given?"	# for ruby-1.4
if Kernel.respond_to? :block_given?
  print "yes\n"
  $defs << "-DHAVE_BLOCK_GIVEN_P"
else
  print "no\n"
end

msg_check "checking for new allocation framework"	# for ruby-1.7
if Object.respond_to? :allocate
  print "yes\n"
  $defs << "-DHAVE_OBJECT_ALLOCATE"
else
  print "no\n"
end

msg_check "checking for new NORETURN"	# for ruby-1.6
if egrep_cpp("^NORETURN", "#include \"config.h\"\nNORETURN(exit);\n")
  print "no\n"
else
  print "yes\n"
  $defs << "-DHAVE_NEW_NORETURN"
end

msg_check "checking for RUBY_DATA_FUNC"
if try_link(<<SRC)
#include "ruby.h"
int t() {RUBY_DATA_FUNC foo; return 0;}
int main() {return 0;}
SRC
  print "yes\n"
  $defs << "-DHAVE_RUBY_DATA_FUNC"
else
  print "no\n"
end

have_header "m17n.h"

if method(:have_func).arity == 1	# for ruby-1.4
  alias have_func_1 have_func
  def have_func(func, header = nil)
    have_func_1(func)
  end
end
libs = $libs
libpath = $LIBPATH
unless have_func "ruby_init", "ruby.h"
  $libs = libs + " " + CONFIG["LIBRUBYARG"]
  $LIBPATH = libpath | [Config::CONFIG["libdir"]]
  unless have_func "ruby_init", "ruby.h"
    $libs = libs
    find_library(CONFIG["RUBY_INSTALL_NAME"], "ruby_init")
  end
end
have_func "rb_io_addstr", "ruby.h"
have_func "rb_io_puts", "ruby.h"
have_func "rb_io_print", "ruby.h"
have_func "rb_io_printf", "ruby.h"
have_func "rb_str_buf_new", "ruby.h"
have_func "rb_str_update", "ruby.h"
have_func "memchr", "string.h"
$libs = libs
$LIBPATH = libpath

create_makefile("stringio")
