* ext/extmk.rb (extmake): $extout_prefix doesn't vary for libraries.

* ext/extmk.rb (extmake): remove compile directory if empty.

* ext/extmk.rb (parse_args) lib/mkmf.rb (create_makefile): move
  initialization of $extout_prefix from lib/mkmf.rb.  [ruby-dev:22928]

* ext/extmk.rb: clear ext and extout directory when cleaning.

* lib/mkmf.rb (CLEANLIBS): should be under $(arch) directory.


Index: ext/extmk.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/extmk.rb,v
retrieving revision 1.52
diff -u -2 -p -d -r1.52 extmk.rb
--- ext/extmk.rb	17 Feb 2004 03:12:53 -0000	1.52
+++ ext/extmk.rb	17 Feb 2004 09:34:38 -0000
@@ -52,8 +52,6 @@ def extmake(target)
   init_mkmf
 
-  begin
-    dir = Dir.pwd
-    FileUtils.mkpath target unless File.directory?(target)
-    Dir.chdir target
+  FileUtils.mkpath target unless File.directory?(target)
+  Dir.chdir(target) do
     $target = target
     $mdir = target
@@ -96,5 +94,5 @@ def extmake(target)
       return true
     end
-    args = sysquote($mflags.map {|m| /\Aextout_prefix=\z/ =~ m ? m + $extout_prefix : m})
+    args = sysquote($mflags)
     if $static
       args += ["static"]
@@ -115,7 +113,11 @@ def extmake(target)
       $extpath |= $LIBPATH
     end
-  ensure
-    Dir.chdir dir
   end
+  begin
+    Dir.rmdir target
+    target = File.dirname(target)
+  rescue SystemCallError
+    break
+  end while true
   true
 end
@@ -186,5 +196,6 @@ def parse_args()
       $extout = $absextout
     end
-    $mflags << ("extout=" << $extout) << "extout_prefix="
+    $extout_prefix = $extout ? "$(extout)$(target_prefix)/" : ""
+    $mflags << "extout=#$extout" << "extout_prefix=#$extout_prefix"
   end
 
@@ -200,4 +209,5 @@ if target = ARGV.shift and /^[a-z-]+$/ =
   when /clean/
     $ignore ||= true
+    $clean = true
   when /^install\b/
     $install = true
@@ -293,4 +303,8 @@ end
 if $ignore
   Dir.chdir ".."
+  if $clean
+    Dir.rmdir('ext') rescue nil
+    FileUtils.rm_rf($absextout) if $extout
+  end
   exit
 end
Index: lib/mkmf.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/lib/mkmf.rb,v
retrieving revision 1.175
diff -u -2 -p -d -r1.175 mkmf.rb
--- lib/mkmf.rb	17 Feb 2004 03:12:53 -0000	1.175
+++ lib/mkmf.rb	17 Feb 2004 08:38:22 -0000
@@ -820,6 +822,4 @@ def create_makefile(target, srcprefix = 
   end
 
-  $extout_prefix = $extout ? "$(extout)$(target_prefix)/" : ""
-
   srcprefix ||= '$(srcdir)'
   Config::expand(srcdir = srcprefix.dup)
@@ -899,5 +899,5 @@ RUBYARCHDIR   = $(sitearchdir)$(target_p
   end
   mfile.print %{
-CLEANLIBS     = #{$extout_prefix}$(TARGET).{#{CONFIG['DLEXT']},#{$LIBEXT},exp,il?,tds,map}
+CLEANLIBS     = #{$extout ? '$(RUBYARCHDIR)/' : ''}$(TARGET).{#{CONFIG['DLEXT']},exp,il?,tds,map}
 CLEANOBJS     = *.#{$OBJEXT} *.#{$LIBEXT} *.s[ol] *.pdb *.bak
 
@@ -1026,4 +1023,5 @@ def init_mkmf(config = CONFIG)
 
   $extout ||= nil
+  $extout_prefix ||= nil
 
   dir_config("opt")
