## Basic build system fixes
--- configure.in~	2007-09-07 09:38:51.000000000 +0200
+++ configure.in	2007-11-08 13:36:39.000000000 +0100
@@ -515,12 +515,12 @@
 AC_TYPE_GETGROUPS
 AC_TYPE_SIGNAL
 case "${target_cpu}-${target_os}" in
-powerpc-darwin*)
-  AC_LIBSOURCES(alloca.c)
-  AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.${ac_objext}])
-  AC_DEFINE(C_ALLOCA)
-  AC_DEFINE_UNQUOTED(alloca, alloca)
-  ;;
+dnl powerpc-darwin*)
+dnl   AC_LIBSOURCES(alloca.c)
+dnl   AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.${ac_objext}])
+dnl   AC_DEFINE(C_ALLOCA)
+dnl   AC_DEFINE_UNQUOTED(alloca, alloca)
+dnl   ;;
 *)
   AC_FUNC_ALLOCA
   ;;

## make miniruby not load already installed extensions
##--- ruby.c	2007-02-13 00:01:19.000000000 +0100
##+++ ruby.c	2007-04-25 14:53:32.000000000 +0200
##@@ -235,6 +235,7 @@
 void
 ruby_init_loadpath()
 {
+    char *argvptr;
 #if defined LOAD_RELATIVE
     char libpath[FILENAME_MAX+1];
     char *p;
##@@ -287,6 +288,10 @@
 	ruby_incpush(getenv("RUBYLIB"));
     }
 
+
+    argvptr = strrchr(origargv[0], '/');
+    if(!argvptr) argvptr = origargv[0];
+    if(!strstr(argvptr, "miniruby")) {
 #ifdef RUBY_SEARCH_PATH
     ruby_incpush(RUBY_RELATIVE(RUBY_SEARCH_PATH));
 #endif
##@@ -307,6 +312,7 @@
     if (rb_safe_level() == 0) {
 	ruby_incpush(".");
     }
+    }
 }
 
 struct req_list {

##--- configure.in~       2007-04-25 15:31:14.000000000 +0200
##+++ configure.in        2007-04-25 15:58:49.000000000 +0200
##@@ -1277,7 +1277,7 @@
   PREP=fake.rb
   RUNRUBY='$(MINIRUBY) -I`cd $(srcdir)/lib; pwd`'
 else
-  MINIRUBY='./miniruby$(EXEEXT)'
+  MINIRUBY='./miniruby$(EXEEXT) -I.'
   PREP='miniruby$(EXEEXT)'
   RUNRUBY='$(MINIRUBY) $(srcdir)/runruby.rb --extout=$(EXTOUT) --'
 fi


## tune module and libruby link options
--- configure.in	2007-04-18 12:49:43.000000000 +0200
+++ configure.in	2007-04-19 14:23:04.000000000 +0200
@@ -1052,7 +1052,7 @@
 	rhapsody*)	: ${LDSHARED='cc -dynamic -bundle -undefined suppress'}
 			: ${LDFLAGS=""}
 			rb_cv_dlopen=yes ;;
-	darwin*)	: ${LDSHARED='cc -dynamic -bundle -undefined suppress -flat_namespace'}
+	darwin*)	: ${LDSHARED='cc -dynamic -bundle -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress'}
 			: ${LDFLAGS=""}
 			: ${LIBPATHENV=DYLD_LIBRARY_PATH}
 			rb_cv_dlopen=yes ;;
@@ -1302,7 +1302,7 @@
     ;;
 esac
 
-RUBY_SO_NAME='$(RUBY_INSTALL_NAME)'
+RUBY_SO_NAME=ruby
 LIBRUBY_LDSHARED=$LDSHARED
 LIBRUBY_DLDFLAGS=$DLDFLAGS
 LIBRUBY_SO='lib$(RUBY_SO_NAME).so.$(MAJOR).$(MINOR).$(TEENY)'
@@ -1384,9 +1384,9 @@
 	;;
     darwin*)
 	LIBRUBY_SO='lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).$(TEENY).dylib'
-	LIBRUBY_LDSHARED='cc -dynamiclib -undefined suppress -flat_namespace'
-	LIBRUBY_DLDFLAGS='-install_name $(libdir)/lib$(RUBY_SO_NAME).dylib -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(MAJOR).$(MINOR)'
-	LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_SO_NAME).dylib'
+	LIBRUBY_LDSHARED='cc -dynamiclib'
+	LIBRUBY_DLDFLAGS='-install_name $(libdir)/lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).dylib -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(MAJOR).$(MINOR)'
+	LIBRUBY_ALIASES='lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_SO_NAME).dylib libruby.2.dylib'
 	;;
     interix*)
 	LIBRUBYARG_SHARED='-L${libdir} -L. -l$(RUBY_SO_NAME)'
## tune architecture (and binary extension directory name)
--- config.guess	2007-04-19 14:41:42.000000000 +0200
+++ config.guess	2007-04-19 14:39:55.000000000 +0200
@@ -1200,7 +1200,7 @@
 	    *86) UNAME_PROCESSOR=i686 ;;
 	    powerpc) UNAME_PROCESSOR=powerpc ;;
 	esac
