$NetBSD: patch-bb,v 1.1 2005/11/02 08:56:40 taca Exp $

--- ext/extmk.rb.orig	2005-08-05 00:20:10.000000000 +0900
+++ ext/extmk.rb
@@ -350,12 +350,30 @@ end unless $extstatic
 
 ext_prefix = "#{$top_srcdir}/ext"
 exts = $static_ext.sort_by {|t, i| i}.collect {|t, i| t}
-exts |= $extension if $extension
-exts |= Dir.glob("#{ext_prefix}/*/**/extconf.rb").collect {|d|
-  d = File.dirname(d)
-  d.slice!(0, ext_prefix.length + 1)
-  d
-}.sort unless $extension
+if $extension
+  exts |= $extension.select {|d| File.directory?("#{ext_prefix}/#{d}")}
+else
+  withes, withouts = %w[--with --without].collect {|w|
+    if not (w = %w[-extensions -ext].collect {|opt|arg_config(w+opt)}).any?
+      proc {false}
+    elsif (w = w.grep(String)).empty?
+      proc {true}
+    else
+      w.collect {|opt| opt.split(/,/)}.flatten.method(:any?)
+    end
+  }
+  cond = proc {|ext|
+    cond1 = proc {|n| File.fnmatch(n, ext, File::FNM_PATHNAME)}
+    withes.call(&cond1) or !withouts.call(&cond1)
+  }
+  exts |= Dir.glob("#{ext_prefix}/*/**/extconf.rb").collect {|d|
+    d = File.dirname(d)
+    d.slice!(0, ext_prefix.length + 1)
+    d
+  }.find_all {|ext|
+    with_config(ext, &cond)
+  }.sort
+end
 
 if $extout
   Config.expand(extout = "#$extout", Config::CONFIG.merge("topdir"=>$topdir))
