Index: build.conf
===================================================================
--- build.conf	(revision 6623)
+++ build.conf	(working copy)
@@ -265,6 +265,11 @@
 libs = libsvn_subr $(SVN_APR_LIBS)
 description = Subversion core library bindings
 
+[swig_runtime]
+type = swig_runtime
+path = subversion/bindings/swig
+description = Swig language runtime libraries
+
 # SWIG utility library for Python modules
 [libsvn_swig_py]
 type = lib
Index: build/generator/msvc_dsp.ezt
===================================================================
--- build/generator/msvc_dsp.ezt	(revision 6623)
+++ build/generator/msvc_dsp.ezt	(working copy)
@@ -70,8 +70,9 @@
 InputPath=[sources.path]
 
 [sources.swig_target] : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
-	swig -[sources.swig_language][for includes] -I"[includes]"[end] -o [sources.swig_output] $(InputPath)
-	
+[if-any sources.swig_output]	swig -c -[sources.swig_language][for includes] -I"[includes]"[end] -o [sources.swig_output] $(InputPath)
+[else]	$(InputPath) [sources.swig_language] [sources.swig_target]
+[end]
 # End Custom Build
 
 [end]
Index: build/generator/gen_vcnet_vcproj.py
===================================================================
--- build/generator/gen_vcnet_vcproj.py	(revision 6623)
+++ build/generator/gen_vcnet_vcproj.py	(working copy)
@@ -37,8 +37,6 @@
         #LIB
         config_type=4
         target.output_name = '%s-%d.lib' % (target.name, self.cfg.version)
-    elif isinstance(target, gen_base.TargetExternal):
-      return
     elif isinstance(target, gen_base.TargetUtility):
       config_type=1
       target.output_name = target.name + '.exe'
@@ -135,7 +133,8 @@
     for target in install_targets:
       name = target.name
       # These aren't working yet
-      if isinstance(target, gen_base.TargetScript) \
+      if isinstance(target, gen_base.TargetScript)      \
+         or isinstance(target, gen_base.TargetExternal) \
          or isinstance(target, gen_base.TargetSWIG):
         continue
 
@@ -169,7 +168,7 @@
                             depends=deplist,
                             ))
 
-    targets.sort()
+    targets.sort(lambda x, y: cmp(x.name, y.name))
 
     configs = [ ]
     for i in range(len(self.configs)):
Index: build/generator/vcnet_vcproj.ezt
===================================================================
--- build/generator/vcnet_vcproj.ezt	(revision 6623)
+++ build/generator/vcnet_vcproj.ezt	(working copy)
@@ -95,8 +95,9 @@
 				Name="[configs.name]|Win32">
 				<Tool
 					Name="VCCustomBuildTool"
-					CommandLine="swig -[sources.swig_language][for includes] -I&quot;[includes]&quot;[end] -o &quot;[sources.swig_output]&quot; $(InputPath)"
-					AdditionalDependencies="[for sources.user_deps]&quot;[sources.user_deps]&quot;;[end]"
+					[if-any sources.swig_output]CommandLine="swig -c -[sources.swig_language][for includes] -I&quot;[includes]&quot;[end] -o &quot;[sources.swig_output]&quot; $(InputPath)"
+					[else]CommandLine="$(InputPath) [sources.swig_language] [sources.swig_target]"
+					[end]AdditionalDependencies="[for sources.user_deps]&quot;[sources.user_deps]&quot;;[end]"
 					Outputs="&quot;[sources.swig_target]&quot;"/>
 			</FileConfiguration>
 [end][end]
Index: build/generator/gen_base.py
===================================================================
--- build/generator/gen_base.py	(revision 6623)
+++ build/generator/gen_base.py	(working copy)
@@ -321,14 +321,12 @@
   ### stupid Target vs DependencyNode
   add_deps = ''
 
-  def __init__(self, fname, lang, desc):
+  def __init__(self, fname, name, lang, desc):
     DependencyNode.__init__(self, fname)
+    self.name = name
     self.lang = lang
     self.lang_abbrev = lang_abbrev[lang]
-
     self.path = os.path.dirname(fname)