-	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
+	echo ${UNAME_PROCESSOR}-apple-darwin
 	exit 0 ;;
     *:procnto*:*:* | *:QNX:[0123456789]*:*)
 	UNAME_PROCESSOR=`uname -p`

## more miscellaneous tweaks
diff -uNr ruby-1.8.4/lib/delegate.rb ruby-1.8.4-new/lib/delegate.rb
--- lib/delegate.rb  2005-09-28 10:23:24.000000000 -0400
+++ lib/delegate.rb      2006-08-05 18:21:28.000000000 -0400
@@ -290,7 +290,7 @@
   }
   for method in methods
     begin
-      klass.module_eval <<-EOS
+      klass.module_eval <<-EOS, __FILE__, __LINE__+1
         def #{method}(*args, &block)
          begin
            @_dc_obj.__send__(:#{method}, *args, &block)
--- lib/rdoc/options.rb.orig	2007-10-23 17:36:41.000000000 +0200
+++ lib/rdoc/options.rb	2007-10-23 17:37:12.000000000 +0200
@@ -544,7 +544,7 @@
   # so we'll bypass the test under Windows
 
   def check_diagram
-    return if RUBY_PLATFORM =~ /win/
+    return if RUBY_PLATFORM =~ /mswin32|cygwin|mingw|bccwin/
 
     ok = false
     ver = nil
--- dln.c.orig	2007-10-23 19:59:39.000000000 +0200
+++ dln.c	2007-10-23 20:06:45.000000000 +0200
@@ -87,13 +87,21 @@
 
 #ifndef NO_DLN_LOAD
 
-#if defined(HAVE_DLOPEN) && !defined(USE_DLN_A_OUT) && !defined(_AIX) && !defined(__APPLE__) && !defined(_UNICOSMP)
+#if defined(HAVE_DLOPEN) && !defined(USE_DLN_A_OUT) && !defined(_AIX) && !defined(_UNICOSMP)
 /* dynamic load with dlopen() */
 # define USE_DLN_DLOPEN
 #endif
 
+#if defined(USE_DLN_DLOPEN) && defined(__APPLE__)
+/* Mac OS X system lesser than 10.4 should use the NSSymbol APIs instead of dlopen/dlsym. */
+# include <AvailabilityMacros.h>
+# if MAC_OS_X_VERSION_MAX_ALLOWED < 1040
+#  undef USE_DLN_DLOPEN
+# endif
+#endif
+
 #ifndef FUNCNAME_PATTERN
-# if defined(__hp9000s300) ||  (defined(__NetBSD__) && !defined(__ELF__)) || defined(__BORLANDC__) || (defined(__FreeBSD__) && !defined(__ELF__)) || (defined(__OpenBSD__) && !defined(__ELF__)) || defined(NeXT) || defined(__WATCOMC__) || defined(__APPLE__)
+# if defined(__hp9000s300) ||  (defined(__NetBSD__) && !defined(__ELF__)) || defined(__BORLANDC__) || (defined(__FreeBSD__) && !defined(__ELF__)) || (defined(__OpenBSD__) && !defined(__ELF__)) || defined(NeXT) || defined(__WATCOMC__) || (defined(__APPLE__) && !defined(USE_DLN_DLOPEN))
 #  define FUNCNAME_PATTERN "_Init_%s"
 # else
 #  define FUNCNAME_PATTERN "Init_%s"
@@ -1403,7 +1411,7 @@
     }
 #endif /* _AIX */
 
-#if defined(NeXT) || defined(__APPLE__)
+#if defined(NeXT) || (defined(__APPLE__) && !defined(USE_DLN_DLOPEN))
 #define DLN_DEFINED
 /*----------------------------------------------------
    By SHIROYAMA Takayuki Psi@fortune.nest.or.jp
--- defines.h.orig	2007-10-23 19:48:41.000000000 +0200
+++ defines.h	2007-10-23 19:49:23.000000000 +0200
@@ -102,6 +102,16 @@
 #endif
 #endif
 
+#if defined(__NeXT__) || defined(__APPLE__)
+/* Do not trust WORDS_BIGENDIAN from configure since -arch compiler flag may
+   result in a different endian.  Instead trust __BIG_ENDIAN__ and
+   __LITTLE_ENDIAN__ which are set correctly by -arch. */
+#undef WORDS_BIGENDIAN
+#ifdef __BIG_ENDIAN__
+#define WORDS_BIGENDIAN
+#endif
+#endif
+
 #ifdef __NeXT__
 /* NextStep, OpenStep, Rhapsody */
 #ifndef S_IRUSR
@@ -155,13 +165,6 @@
 #ifndef S_ISREG
 #define S_ISREG(mode)  (((mode) & (0170000)) == (0100000))
 #endif
-/* Do not trust WORDS_BIGENDIAN from configure since -arch compiler flag may
-   result in a different endian.  Instead trust __BIG_ENDIAN__ and
-   __LITTLE_ENDIAN__ which are set correctly by -arch. */
-#undef WORDS_BIGENDIAN
-#ifdef __BIG_ENDIAN__
-#define WORDS_BIGENDIAN
-#endif
 #ifndef __APPLE__
 /* NextStep, OpenStep (but not Rhapsody) */
 #ifndef GETPGRP_VOID
