noreply / rubyforge.org wrote:
> Patches item #9762, was opened at 2007-04-02 09:55
> You can respond by visiting: 
> http://rubyforge.org/tracker/?func=detail&atid=1700&aid=9762&group_id=426

<snip>

Oops, forgot RubyForge doesn't forward the attachments. Here's the 
patch, inline:

--- mkmf.orig	Wed Feb 28 06:23:42 2007
+++ mkmf.rb	Mon Apr  2 10:48:21 2007
@@ -63,6 +63,8 @@
  $solaris = /solaris/ =~ RUBY_PLATFORM
  $dest_prefix_pattern = (File::PATH_SEPARATOR == ';' ? 
/\A([[:alpha:]]:)?/ : /\A/)

+# :stopdoc:
+
  def config_string(key, config = CONFIG)
    s = config[key] and !s.empty? and block_given? ? yield(s) : s
  end
@@ -129,11 +131,13 @@
  CONFTEST_C = "conftest.c"

  class String
+  # Wraps a string in escaped quotes if it contains whitespace.
    def quote
      /\s/ =~ self ? "\"#{self}\"" : self
    end
  end
  class Array
+  # Wraps all strings in escaped quotes if they contain whitespace.
    def quote
      map {|s| s.quote}
    end
@@ -165,6 +169,12 @@
    end
  end

+# This is a custom logging module. It generates an mkmf.log file when you
+# run your extconf.rb script. This can be useful for debugging unexpected
+# failures.
+#
+# This module and its associated methods are meant for internal use only.
+#
  module Logging
    @log = nil
    @logfile = 'mkmf.log'
@@ -461,6 +471,10 @@
    log_src(src)
  end

+# This is used internally by the have_macro? method.
+#
+# Internal use only.
+#
  def macro_defined?(macro, src, opt = "", &b)
    src = src.sub(/[^\n]\z/, "\\&\n")
    try_compile(src + <<"SRC", opt, &b)
@@ -523,7 +537,7 @@
    install_files(mfile, [["lib/**/*.rb", dest, "lib"]], nil, srcdir)
  end

-def append_library(libs, lib)
+def append_library(libs, lib) # :no-doc:
    format(LIBARG, lib) + " " + libs
  end

@@ -534,6 +548,11 @@
    end
  end

