Index: lib/mkmf.rb
===================================================================
RCS file: //sharui/cvs/ruby/src/ruby/lib/mkmf.rb,v
retrieving revision 1.135
diff -u -2 -p -r1.135 mkmf.rb
--- lib/mkmf.rb	3 Jul 2003 11:07:55 -0000	1.135
+++ lib/mkmf.rb	17 Jul 2003 01:14:04 -0000
@@ -3,4 +3,5 @@
 
 require 'rbconfig'
+require 'fileutils'
 require 'shellwords'
 
@@ -91,4 +92,5 @@ CPPOUTFILE = CONFIG['CPPOUTFILE']
 
 CONFTEST_C = "conftest.c"
+CONFTEST_I = "conftest.i"
 
 $INSTALLFILES ||= nil
@@ -106,23 +108,11 @@ end
 
 def rm_f(*files)
-  targets = []
-  for file in files
-    targets.concat Dir[file]
-  end
-  if not targets.empty?
-    File::chmod(0777, *targets)
-    File::unlink(*targets)
-  end
+  FileUtils.rm_f(Dir[files.join("\0")])
 end
 
-def older(target, *files)
-  mtime = proc do |f|
-    Time === f ? f : f.respond_to?(:mtime) ? f.mtime : File.mtime(f) rescue nil
-  end
-  t = mtime[target] or return true
-  for f in files
-    return true if t < (mtime[f] or next)
-  end
-  false
+def modified?(target, times)
+  (t = File.mtime(target)) rescue return nil
+  Array === times or times = [times]
+  t if times.all? {|n| n <= t}
 end
 
@@ -225,5 +215,5 @@ end
 def cpp_command(outfile, opt="")
   "$(CPP) #$INCFLAGS -I#{$hdrdir} " \
-  "#$CPPFLAGS #$CFLAGS #{outfile} #{opt} #{CONFTEST_C}"
+  "#$CPPFLAGS #$CFLAGS #{CPPOUTFILE % outfile} #{opt} #{CONFTEST_C}"
 end
 
@@ -249,5 +239,5 @@ end
 
 def try_cpp(src, opt="")
-  try_do(src, cpp_command(CPPOUTFILE, opt))
+  try_do(src, cpp_command(CONFTEST_I, opt))
 ensure
   rm_f "conftest*"
@@ -280,22 +270,13 @@ def egrep_cpp(pat, src, opt="")
   src += "\n" unless /\n\z/ =~ src
   create_tmpsrc(src)
-  xpopen(cpp_command('', opt)) do |f|
-    if Regexp === pat
-      puts("    ruby -ne 'print if #{pat.inspect}'")
-      f.grep(pat) {|l|
-	puts "#{f.lineno}: #{l}"
-	return true
-      }
-      false
-    else
-      puts("    egrep '#{pat}'")
-      begin
-	stdin = $stdin.dup
-	$stdin.reopen(f)
-	system("egrep", pat)
-      ensure
-	$stdin.reopen(stdin)
-      end
+  return false unless xsystem(cpp_command(CONFTEST_I, opt))
+  pat = Regexp.new(pat) unless Regexp === pat
+  open(CONFTEST_I) do |f|
+    puts("ruby -ne 'print if #{pat.inspect}' #{CONFTEST_I}")
+    f.grep(pat) do |l|
+      puts "#{f.lineno}: #{l}"
+      return true
     end
+    false
   end
 ensure
