Index: lib/mkmf.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/lib/mkmf.rb,v
retrieving revision 1.143
diff -u -2 -p -r1.143 mkmf.rb
--- lib/mkmf.rb	2 Aug 2003 05:54:00 -0000	1.143
+++ lib/mkmf.rb	3 Aug 2003 14:34:22 -0000
@@ -741,11 +741,15 @@ def create_makefile(target, srcprefix = 
   unless $objs then
     $objs = []
-    for f in Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
+    for f in srcs = Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
       $objs.push(File.basename(f, ".*") << "." << $OBJEXT)
     end
+    re = /\A#{Regexp.quote(srcdir)}\//
+    prefix = $nmake ? '{$(srcdir)}' : '$(srcdir)/'
+    $srcs ||= srcs.map{|src| src.sub(re, prefix)}.join(" ")
   else
     for i in $objs
       i.sub!(/\.o\z/, ".#{$OBJEXT}")
     end
+    $srcs ||= "$(OBJS:.#{$OBJEXT}=.c)"
   end
   $objs = $objs.join(" ")
@@ -795,4 +799,5 @@ target_prefix = #{target_prefix}
 LOCAL_LIBS = #{$LOCAL_LIBS}
 LIBS = #{$LIBRUBYARG} #{$libs} #{$LIBS}
+SRCS = #{$srcs}
 OBJS = #{$objs}
 TARGET = #{target}
@@ -892,4 +897,10 @@ all:		#{target ? "$(DLLIB)" : "Makefile"
       end
     end
+  else
+    open("GNUmakefile", "w") do |file|
+      file.puts %w"Makefile .depend".map {|f| "include #{f}"}
+      file.print ".depend: $(SRCS)\n"
+      file.print "\t$(RUBY) -run -e mkdep 'topdir=$(topdir)' 'srcdir=$(srcdir)' 'hdrdir=$(hdrdir)' -- $(CFLAGS) $(CPPFLAGS) $^"
+    end
   end
 ensure
@@ -915,4 +926,5 @@ def init_mkmf(config = CONFIG)
   $INSTALLFILES = nil
 
+  $srcs = nil
   $objs = nil
   $libs = ""
Index: lib/un.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/lib/un.rb,v
retrieving revision 1.4
diff -u -2 -p -r1.4 un.rb
--- lib/un.rb	3 Aug 2003 09:32:23 -0000	1.4
+++ lib/un.rb	3 Aug 2003 12:59:18 -0000
@@ -32,8 +32,12 @@ end
 def setup(options = "")
   options += "v"
+  opt = true
   ARGV.map! do |x|
     case x
+    when '--'
+      opt = false
+      nil
     when /^-/
-      x.delete "^-#{options}"
+       opt ? x.delete("^-#{options}") : x
     when /[*?\[{]/
       Dir[x]
@@ -43,5 +47,6 @@ def setup(options = "")
   end
   ARGV.flatten!
-  ARGV.delete_if{|x| x == '-'}
+  ARGV.compact!
+  ARGV.delete_if{|x| /\A--?\z/ === x}
   getopts(options)
   options = {}
@@ -203,4 +208,35 @@ def touch
   setup do |argv, options|
     FileUtils.touch argv, options
+  end
+end
+
+##
+# Make dependency file
+#
+#   ruby -run -e mkdep -- [var=value]... -- [INPUT]
+
+def mkdep
+  setup do |argv,|
+    require 'mkmf'
+    if /gcc/ =~ Config::CONFIG["CC"]
+      cmd = Config::CONFIG["CC"] + " -MM"
+    else
+      cmd = find_executable0("mkdep")
+    end
+    pat = {}
+    while /\A(\w+)=(.*)/ =~ ARGV[0]
+      ARGV.shift
+      var, val = "$(#{$1})/", Regexp.quote($2) + "/"
+      val.sub(/\A/, '(\A|\s)')
+      pat[Regexp.new(val)] = var
+    end
+    ARGV.shift if ARGV[0] == '--'
+    IO.popen("#{cmd} #{ARGV.join(' ')}") do |inp|
+      open(".depend", "w") do |dep|
+        inp.each do |line|
+          dep.print pat.inject(line) {|line, (re, s)| line.gsub(re) {"#{$1}#{s}"}}
+        end
+      end
+    end
   end
 end
Index: ext/openssl/extconf.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/openssl/extconf.rb,v
retrieving revision 1.13
diff -u -2 -p -r1.13 extconf.rb
--- ext/openssl/extconf.rb	2 Aug 2003 05:54:00 -0000	1.13
+++ ext/openssl/extconf.rb	3 Aug 2003 15:20:20 -0000
@@ -92,30 +92,3 @@ have_header("openssl/ocsp.h")
 $distcleanfiles << "GNUmakefile" << "dep"
 create_makefile("openssl")
-if /gcc/ =~ CONFIG["CC"]
-  File.open("GNUmakefile", "w") {|f|
-    f.print <<EOD
-include Makefile
-
-SRCS = $(OBJS:.o=.c)
-
-test-link: $(OBJS)
-	$(CC) $(DLDFLAGS) #{OUTFLAG}.testlink $(OBJS) $(LIBPATH) $(LIBS) $(LOCAL_LIBS)
-	@$(RM) .testlink
-	@echo "Done."
-
-dep: $(SRCS)
-	$(CC) $(CFLAGS) $(CPPFLAGS) -c $^ -MM | \\
-	$(RUBY) -p -e 'BEGIN{S = []' \\
-		-e 'while !ARGV.empty? and /^(\\w+)=(.*)/ =~ ARGV[0]' \\
-		  -e 'S << [/\#{Regexp.quote($$2)}\\//, "$$(\#{$$1})/"]' \\
-		  -e 'ARGV.shift' \\
-		-e 'end' \\
-		-e '}' -e 'S.each(&method(:gsub!))' -- \\
-            'topdir=$(topdir)' 'srcdir=$(srcdir)' 'hdrdir=$(hdrdir)' \\
-	> dep
-
-include dep
-EOD
-  }
-end
 message "Done.\n"