-
-    self.name = lang + os.path.splitext(os.path.basename(fname))[0]
     self.desc = desc + ' for ' + lang_full_name[lang]
 
     ### maybe tweak to avoid these duplicate attrs
@@ -338,6 +336,9 @@
     ### hmm. this is Makefile-specific
     self.link_cmd = '$(LINK_%s_WRAPPER)' % string.upper(self.lang_abbrev)
 
+class SWIGRuntimeLibrary(SWIGLibrary):
+  pass
+
 class ExternalLibrary(DependencyNode):
   pass
 
@@ -512,10 +513,12 @@
 
     ### we should really extract the %module line
     if iname[:4] == 'svn_':
-      libname = iname[3:-2] + self._libext
+      libname = iname[3:-2]
     else:
-      libname = '_' + iname[:-2] + self._libext
+      libname = '_' + iname[:-2]
 
+    libfile = libname + self._libext
+
     ifile = SWIGSource(ipath)
 
     for lang in self.cfg.swig_lang:
@@ -530,26 +533,58 @@
       graph.add(DT_OBJECT, ofile, cfile)
 
       # the library depends upon the object
-      library = SWIGLibrary(os.path.join(dir, lang, libname), lang, self.desc)
-      graph.add(DT_LINK, library, ofile)
+      library = SWIGLibrary(os.path.join(dir, lang, libfile),
+                            lang + libname, lang, self.desc)
+      graph.add(DT_LINK, library.name, ofile)
 
       # add some more libraries
       for lib in self.libs:
-        graph.add(DT_LINK, library, lib)
+        graph.add(DT_LINK, library.name, lib)
 
       # add some language-specific libraries for languages other than
       # Java (SWIG doesn't seem to provide a libswigjava.so)
       if abbrev != 'java':
         ### fix this. get these from the .conf file
-        graph.add(DT_LINK, library, ExternalLibrary('-lswig' + abbrev))
+        graph.add(DT_LINK, library.name, ExternalLibrary('-lswig' + abbrev))
       ### fix this, too. find the right Target swigutil lib. we know there
       ### will be only one.
       util = graph.get_sources(DT_INSTALL, 'swig-%s-lib' % abbrev)[0]
-      graph.add(DT_LINK, library, util)
+      graph.add(DT_LINK, library.name, util)
 
       # the specified install area depends upon the library
       graph.add(DT_INSTALL, self.install + '-' + abbrev, library)
 
+class TargetSWIGRuntime(TargetSWIG):
+  default_install = 'swig_runtime'
+
+  def add_dependencies(self, src_patterns, graph):
+    self._libraries = {}
+    for lang in self.cfg.swig_lang:
+      if lang == 'java':
+        # java doesn't seem to have a separate runtime  
+        continue
+
+      abbrev = lang_abbrev[lang]
+
+      name = 'swig' + abbrev
+      cname = name + '.c'
+      oname = name + self._objext
+      libname = name + self._libext
+
+      cfile = SWIGObject(os.path.join(self.path, lang, cname), lang)
+      ofile = SWIGObject(os.path.join(self.path, lang, oname), lang)
+      graph.add(DT_OBJECT, ofile, cfile)
+
+      library = SWIGRuntimeLibrary(os.path.join(self.path, lang, libname),
+                                   lang + '_runtime', lang, self.desc)
+      graph.add(DT_LINK, library.name, ofile)
+
+      self._libraries[lang] = library
+      graph.add(DT_INSTALL, self.install + '-' + abbrev, library)
+
+  def get_library(self, lang):
+    return self._libraries.get(lang, None)
+
 ### I don't think this should be TargetLinked, but 'apr' uses the 'libs'
 ### option, which means we need to make this TargetLinked so that the
 ### GeneratorBase.__init__ method will process libs on this target.
@@ -580,6 +615,7 @@
   'project' : TargetProject,
   'external' : TargetExternal,
   'utility' : TargetUtility,
+  'swig_runtime' : TargetSWIGRuntime,
   'swig_utility' : TargetSWIGUtility,
   }
 
Index: build/generator/gen_make.py
===================================================================
--- build/generator/gen_make.py	(revision 6623)
+++ build/generator/gen_make.py	(working copy)
@@ -35,10 +35,7 @@
         # there is nothing to build
         continue
 