@@ -340,4 +321,5 @@ def install_files(mfile, ifiles, map = n
       len = srcdir.size
     end
+    f = nil
     Dir.glob(files) do |f|
       f[0..len] = "" if len
@@ -348,4 +330,10 @@ def install_files(mfile, ifiles, map = n
       path[d] << f
     end
+    unless len or f
+      d = File.dirname(files)
+      d.sub!(prefix, "") if prefix
+      d = (d.empty? || d == ".") ? dir : File.join(dir, d)
+      path[d] << files
+    end
   end
   dirs
@@ -371,7 +359,8 @@ def checking_for(m)
   m = "checking for #{m}... "
   message m
-  Logging::message "#{f}#{m}\n"
+  Logging::message "#{f}#{m}--------------------\n"
   r = yield
-  message(r ? "yes\n" : "no\n")
+  message(a = r ? "yes\n" : "no\n")
+  Logging::message "-------------------- #{a}\n"
   r
 end
@@ -538,4 +527,5 @@ end
 def configuration(srcdir)
   mk = []
+  vars = []
   mk << %{
 SHELL = /bin/sh
@@ -547,8 +537,11 @@ topdir = #{$topdir}
 hdrdir = #{$hdrdir}
 VPATH = #{$mingw && CONFIG['build_os'] == 'cygwin' ? '$(shell cygpath -u $(srcdir))' : '$(srcdir)'}
+
 }
   drive = File::PATH_SEPARATOR == ';' ? /\A\w:/ : /\A/
   if destdir = CONFIG["prefix"].scan(drive)[0] and !destdir.empty?
-    mk << "\nDESTDIR = #{destdir}\n"
+    v = "DESTDIR = #{destdir}\n"
+    mk << v
+    vars << v
   end
   CONFIG.each do |key, var|
@@ -571,5 +564,5 @@ CFLAGS   = #{CONFIG['CCDLFLAGS'] unless 
 CPPFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir) #{$defs.join(" ")} #{$CPPFLAGS}
 CXXFLAGS = $(CFLAGS) #{CONFIG['CXXFLAGS']}
-DLDFLAGS = #$LDFLAGS #{CONFIG['DLDFLAGS']} #$DLDFLAGS
+DLDFLAGS = #{CONFIG['DLDFLAGS']} #$DLDFLAGS
 LDSHARED = #{CONFIG['LDSHARED']}
 AR = #{CONFIG['AR']}
@@ -581,4 +574,6 @@ arch = #{CONFIG['arch']}
 sitearch = #{CONFIG['sitearch']}
 ruby_version = #{Config::CONFIG['ruby_version']}
+}
+  v = <<EOS.to_a
 RUBY = #{$ruby}
 RM = $(RUBY) -rftools -e "File::rm_f(*ARGV.map do|x|Dir[x]end.flatten.uniq)"
@@ -586,16 +581,14 @@ MAKEDIRS = $(RUBY) -r ftools -e 'File::m
 INSTALL_PROG = $(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0755, true)'
 INSTALL_DATA = $(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0644, true)'
-
+CONFIGURE_ARGS = #{ARGV.quote.join(' ')}
+EOS
+  mk.concat(v)
+  vars.concat(v)
+  mk << %{
 #### End of system configuration section. ####
 
 }
   if $nmake == ?b
-    mk.each do |x|
-      x.gsub!(/^(MAKEDIRS|INSTALL_(?:PROG|DATA))+\s*=.*\n/) do
-        "!ifndef " + $1 + "\n" +
-        $& +
-	"!endif\n"
-      end
-    end
+    vars.each {|x| x.sub!(/\A(\S+)\s*=.*/m, "!ifndef \\1\n\\&!endif\n")}
   end
   mk
@@ -603,5 +596,5 @@ end
 
 def dummy_makefile(srcdir)
-  configuration(srcdir) << "all install: Makefile\n" << CLEANINGS
+  configuration(srcdir) << "all install: Makefile\n" << MISC_RULES
 end
 
