@@ -160,7 +160,7 @@ def run (self):
160160
161161 # 'self.extensions', as supplied by setup.py, is a list of
162162 # Extension instances. See the documentation for Extension (in
163- # distutils.core ) for details.
163+ # distutils.extension ) for details.
164164 #
165165 # For backwards compatibility with Distutils 0.8.2 and earlier, we
166166 # also allow the 'extensions' list to be a list of tuples:
@@ -395,6 +395,11 @@ def build_extensions (self):
395395 if os .environ .has_key ('CFLAGS' ):
396396 extra_args .extend (string .split (os .environ ['CFLAGS' ]))
397397
398+ # Run any platform/compiler-specific hooks needed before
399+ # compiling (currently none, but any hypothetical subclasses
400+ # might find it useful to override this).
401+ self .precompile_hook ()
402+
398403 objects = self .compiler .compile (sources ,
399404 output_dir = self .build_temp ,
400405 #macros=macros,
@@ -409,41 +414,9 @@ def build_extensions (self):
409414 objects .extend (ext .extra_objects )
410415 extra_args = ext .extra_link_args
411416
412- # XXX this is a kludge! Knowledge of specific compilers or
413- # platforms really doesn't belong here; in an ideal world, the
414- # CCompiler interface would provide access to everything in a
415- # compiler/linker system needs to build Python extensions, and
416- # we would just do everything nicely and cleanly through that
417- # interface. However, this is a not an ideal world and the
418- # CCompiler interface doesn't handle absolutely everything.
419- # Thus, kludges like this slip in occasionally. (This is no
420- # excuse for committing more platform- and compiler-specific
421- # kludges; they are to be avoided if possible!)
422- if self .compiler .compiler_type == 'msvc' :
423- def_file = ext .export_symbol_file
424- if def_file is None :
425- source_dir = os .path .dirname (sources [0 ])
426- ext_base = (string .split (ext .name , '.' ))[- 1 ]
427- def_file = os .path .join (source_dir , "%s.def" % ext_base )
428- if not os .path .exists (def_file ):
429- def_file = None
430-
431- if def_file is not None :
432- extra_args .append ('/DEF:' + def_file )
433- else :
434- modname = string .split (ext .name , '.' )[- 1 ]
435- extra_args .append ('/export:init%s' % modname )
436-
437- # The MSVC linker generates unneeded .lib and .exp files,
438- # which cannot be suppressed by any linker switches. So
439- # make sure they are generated in the temporary build
440- # directory.
441- implib_file = os .path .join (
442- self .build_temp ,
443- self .get_ext_libname (ext .name ))
444- extra_args .append ('/IMPLIB:' + implib_file )
445- self .mkpath (os .path .dirname (implib_file ))
446- # if MSVC
417+ # Run any platform/compiler-specific hooks needed between
418+ # compiling and linking (currently needed only on Windows).
419+ self .prelink_hook ()
447420
448421 self .compiler .link_shared_object (
449422 objects , ext_filename ,
@@ -456,13 +429,67 @@ def build_extensions (self):
456429 # build_extensions ()
457430
458431
432+ # -- Hooks ---------------------------------------------------------
433+
434+ def precompile_hook (self ):
435+ pass
436+
437+ def prelink_hook (self ):
438+
439+ # XXX this is a kludge! Knowledge of specific compilers or
440+ # platforms really doesn't belong here; in an ideal world, the
441+ # CCompiler interface would provide access to everything in a
442+ # compiler/linker system needs to build Python extensions, and
443+ # we would just do everything nicely and cleanly through that
444+ # interface. However, this is a not an ideal world and the
445+ # CCompiler interface doesn't handle absolutely everything.
446+ # Thus, kludges like this slip in occasionally. (This is no
447+ # excuse for committing more platform- and compiler-specific
448+ # kludges; they are to be avoided if possible!)
449+ if self .compiler .compiler_type == 'msvc' :
450+ def_file = ext .export_symbol_file
451+ if def_file is None :
452+ source_dir = os .path .dirname (sources [0 ])
453+ ext_base = (string .split (ext .name , '.' ))[- 1 ]
454+ def_file = os .path .join (source_dir , "%s.def" % ext_base )
455+ if not os .path .exists (def_file ):
456+ def_file = None
457+
458+ if def_file is not None :
459+ extra_args .append ('/DEF:' + def_file )
460+ else :
461+ modname = string .split (ext .name , '.' )[- 1 ]
462+ extra_args .append ('/export:init%s' % modname )
463+
464+ # The MSVC linker generates unneeded .lib and .exp files,
465+ # which cannot be suppressed by any linker switches. So
466+ # make sure they are generated in the temporary build
467+ # directory.
468+ implib_file = os .path .join (
469+ self .build_temp ,
470+ self .get_ext_libname (ext .name ))
471+ extra_args .append ('/IMPLIB:' + implib_file )
472+ self .mkpath (os .path .dirname (implib_file ))
473+ # if MSVC
474+
475+ # prelink_hook ()
476+
477+
478+ # -- Name generators -----------------------------------------------
479+ # (extension names, filenames, whatever)
480+
459481 def get_ext_fullname (self , ext_name ):
460482 if self .package is None :
461483 return ext_name
462484 else :
463485 return self .package + '.' + ext_name
464486
465487 def get_ext_filename (self , ext_name ):
488+ """Convert the name of an extension (eg. "foo.bar") into the name
489+ of the file from which it will be loaded (eg. "foo/bar.so", or
490+ "foo\b ar.pyd").
491+ """
492+
466493 from distutils import sysconfig
467494 ext_path = string .split (ext_name , '.' )
468495 # extensions in debug_mode are named 'module_d.pyd' under windows
0 commit comments