* ext/extmk.rb (extmake): not continue making when extconf.rb
  failed.

* win32/Makefile.sub, bcc32/Makefile.sub, wince/Makefile.sub:
  define exec_prefix and libdir.

* lib/mkmf.rb (pkg_config): use --libs output except with
  only-L for other options.  [ruby-list:38099]

* lib/mkmf.rb (create_makefile): separate rule for static
  library from shared object.

Index: Makefile.in
===================================================================
RCS file: /src/ruby/Makefile.in,v
retrieving revision 1.45
diff -u -2 -p -r1.45 Makefile.in
--- Makefile.in	12 Aug 2003 02:12:48 -0000	1.45
+++ Makefile.in	16 Aug 2003 04:55:35 -0000
@@ -197,10 +197,10 @@ Makefile:	$(srcdir)/Makefile.in
 @MAKEFILES@: config.status
 		MAKE=$(MAKE) $(SHELL) ./config.status
-		@{ : $(MAKE); \
+		@{ \
 		    echo "all:; -@rm -f conftest.mk"; \
 		    echo "conftest.mk: .force; @echo AUTO_REMAKE"; \
 		    echo ".force:"; \
-		} > conftest.mk
-		@$(MAKE) -f conftest.mk | grep '^AUTO_REMAKE$$' >/dev/null 2>&1 || \
+		} > conftest.mk || exit 1; \
+		$(MAKE) -f conftest.mk | grep '^AUTO_REMAKE$$' >/dev/null 2>&1 || \
 		{ echo "Makefile updated, restart."; exit 1; }
 
Index: ext/extmk.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/ext/extmk.rb,v
retrieving revision 1.41
diff -u -2 -p -r1.41 extmk.rb
--- ext/extmk.rb	12 Aug 2003 08:06:22 -0000	1.41
+++ ext/extmk.rb	14 Aug 2003 07:11:14 -0000
@@ -62,7 +62,8 @@ def extmake(target)
     $srcdir = File.join($top_srcdir, "ext", $mdir)
     $preload = nil
+    makefile = "./Makefile"
     unless $ignore
       if $static ||
-	 !(t = modified?("./Makefile", MTIMES)) ||
+	 !(t = modified?(makefile, MTIMES)) ||
 	 %W<#{$srcdir}/makefile.rb #{$srcdir}/extconf.rb
 	    #{$srcdir}/depend #{$srcdir}/MANIFEST>.any? {|f| modified?(f, [t])}
@@ -71,4 +72,5 @@ def extmake(target)
 	Logging::logfile 'mkmf.log'
 	Config::CONFIG["srcdir"] = $srcdir
+	rm_f makefile
 	begin
 	  if File.exist?($0 = "#{$srcdir}/makefile.rb")
@@ -79,4 +81,5 @@ def extmake(target)
 	    create_makefile(target)
 	  end
+	  File.exist?(makefile)
 	rescue SystemExit
 	  # ignore
@@ -86,17 +89,18 @@ def extmake(target)
 	  Config::CONFIG["srcdir"] = $top_srcdir
 	end
+      else
+	true
       end
+    end or open(makefile, "w") do |f|
+      f.print dummy_makefile($srcdir)
+      return true
     end
-    if File.exist?("./Makefile")
-      if $static
-	$extlist.push [$static, $target, File.basename($target), $preload]
-      end
-      unless system($make, *sysquote($mflags))
-	$ignore or $continue or return false
-      end
-    else
-      open("./Makefile", "w") {|f|
-        f.print dummy_makefile($srcdir)
-      }
+    args = sysquote($mflags)
+    if $static
+      args += ["static"]
+      $extlist.push [$static, $target, File.basename($target), $preload]
+    end
+    unless system($make, *args)
+      $ignore or $continue or return false
     end
     if $static
Index: win32/Makefile.sub
===================================================================
RCS file: /cvs/ruby/src/ruby/win32/Makefile.sub,v
retrieving revision 1.48
diff -u -2 -p -r1.48 Makefile.sub
--- win32/Makefile.sub	5 Jun 2003 09:38:01 -0000	1.48
+++ win32/Makefile.sub	12 Aug 2003 10:27:25 -0000
@@ -1,2 +1,4 @@
+# -*- makefile -*-
+
 SHELL = $(COMSPEC)
 
@@ -75,4 +77,10 @@ DEBUGFLAGS = -Zi
 prefix = /usr
 !endif
+!if !defined(exec_prefix)
+exec_prefix = $(prefix)
+!endif
+!if !defined(libdir)
+libdir = $(exec_prefix)/lib
+!endif
 !if !defined(DESTDIR)
 DESTDIR = $(prefix)