@@ -643,28 +636,17 @@ def create_makefile(target, srcprefix = 
 
   if target and EXPORT_PREFIX
-    origdef = target + '.def'
-    deffile = EXPORT_PREFIX + origdef
-    unless File.exist? deffile
-      if File.exist? File.join(srcdir, deffile)
-	deffile = File.join srcdir, deffile
-      elsif !EXPORT_PREFIX.empty? and File.exist?(origdef = File.join(srcdir, origdef))
-	open(origdef) do |d|
-	  open(deffile, 'wb') do |f|
-	    d.each do |l|
-	      f.print l
-	      break if /^EXPORTS$/i =~ l
-	    end
-	    d.each do |l|
-	      f.print l.sub(/\S/, EXPORT_PREFIX+'\&')
-	    end
-	  end
-	end
-      else
-	open(deffile, 'wb') do |f|
-	  f.print "EXPORTS\n", EXPORT_PREFIX, "Init_", target, "\n"
-	end
+    if File.exist?(File.join(srcdir, target + '.def'))
+      deffile = "$(srcdir)/$(TARGET).def"
+      unless EXPORT_PREFIX.empty?
+	makedef = %{-pe "sub!(/^(?=\\w)/,'#{EXPORT_PREFIX}') unless 1../^EXPORTS$/i"}
       end
+    else
+      makedef = %{-e "puts 'EXPORTS', '#{EXPORT_PREFIX}Init_$(TARGET)'"}
+    end
+    if makedef
+      $distcleanfiles << '$(DEFFILE)'
+      origdef = deffile
+      deffile = "$(TARGET)-$(arch).def"
     end
-    $distcleanfiles << deffile unless deffile == origdef
   end
 
@@ -707,5 +689,5 @@ CLEANOBJS     = "*.{#{$OBJEXT},#{$LIBEXT
 all:		#{target ? "$(DLLIB)" : "Makefile"}
 }
-  mfile.print CLEANINGS
+  mfile.print MISC_RULES
   dirs = []
   if not $static and target
@@ -757,7 +739,6 @@ all:		#{target ? "$(DLLIB)" : "Makefile"
   end
 
-  mfile.print "$(DLLIB): $(OBJS)\n\t"
-  mfile.print "@-$(RM) $@\n\t"
-  mfile.print "@-$(RM) $(TARGET).lib\n\t" if $mswin
+  mfile.print "$(DLLIB): $(OBJS) $(DEFFILE)\n\t"
+  mfile.print "@-$(RM) $@#{' $(TARGET).lib' if $mswin}\n\t"
   if $static
     mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$(DLLIB) $(OBJS)"
@@ -770,4 +751,9 @@ all:		#{target ? "$(DLLIB)" : "Makefile"
   mfile.print "\n\n"
 
+  if makedef
+    mfile.print "$(DEFFILE): #{origdef}\n"
+    mfile.print "\t$(RUBY) #{makedef} #{origdef} > $@\n\n"
+  end
+
   depend = File.join(srcdir, "depend")
   if File.exist?(depend)
@@ -867,8 +853,10 @@ LINK_SO = config_string('LINK_SO') ||
     "$(OBJS) $(LOCAL_LIBS) $(LIBS)"
   end
+LINK_EXE = config_string('LINK_EXE') ||
+  "$(CC) $(LDFLAGS) $(XLDFLAGS) #{OUTFLAG}$@ $(OBJS) $(LOCAL_LIBS) $(LIBS)"
 LIBPATHFLAG = config_string('LIBPATHFLAG') || ' -L%s'
 LIBARG = config_string('LIBARG') || '-l%s'
 
-CLEANINGS = "
+MISC_RULES = "
 clean:
 		@$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
@@ -880,2 +868,21 @@ distclean:	clean
 realclean:	distclean
 "
+
+# for backward compatibility
+CFLAGS = $CFLAGS
+CPPFLAGS = $CPPFLAGS
+LINK = Config::expand(TRY_LINK.dup,
+		      'hdrdir' => $hdrdir,
+		      'src' => CONFTEST_C,
+		      'INCFLAGS' => $INCFLAGS,
+		      'CPPFLAGS' => "%s",
+		      'CFLAGS' => "#{CFLAGS} %s",
+		      'LDFLAGS' => "#$LDFLAGS %s",
+		      'LIBPATH' => "",
+		      'LOCAL_LIBS' => "%s",
+		      'LIBS' => "#$LIBRUBYARG_STATIC %s #$LIBS")
+CC = Config::expand(COMPILE_C.sub(/\$</, CONFTEST_C),
+		    'CPPFLAGS' => "#{CPPFLAGS} %s -I#{$hdrdir}",
+		    'CFLAGS' => "#{CFLAGS} %s %s")
+CPP = Config::expand("$(CPP) #$INCFLAGS -I#{$hdrdir} " \
+		     "%s %s #{CPPOUTFILE % CONFTEST_I} %s #{CONFTEST_C}")
Index: ext/iconv/MANIFEST
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/iconv/MANIFEST,v
retrieving revision 1.2
diff -u -2 -p -r1.2 MANIFEST
--- ext/iconv/MANIFEST	18 Mar 2002 09:23:11 -0000	1.2
+++ ext/iconv/MANIFEST	17 Jul 2003 00:05:21 -0000
@@ -3,2 +3,5 @@ extconf.rb
 iconv.c
 depend