-      if isinstance(target_ob, gen_base.SWIGLibrary):
-        sources = self.graph.get_sources(gen_base.DT_LINK, target_ob.fname)
-      else:
-        sources = self.graph.get_sources(gen_base.DT_LINK, target_ob.name)
+      sources = self.graph.get_sources(gen_base.DT_LINK, target_ob.name)
 
       target = target_ob.name
       path = target_ob.path
Index: build/generator/gen_win.py
===================================================================
--- build/generator/gen_win.py	(revision 6623)
+++ build/generator/gen_win.py	(working copy)
@@ -262,16 +262,21 @@
                                    swig_language=None))
 
     if isinstance(target, gen_base.SWIGLibrary):
-      for obj in self.graph.get_sources(gen_base.DT_LINK, target):
+      for obj in self.graph.get_sources(gen_base.DT_LINK, target.name):
         if isinstance(obj, gen_base.SWIGObject):
           for cobj in self.graph.get_sources(gen_base.DT_OBJECT, obj):
             if isinstance(cobj, gen_base.SWIGObject):
               csrc = rootpath + '\\' + string.replace(cobj.fname, '/', '\\')
-              sources.append(ProjectItem(path=csrc, reldir=None, user_deps=[],
-                                         swig_language=None))
 
+              if isinstance(target, gen_base.SWIGRuntimeLibrary):
+                bsrc = rootpath + "\\build\\win32\\gen_swig_runtime.bat"
+                sources.append(ProjectItem(path=bsrc, reldir=None, user_deps=[],
+                                           swig_language=target.lang,
+                                           swig_target=csrc, swig_output=None))
+                continue
+
               # output path passed to swig has to use forward slashes,
-              # otherwise the generatated python files (for shadow
+              # otherwise the generated python files (for shadow
               # classes) will be saved to the wrong directory
               cout = string.replace(os.path.join(rootpath, cobj.fname),
                                     os.sep, '/')
@@ -290,7 +295,7 @@
                                            user_deps=user_deps,
                                            swig_language=target.lang,
                                            swig_target=csrc, swig_output=cout))
-        
+
     sources.sort(lambda x, y: cmp(x.path, y.path))
     return sources
   
@@ -350,10 +355,13 @@
       else:
         depends.extend(self.get_unique_win_depends(target))
     elif isinstance(target, gen_base.SWIGLibrary):
-      for lib in self.graph.get_sources(gen_base.DT_LINK, target):
+      for lib in self.graph.get_sources(gen_base.DT_LINK, target.name):
         if hasattr(lib, 'proj_name'):
           depends.append(lib)
-          depends.extend(self.get_win_depends(lib, 0))          
+          depends.extend(self.get_win_depends(lib, 0))
+      if not isinstance(target, gen_base.SWIGRuntimeLibrary):
+        runtime = self.targets['swig_runtime'].get_library(target.lang)
+        if runtime: depends.append(runtime)
     else:
       assert 0
       
@@ -500,12 +508,15 @@
       return libs
 
     if isinstance(target, gen_base.SWIGLibrary):
-      return [ self.dblibname+(cfg == 'Debug' and 'd.lib' or '.lib'),
+      libs = [ self.dblibname+(cfg == 'Debug' and 'd.lib' or '.lib'),
                'mswsock.lib',
                'ws2_32.lib',
                'advapi32.lib',
                'rpcrt4.lib',
                'shfolder.lib' ]
+      if target.lang == 'perl':
+        libs.append('perl56.lib')
+      return libs
 
     if not isinstance(target, gen_base.TargetExe):
       return []
Index: build/generator/gen_msvc_dsp.py
===================================================================
--- build/generator/gen_msvc_dsp.py	(revision 6623)
+++ build/generator/gen_msvc_dsp.py	(working copy)
@@ -123,7 +123,8 @@
                             dsp=string.replace(fname, os.sep, '\\'),
                             depends=dep_names))
 
-    targets.sort()
+    targets.sort(lambda x, y: cmp(x.name, y.name))
+
     data = {
       'targets' : targets,
       }