Index: bcc32/Makefile.sub
===================================================================
RCS file: /cvs/ruby/src/ruby/bcc32/Makefile.sub,v
retrieving revision 1.31
diff -u -2 -p -r1.31 Makefile.sub
--- bcc32/Makefile.sub	8 Aug 2003 03:35:45 -0000	1.31
+++ bcc32/Makefile.sub	12 Aug 2003 10:29:39 -0000
@@ -1,2 +1,4 @@
+# -*- makefile -*-
+
 SHELL = $(COMSPEC)
 
@@ -83,4 +85,10 @@ OPTFLAGS = -O
 !ifndef prefix
 prefix = /usr
+!endif
+!ifndef exec_prefix
+exec_prefix = $(prefix)
+!endif
+!ifndef libdir
+libdir = $(exec_prefix)/lib
 !endif
 !ifndef DESTDIR
Index: wince/Makefile.sub
===================================================================
RCS file: /cvs/ruby/src/ruby/wince/Makefile.sub,v
retrieving revision 1.6
diff -u -2 -p -r1.6 Makefile.sub
--- wince/Makefile.sub	21 Jun 2003 04:55:59 -0000	1.6
+++ wince/Makefile.sub	12 Aug 2003 10:31:06 -0000
@@ -1,2 +1,4 @@
+# -*- makefile -*-
+
 SHELL = $(COMSPEC)
 
@@ -78,4 +80,10 @@ RUBY_SO_NAME = $(RT)-$(RUBY_INSTALL_NAME
 !if !defined(prefix)
 prefix = /usr
+!endif
+!if !defined(exec_prefix)
+exec_prefix = $(prefix)
+!endif
+!if !defined(libdir)
+libdir = $(exec_prefix)/lib
 !endif
 !if !defined(DESTDIR)
Index: lib/mkmf.rb
===================================================================
RCS file: /cvs/ruby/src/ruby/lib/mkmf.rb,v
retrieving revision 1.145
diff -u -2 -p -r1.145 mkmf.rb
--- lib/mkmf.rb	6 Aug 2003 08:28:52 -0000	1.145
+++ lib/mkmf.rb	14 Aug 2003 08:22:31 -0000
@@ -651,6 +651,7 @@ def pkg_config(pkg)
   if $PKGCONFIG and system("#{$PKGCONFIG} --exists #{pkg}")
     cflags = `#{$PKGCONFIG} --cflags #{pkg}`.chomp
-    ldflags = `#{$PKGCONFIG} --libs-only-L #{pkg}`.chomp
+    ldflags = `#{$PKGCONFIG} --libs #{pkg}`.chomp
     libs = `#{$PKGCONFIG} --libs-only-l #{pkg}`.chomp
+    ldflags = (Shellwords.shellwords(ldflags) - Shellwords.shellwords(libs)).quote.join(" ")
     $CFLAGS += " " << cflags
     $LDFLAGS += " " << ldflags
@@ -806,5 +807,6 @@ def create_makefile(target, srcprefix = 
   libpath = libpathflag(libpath)
 
-  dllib = target ? "$(TARGET).#{$static ? $LIBEXT : CONFIG['DLEXT']}" : ""
+  dllib = target ? "$(TARGET).#{CONFIG['DLEXT']}" : ""
+  staticlib = target ? "$(TARGET).#$LIBEXT" : ""
   mfile = open("Makefile", "wb")
   mfile.print configuration(srcdir)
@@ -822,4 +824,5 @@ OBJS = #{$objs}
 TARGET = #{target}
 DLLIB = #{dllib}
+STATIC_LIB = #{staticlib}
 }
   if $extmk
@@ -841,4 +844,5 @@ CLEANOBJS     = "*.{#{$OBJEXT},#{$LIBEXT
 
 all:		#{target ? "$(DLLIB)" : "Makefile"}
+static:		$(STATIC_LIB)
 }
   mfile.print CLEANINGS
@@ -895,11 +899,9 @@ all:		#{target ? "$(DLLIB)" : "Makefile"
   mfile.print "@-$(RM) $@\n\t"
   mfile.print "@-$(RM) $(TARGET).lib\n\t" if $mswin
-  if $static
-    mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$(DLLIB) $(OBJS)"
-    if ranlib = config_string('RANLIB')
-      mfile.print "\n\t@-#{ranlib} $(DLLIB) 2> /dev/null || true"
-    end
-  else
-    mfile.print LINK_SO
+  mfile.print LINK_SO, "\n\n"
+  mfile.print "$(STATIC_LIB): $(OBJS)\n\t"
+  mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$@ $(OBJS)"
+  if ranlib = config_string('RANLIB')
+    mfile.print "\n\t@-#{ranlib} $(DLLIB) 2> /dev/null || true"
   end
   mfile.print "\n\n"