+# This emits a string to stdout that allows users to see the results of the
+# various have* and find* methods as they are tested.
+#
+# Internal use only.
+#
  def checking_for(m, fmt = nil)
    f = caller[0][/in `(.*)'$/, 1] and f << ": " #` for vim
    m = "checking #{/\Acheck/ =~ f ? '' : 'for '}#{m}... "
@@ -563,6 +582,8 @@
    end
  end

+# :startdoc:
+
  # Returns whether or not +macro+ is defined either in the common header
  # files or within any +headers+ you provide.
  #
@@ -582,7 +603,7 @@
  # If +headers+ are provided, it will include those header files as the
  # header files it looks in when searching for +func+.
  #
-# Real name of the library to be linked can be altered by
+# The real name of the library to be linked can be altered by
  # '--with-FOOlib' configuration option.
  #
  def have_library(lib, func = nil, headers = nil, &b)
@@ -722,7 +743,7 @@
  # If found, a macro is passed as a preprocessor constant to the 
compiler using
  # the member name, in uppercase, prepended with 'HAVE_ST_'.
  #
-# For example, if have_struct_member('foo', 'bar') returned true, then the
+# For example, if have_struct_member('struct foo', 'bar') returned 
true, then the
  # HAVE_ST_BAR preprocessor macro would be passed to the compiler.
  #
  def have_struct_member(type, member, headers = nil, &b)
@@ -797,6 +818,13 @@
    end
  end

+# :stopdoc:
+
+# Used internally by the what_type? method to determine if +type+ is a 
scalar
+# pointer.
+#
+# Internal use only.
+#
  def scalar_ptr_type?(type, member = nil, headers = nil, &b)
    try_compile(<<"SRC", &b)   # pointer
  #{COMMON_HEADERS}
@@ -808,6 +836,11 @@
  SRC
  end

+# Used internally by the what_type? method to determine if +type+ is a 
scalar
+# pointer.
+#
+# Internal use only.
+#
  def scalar_type?(type, member = nil, headers = nil, &b)
    try_compile(<<"SRC", &b)   # pointer
  #{COMMON_HEADERS}
@@ -851,6 +884,10 @@
    end
  end

+# This method is used internally by the find_executable method.
+#
+# Internal use only.
+#
  def find_executable0(bin, path = nil)
    ext = config_string('EXEEXT')
    if File.expand_path(bin) == bin
@@ -871,6 +908,17 @@
    nil
  end

+# :startdoc:
+
+# Searches for the executable +bin+ on +path+. The default path is your
+# PATH environment variable. If that isn't defined, it will resort to
+# searching /usr/local/bin, /usr/ucb, /usr/bin and /bin.
+#
+# If found, it will return the full path, including the executable name,
+# of where it was found.
+#
+# Note that this method does not actually affect the generated Makefile.
+#
  def find_executable(bin, path = nil)
    checking_for checking_message(bin, path) do
      find_executable0(bin, path)
@@ -877,6 +925,8 @@
    end
  end

+# :stopdoc:
+
  def arg_config(config, *defaults, &block)
    $arg_config << [config, *defaults]
    defaults << nil if !block and defaults.empty?
@@ -883,6 +933,20 @@
    $configure_args.fetch(config.tr('_', '-'), *defaults, &block)
  end

+# :startdoc:
+
+# Tests for the presence of a --with-<tt>config</tt> or 
--without-<tt>config</tt>
+# option. Returns true if the with option is given, false if the without
+# option is given, and the default value otherwise.
+#
+# This can be useful for adding custom definitions, such as debug 
information.
+#
+# Example:
+#
+#    if with_config("debug")
+#       $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
+#    end
+#
  def with_config(config, *defaults)
    config = config.sub(/^--with[-_]/, '')
    val = arg_config("--with-"+config) do
@@ -904,6 +968,18 @@
    end
  end

+# Tests for the presence of an --enable-<tt>config</tt> or
+# --disable-<tt>config</tt> option. Returns true if the enable option 
is given,
+# false if the disable option is given, and the default value otherwise.
+#
+# This can be useful for adding custom definitions, such as debug 
information.
+#
+# Example:
+#
+#    if enable_config("debug")
+#       $defs.push("-DOSSL_DEBUG") unless $defs.include? "-DOSSL_DEBUG"
+#    end
+#
  def enable_config(config, *defaults)
    if arg_config("--enable-"+config)
      true
@@ -916,6 +992,32 @@
    end
  end

+# Generates a header file consisting of the various macro definitions 
generated
+# by other methods such as have_func and have_header. These are then 
wrapped in
+# a custom #ifndef based on the +header+ file name, which defaults to
+# 'extconf.h'.
+#
+# For example:
+#
+#    # extconf.rb
+#    require 'mkmf'
+#    have_func('realpath')
+#    have_header('sys/utime.h')
+#    create_header
+#    create_makefile('foo')
+#
+# The above script would generate the following extconf.h file:
+#
+#    #ifndef EXTCONF_H
+#    #define EXTCONF_H
+#    #define HAVE_REALPATH 1
+#    #define HAVE_SYS_UTIME_H 1
+#    #endif
+#
+# Given that the create_header method generates a file based on definitions
+# set earlier in your extconf.rb file, you will probably want to make this
+# one of the last methods you call in your script.
+#
  def create_header(header = "extconf.h")
    message "creating %s\n", header
    sym = header.tr("a-z./\055", "A-Z___")
@@ -983,6 +1085,13 @@
    [idir, ldir]
  end

+# :stopdoc:
+
+# Handles meta information about installed libraries. Uses your platform's
+# pkg-config program if it has one.
+#
+# Internal use only.
+#
  def pkg_config(pkg)
    if pkgconfig = with_config("#{pkg}-config") and 
find_executable0(pkgconfig)
      # iff package specific config command is given
@@ -1020,6 +1129,10 @@
    /\A\$[\(\{]/ =~ dir ? dir : "$(DESTDIR)"+dir
  end

+# Converts forward slashes to backslashes. Aimed at MS Windows.
+#
+# Internal use only.
+#
  def winsep(s)
    s.tr('/', '\\')
  end
@@ -1122,6 +1235,7 @@

  RULES
  end
+# :startdoc:

  # Generates the Makefile for your extension, passing along any options and
  # preprocessor constants that you may have generated through other 
methods.
@@ -1140,6 +1254,10 @@
  # load the file within a Ruby program later, that directory structure will
  # have to be followed, e.g. "require 'test/foo'".
  #
+# The +srcprefix+ argument can be used to override the default source
+# directory, i.e. the current directory . It is included as part of the 
VPATH
+# and added to the list of INCFLAGS.
+#
  def create_makefile(target, srcprefix = nil)
    $target = target
    libpath = $DEFLIBPATH|$LIBPATH
@@ -1406,6 +1524,8 @@
    mfile.close if mfile
  end

+# :stopdoc:
+
  def init_mkmf(config = CONFIG)
    $makefile_created = false
    $arg_config = []
@@ -1455,6 +1575,11 @@
  Provided configuration options:
  MESSAGE

+# Returns whether or not the Makefile was successfully generated. If not,
+# the script will abort with an error message.
+#
+# Internal use only.
+#
  def mkmf_failed(path)
    unless $makefile_created or File.exist?("Makefile")
      opts = $arg_config.collect {|t, n| "\t#{t}#{n ? "=#{n}" : ""}\n"}
@@ -1462,6 +1587,8 @@
    end
  end

+# :startdoc:
+
  init_mkmf

  $make = with_config("make-prog", ENV["MAKE"] || "make")