Index: Lib/distutils/msvc9compiler.py =================================================================== --- Lib/distutils/msvc9compiler.py (revision 81049) +++ Lib/distutils/msvc9compiler.py (working copy) @@ -656,17 +656,19 @@ mfid = 1 else: mfid = 2 - self._remove_visual_c_ref(temp_manifest) - out_arg = '-outputresource:%s;%s' % (output_filename, mfid) - try: - self.spawn(['mt.exe', '-nologo', '-manifest', - temp_manifest, out_arg]) - except DistutilsExecError, msg: - raise LinkError(msg) + if os.path.splitext(output_filename)[1].lower() == '.pyd': + self._remove_visual_c_ref(temp_manifest, ld_args) + if not '/MANIFEST:NO' in ld_args: + out_arg = '-outputresource:%s;%s' % (output_filename, mfid) + try: + self.spawn(['mt.exe', '-nologo', '-manifest', + temp_manifest, out_arg]) + except DistutilsExecError, msg: + raise LinkError(msg) else: log.debug("skipping %s (up-to-date)", output_filename) - def _remove_visual_c_ref(self, manifest_file): + def _remove_visual_c_ref(self, manifest_file, ld_args): try: # Remove references to the Visual C runtime, so they will # fall through to the Visual C dependency of Python.exe. @@ -674,6 +676,8 @@ # runtimes are not in WinSxS folder, but in Python's own # folder), the runtimes do not need to be in every folder # with .pyd's. + # Append '/MANIFEST:NO' to ld_args if no dependencies other + # than MSVC are found. manifest_f = open(manifest_file) try: manifest_buf = manifest_f.read() @@ -686,6 +690,11 @@ manifest_buf = re.sub(pattern, "", manifest_buf) pattern = "\s*" manifest_buf = re.sub(pattern, "", manifest_buf) + pattern = re.compile( + r"""|)""", re.DOTALL) + if re.search(pattern, manifest_buf) is None: + ld_args.append('/MANIFEST:NO') manifest_f = open(manifest_file, 'w') try: manifest_f.write(manifest_buf)