+lib/iconv.rb
+charset_alias.rb
+config.charset
Index: ext/iconv/charset_alias.rb
===================================================================
RCS file: ext/iconv/charset_alias.rb
diff -N ext/iconv/charset_alias.rb
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ext/iconv/charset_alias.rb	17 Jul 2003 00:13:47 -0000
@@ -0,0 +1,28 @@
+#! /usr/bin/ruby
+require 'rbconfig'
+
+def charset_alias(config_charset, mapfile)
+  map = {}
+  os = Config::CONFIG["target"]
+  unless /linux|-gnu/ =~ os
+    comments = []
+    shell = with_config("shell", Config::CONFIG['SHELL'])
+    IO.popen("#{shell} #{config_charset} #{os}", "r") do |conf|
+      conf.each do |list|
+        next if /^\#/ =~ list
+        next unless /^(\S+)\s+(\S+)$/ =~ list
+        next if $1 == $2
+        map[$2] = $1
+      end
+    end
+  end
+  open(mapfile, "w") do |f|
+    f.puts(comments)
+    f.puts("class Iconv\n  CharsetMap = {")
+    map.each {|can, sys| f.puts("    '#{can.downcase}' => '#{sys}',")}
+    f.puts("  }\nend")
+  end
+end
+
+ARGV.size == 2 or abort "usage: #$0 config.status map.rb"
+charset_alias(*ARGV)
Index: ext/iconv/depend
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/iconv/depend,v
retrieving revision 1.1
diff -u -2 -p -r1.1 depend
--- ext/iconv/depend	17 Mar 2002 11:07:46 -0000	1.1
+++ ext/iconv/depend	17 Jul 2003 00:13:05 -0000
@@ -1,2 +1,7 @@
 iconv.o: iconv.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h \
   $(hdrdir)/intern.h
+
+all: iconv-map.rb
+
+iconv-map.rb: config.charset
+	$(RUBY) $(srcdir)/charset_alias.rb $< $@
Index: ext/iconv/extconf.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/iconv/extconf.rb,v
retrieving revision 1.2
diff -u -2 -p -r1.2 extconf.rb
--- ext/iconv/extconf.rb	18 Mar 2002 03:54:10 -0000	1.2
+++ ext/iconv/extconf.rb	16 Jul 2003 23:59:28 -0000
@@ -1,8 +1,12 @@
 require 'mkmf'
 
+# http://www.ctan.org/tex-archive/macros/texinfo/texinfo/intl/config.charset
+# at Fri, 30 May 2003 00:09:00 GMT
+
 dir_config("iconv")
 
 if have_header("iconv.h")
   have_library("iconv")
+  $INSTALLFILES = [["./iconv-map.rb", "$(RUBYLIBDIR)"]]
   create_makefile("iconv")
 end
Index: ext/iconv/iconv.c
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/iconv/iconv.c,v
retrieving revision 1.6
diff -u -2 -p -r1.6 iconv.c
--- ext/iconv/iconv.c	4 May 2003 16:03:14 -0000	1.6
+++ ext/iconv/iconv.c	10 Jul 2003 13:10:16 -0000
@@ -64,4 +64,5 @@ static VALUE iconv_failure_failed _((VAL
 
 static iconv_t iconv_create _((VALUE to, VALUE from));
+static void iconv_dfree _((void *cd));
 static VALUE iconv_free _((VALUE cd));
 static VALUE iconv_try _((iconv_t cd, const char **inptr, size_t *inlen, char **outptr, size_t *outlen));
@@ -123,4 +124,18 @@ iconv_create
 }
 
+static void
+iconv_dfree
+#ifdef HAVE_PROTOTYPES
+(void *cd)
+#else /* HAVE_PROTOTYPES */
+    (cd)
+    void *cd;
+#endif /* HAVE_PROTOTYPES */
+{
+    iconv_close(VALUE2ICONV(cd));
+}
+
+#define ICONV_FREE iconv_dfree
+
 static VALUE
 iconv_free
@@ -137,6 +152,4 @@ iconv_free
 }
 
