* ext/extmk.rb: extend --extension option to specify necessary
  libraries.  [ruby-talk:117405]

* lib/mkmf.rb: err if no makefile is created from extconf.rb.


Index: ruby-ruby_1_8/ext/extmk.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/extmk.rb,v
retrieving revision 1.44.2.4
diff -U2 -p -d -r1.44.2.4 extmk.rb
--- ruby-ruby_1_8/ext/extmk.rb	2 Sep 2004 16:54:53 -0000	1.44.2.4
+++ ruby-ruby_1_8/ext/extmk.rb	24 Oct 2004 06:14:37 -0000
@@ -61,9 +61,11 @@ def extmake(target)
     $preload = nil
     makefile = "./Makefile"
+    ok = false
     unless $ignore
       if $static ||
 	 !(t = modified?(makefile, MTIMES)) ||
 	 %W<#{$srcdir}/makefile.rb #{$srcdir}/extconf.rb
-	    #{$srcdir}/depend #{$srcdir}/MANIFEST>.any? {|f| modified?(f, [t])}
+	    #{$srcdir}/depend #{$srcdir}/MANIFEST>.any? {|f| modified?(f, [t])} ||
+         $necessary[target] && /^all\b.*:\s*Makefile$/ =~ File.read(makefile)
       then
 	$defs = []
@@ -79,20 +81,27 @@ def extmake(target)
 	    create_makefile(target)
 	  end
-	  File.exist?(makefile)
+	  ok = File.exist?(makefile)
 	rescue SystemExit
 	  # ignore
 	ensure
 	  rm_f "conftest*"
+          config = $0
 	  $0 = $PROGRAM_NAME
 	  Config::CONFIG["srcdir"] = $top_srcdir
 	end
       else
-	true
+	ok = true
       end
     else
-      File.exist?(makefile)
-    end or open(makefile, "w") do |f|
-      f.print dummy_makefile($srcdir)
-      return true
+      ok = File.exist?(makefile)
+    end
+    unless ok
+      if $necessary[target]
+        mkmf_failed(config)
+      end
+      open(makefile, "w") do |f|
+        f.print dummy_makefile($srcdir)
+        return true
+      end
     end
     args = sysquote($mflags)
@@ -120,8 +129,18 @@ end
 
 def parse_args()
-  getopts('n', 'extstatic:', 'dest-dir:',
+  getopts('n', 'extension:', 'extstatic:', 'dest-dir:',
 	  'make:', 'make-flags:', 'mflags:')
 
   $dryrun = $OPT['n']
+  if $extension
+    $extension.split(/\s*,\s*/).compact.collect {|v|
+      (m = /\A[-+]?/.match(v)) ? [m.post_match, m[0][0]] : [v, nil]
+    }
+    if $extension.empty? or
+        $extension.all? {|t, n| t != '*' and n != ?-} &&
+        $extension.any? {|t, n| n != ?+}
+      $extension << ["*", ?-]
+    end
+  end
   $force_static = $OPT['extstatic'] == 'static'
   $destdir = $OPT['dest-dir'] || ''
@@ -206,5 +225,5 @@ for dir in ["ext", File::join($top_srcdi
       end
       target = target.downcase if /mswin32|bccwin32/ =~ RUBY_PLATFORM
-      $static_ext[target] = true
+      $static_ext[target] = $static_ext.size
     end
     MTIMES << f.mtime
@@ -218,9 +237,29 @@ FileUtils::makedirs('ext')
 Dir::chdir('ext')
 
+$necessary = {}
 ext_prefix = "#{$top_srcdir}/ext"
-Dir.glob("#{ext_prefix}/*/**/MANIFEST") do |d|
+exts = $static_ext.sort_by {|t, i| i}.collect {|t, i| t}
+exts.delete_if {|t| !File.exist?("#{ext_prefix}/#{t}/MANIFEST")}
+Dir.glob("#{ext_prefix}/*/**/MANIFEST")
+exts.collect! {|d|
   d = File.dirname(d)
   d.slice!(0, ext_prefix.length + 1)
-  extmake(d) or exit(1)
+  $extension.each {|pat, opt|
+    if File.fnmatch?(pat, d)
+      case opt
+      when ?+
+        $necessary[d] = true
+      when ?-
+        d = nil
+      end
+      break
+    end
+  } if $extension
+  d
+}
+exts.compact!
+
+exts.each do |d|
+  extmake(d) or abort
 end
 
Index: ruby-ruby_1_8/lib/mkmf.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/lib/mkmf.rb,v
retrieving revision 1.162.2.19
diff -U2 -p -d -r1.162.2.19 mkmf.rb
--- ruby-ruby_1_8/lib/mkmf.rb	18 Sep 2004 06:56:36 -0000	1.162.2.19
+++ ruby-ruby_1_8/lib/mkmf.rb	24 Oct 2004 05:57:40 -0000
@@ -606,4 +606,5 @@ end
 
 def arg_config(config, default=nil)
+  $arg_config << [config, default]
   $configure_args.fetch(config.tr('_', '-'), default)
 end
@@ -652,5 +653,7 @@ def dir_config(target, idefault=nil, lde
 
   idir = with_config(target + "-include", idefault)
+  $arg_config.last[1] ||= "${#{target}-dir}/include"
   ldir = with_config(target + "-lib", ldefault)
+  $arg_config.last[1] ||= "${#{target}-dir}/lib"
 
 #  idirs = idir ? idir.split(File::PATH_SEPARATOR) : []
@@ -953,4 +956,6 @@ static:		$(STATIC_LIB)
     end
   end
+
+  $makefile_created = true
 ensure
   mfile.close if mfile
@@ -958,4 +963,6 @@ end
 
 def init_mkmf(config = CONFIG)
+  $makefile_created = false
+  $arg_config = []
   $enable_shared = config['ENABLE_SHARED'] == 'yes'
   $defs = []
@@ -986,7 +993,23 @@ def init_mkmf(config = CONFIG)
   $distcleanfiles = []
 
+  $arg_config.clear
   dir_config("opt")
 end
 
+FailedMassage = <<MESSAGE
+Could not create Makefile due to some reason, probably lack of
+necessary libraries and/or headers.  Check the mkmf.log file for more
+details.  You may need configuration options.
+
+Provided configuration options:
+MESSAGE
+
+def mkmf_failed(path)
+  unless $makefile_created
+    opts = $arg_config.collect {|t, n| "\t#{t}#{"=#{n}" if n}\n"}
+    abort "*** #{path} failed ***\n" + FailedMassage + opts.join
+  end
+end
+
 init_mkmf
 
@@ -1053,2 +1076,6 @@ distclean:	clean
 realclean:	distclean
 "
+
+if not $extmk and /\A(extconf|makefile).rb\z/ =~ File.basename($0)
+  END {mkmf_failed($0)}
+end