-#define ICONV_FREE (RUBY_DATA_FUNC)iconv_free
-
 static VALUE
 iconv_try
@@ -189,5 +202,5 @@ iconv_failure_initialize
 #endif /* HAVE_PROTOTYPES */
 {
-    if (!rb_ivar_defined(error, rb_mesg) || NIL_P(rb_ivar_get(error, rb_mesg)))
+    if (NIL_P(rb_attr_get(error, rb_mesg)))
 	rb_ivar_set(error, rb_mesg, rb_inspect(failed));
     if (env) {
@@ -479,4 +492,22 @@ iconv_s_iconv
 }
 
+static VALUE
+iconv_s_conv
+#ifdef HAVE_PROTOTYPES
+    (VALUE self, VALUE to, VALUE from, VALUE str)
+#else /* HAVE_PROTOTYPES */
+    (self, to, from, str)
+    VALUE self, to, from, str;
+#endif /* HAVE_PROTOTYPES */
+{
+    struct iconv_env_t arg;
+
+    arg.argc = 1;
+    arg.argv = &str;
+    arg.ret = rb_str_new(0, 0);
+    arg.cd = iconv_create(to, from);
+    return rb_ensure(iconv_s_convert, (VALUE)&arg, iconv_free, ICONV2VALUE(arg.cd));
+}
+
 
 /*
@@ -691,7 +722,13 @@ Init_iconv _((void))
 {
     VALUE rb_cIconv = rb_define_class("Iconv", rb_cData);
+    VALUE metaclass = RBASIC(rb_cIconv)->klass;
+
     rb_define_alloc_func(rb_cIconv, iconv_s_allocate);
     rb_define_singleton_method(rb_cIconv, "open", iconv_s_open, 2);
     rb_define_singleton_method(rb_cIconv, "iconv", iconv_s_iconv, -1);
+    rb_define_singleton_method(rb_cIconv, "conv", iconv_s_conv, 3);
+    rb_enable_super(metaclass, "open");
+    rb_enable_super(metaclass, "iconv");
+    rb_enable_super(metaclass, "conv");
     rb_define_method(rb_cIconv, "initialize", iconv_initialize, 2);
     rb_define_method(rb_cIconv, "close", iconv_finish, 0);
Index: ext/iconv/lib/iconv.rb
===================================================================
RCS file: ext/iconv/lib/iconv.rb
diff -N ext/iconv/lib/iconv.rb
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ext/iconv/lib/iconv.rb	13 Jul 2003 23:35:48 -0000
@@ -0,0 +1,36 @@
+require 'iconv.so'
+begin
+  require 'iconv-map.rb'
+rescue LoadError
+else
+  unless Iconv::CharsetMap.empty?
+    class Iconv
+      init = instance_method(:initialize)
+      open = method(:open)
+      iconv = method(:iconv)
+      include mod = Module.new {
+        define_method(:initialize, init)
+      }
+      extend class << mod
+               define_method(:open, open)
+               define_method(:iconv, iconv)
+               self
+             end
+      def initialize(to, from)
+        to = Sysdep.fetch(to.downcase) {to}
+        from = Sysdep.fetch(from.downcase) {from}
+        super(to, from, *args)
+      end
+      def self.open(to, from)
+        to = Sysdep.fetch(to.downcase) {to}
+        from = Sysdep.fetch(from.downcase) {from}
+        super(to, from, *args)
+      end
+      def self.iconv(to, from, *args)
+        to = Sysdep.fetch(to.downcase) {to}
+        from = Sysdep.fetch(from.downcase) {from}
+        super(to, from, *args)
+      end
+    end
+  end
+end
