55
66__revision__ = "$Id$"
77
8- import sys
9- import os
10- import re
11-
12- from distutils .errors import (CompileError , LinkError , UnknownFileError ,
13- DistutilsPlatformError , DistutilsModuleError )
8+ import sys , os , re
9+ from distutils .errors import *
1410from distutils .spawn import spawn
1511from distutils .file_util import move_file
1612from distutils .dir_util import mkpath
17- from distutils .dep_util import newer_group
13+ from distutils .dep_util import newer_pairwise , newer_group
1814from distutils .util import split_quoted , execute
1915from distutils import log
2016
21- _sysconfig = __import__ ('sysconfig' )
22-
23- def customize_compiler (compiler ):
24- """Do any platform-specific customization of a CCompiler instance.
25-
26- Mainly needed on Unix, so we can plug in the information that
27- varies across Unices and is stored in Python's Makefile.
28- """
29- if compiler .compiler_type == "unix" :
30- (cc , cxx , opt , cflags , ccshared , ldshared , so_ext , ar , ar_flags ) = \
31- _sysconfig .get_config_vars ('CC' , 'CXX' , 'OPT' , 'CFLAGS' ,
32- 'CCSHARED' , 'LDSHARED' , 'SO' , 'AR' ,
33- 'ARFLAGS' )
34-
35- if 'CC' in os .environ :
36- cc = os .environ ['CC' ]
37- if 'CXX' in os .environ :
38- cxx = os .environ ['CXX' ]
39- if 'LDSHARED' in os .environ :
40- ldshared = os .environ ['LDSHARED' ]
41- if 'CPP' in os .environ :
42- cpp = os .environ ['CPP' ]
43- else :
44- cpp = cc + " -E" # not always
45- if 'LDFLAGS' in os .environ :
46- ldshared = ldshared + ' ' + os .environ ['LDFLAGS' ]
47- if 'CFLAGS' in os .environ :
48- cflags = opt + ' ' + os .environ ['CFLAGS' ]
49- ldshared = ldshared + ' ' + os .environ ['CFLAGS' ]
50- if 'CPPFLAGS' in os .environ :
51- cpp = cpp + ' ' + os .environ ['CPPFLAGS' ]
52- cflags = cflags + ' ' + os .environ ['CPPFLAGS' ]
53- ldshared = ldshared + ' ' + os .environ ['CPPFLAGS' ]
54- if 'AR' in os .environ :
55- ar = os .environ ['AR' ]
56- if 'ARFLAGS' in os .environ :
57- archiver = ar + ' ' + os .environ ['ARFLAGS' ]
58- else :
59- archiver = ar + ' ' + ar_flags
60-
61- cc_cmd = cc + ' ' + cflags
62- compiler .set_executables (
63- preprocessor = cpp ,
64- compiler = cc_cmd ,
65- compiler_so = cc_cmd + ' ' + ccshared ,
66- compiler_cxx = cxx ,
67- linker_so = ldshared ,
68- linker_exe = cc ,
69- archiver = archiver )
70-
71- compiler .shared_lib_extension = so_ext
72-
7317class CCompiler :
7418 """Abstract base class to define the interface that must be implemented
7519 by real compiler classes. Also has some utility methods used by
@@ -449,6 +393,22 @@ def _fix_compile_args(self, output_dir, macros, include_dirs):
449393
450394 return output_dir , macros , include_dirs
451395
396+ def _prep_compile (self , sources , output_dir , depends = None ):
397+ """Decide which souce files must be recompiled.
398+
399+ Determine the list of object files corresponding to 'sources',
400+ and figure out which ones really need to be recompiled.
401+ Return a list of all object files and a dictionary telling
402+ which source files can be skipped.
403+ """
404+ # Get the list of expected output (object) files
405+ objects = self .object_filenames (sources , output_dir = output_dir )
406+ assert len (objects ) == len (sources )
407+
408+ # Return an empty dict for the "which source files can be skipped"
409+ # return value to preserve API compatibility.
410+ return objects , {}
411+
452412 def _fix_object_args (self , objects , output_dir ):
453413 """Typecheck and fix up some arguments supplied to various methods.
454414 Specifically: ensure that 'objects' is a list; if output_dir is
@@ -650,15 +610,26 @@ def create_static_lib(self, objects, output_libname, output_dir=None,
650610 """
651611 pass
652612
613+
653614 # values for target_desc parameter in link()
654615 SHARED_OBJECT = "shared_object"
655616 SHARED_LIBRARY = "shared_library"
656617 EXECUTABLE = "executable"
657618
658- def link (self , target_desc , objects , output_filename , output_dir = None ,
659- libraries = None , library_dirs = None , runtime_library_dirs = None ,
660- export_symbols = None , debug = 0 , extra_preargs = None ,
661- extra_postargs = None , build_temp = None , target_lang = None ):
619+ def link (self ,
620+ target_desc ,
621+ objects ,
622+ output_filename ,
623+ output_dir = None ,
624+ libraries = None ,
625+ library_dirs = None ,
626+ runtime_library_dirs = None ,
627+ export_symbols = None ,
628+ debug = 0 ,
629+ extra_preargs = None ,
630+ extra_postargs = None ,
631+ build_temp = None ,
632+ target_lang = None ):
662633 """Link a bunch of stuff together to create an executable or
663634 shared library file.
664635
@@ -707,11 +678,19 @@ def link(self, target_desc, objects, output_filename, output_dir=None,
707678
708679 # Old 'link_*()' methods, rewritten to use the new 'link()' method.
709680
710- def link_shared_lib (self , objects , output_libname , output_dir = None ,
711- libraries = None , library_dirs = None ,
712- runtime_library_dirs = None , export_symbols = None ,
713- debug = 0 , extra_preargs = None , extra_postargs = None ,
714- build_temp = None , target_lang = None ):
681+ def link_shared_lib (self ,
682+ objects ,
683+ output_libname ,
684+ output_dir = None ,
685+ libraries = None ,
686+ library_dirs = None ,
687+ runtime_library_dirs = None ,
688+ export_symbols = None ,
689+ debug = 0 ,
690+ extra_preargs = None ,
691+ extra_postargs = None ,
692+ build_temp = None ,
693+ target_lang = None ):
715694 self .link (CCompiler .SHARED_LIBRARY , objects ,
716695 self .library_filename (output_libname , lib_type = 'shared' ),
717696 output_dir ,
@@ -720,22 +699,37 @@ def link_shared_lib(self, objects, output_libname, output_dir=None,
720699 extra_preargs , extra_postargs , build_temp , target_lang )
721700
722701
723- def link_shared_object (self , objects , output_filename , output_dir = None ,
724- libraries = None , library_dirs = None ,
725- runtime_library_dirs = None , export_symbols = None ,
726- debug = 0 , extra_preargs = None , extra_postargs = None ,
727- build_temp = None , target_lang = None ):
702+ def link_shared_object (self ,
703+ objects ,
704+ output_filename ,
705+ output_dir = None ,
706+ libraries = None ,
707+ library_dirs = None ,
708+ runtime_library_dirs = None ,
709+ export_symbols = None ,
710+ debug = 0 ,
711+ extra_preargs = None ,
712+ extra_postargs = None ,
713+ build_temp = None ,
714+ target_lang = None ):
728715 self .link (CCompiler .SHARED_OBJECT , objects ,
729716 output_filename , output_dir ,
730717 libraries , library_dirs , runtime_library_dirs ,
731718 export_symbols , debug ,
732719 extra_preargs , extra_postargs , build_temp , target_lang )
733720
734721
735- def link_executable (self , objects , output_progname , output_dir = None ,
736- libraries = None , library_dirs = None ,
737- runtime_library_dirs = None , debug = 0 , extra_preargs = None ,
738- extra_postargs = None , target_lang = None ):
722+ def link_executable (self ,
723+ objects ,
724+ output_progname ,
725+ output_dir = None ,
726+ libraries = None ,
727+ library_dirs = None ,
728+ runtime_library_dirs = None ,
729+ debug = 0 ,
730+ extra_preargs = None ,
731+ extra_postargs = None ,
732+ target_lang = None ):
739733 self .link (CCompiler .EXECUTABLE , objects ,
740734 self .executable_filename (output_progname ), output_dir ,
741735 libraries , library_dirs , runtime_library_dirs , None ,
@@ -917,7 +911,7 @@ def spawn(self, cmd):
917911 def move_file (self , src , dst ):
918912 return move_file (src , dst , dry_run = self .dry_run )
919913
920- def mkpath (self , name , mode = 0o777 ):
914+ def mkpath (self , name , mode = 0o777 ):
921915 mkpath (name , mode , dry_run = self .dry_run )
922916
923917
@@ -1085,14 +1079,12 @@ def gen_preprocess_options(macros, include_dirs):
10851079 return pp_opts
10861080
10871081
1088- def gen_lib_options (compiler , library_dirs , runtime_library_dirs , libraries ):
1082+ def gen_lib_options (compiler , library_dirs , runtime_library_dirs , libraries ):
10891083 """Generate linker options for searching library directories and
1090- linking with specific libraries.
1091-
1092- 'libraries' and 'library_dirs' are, respectively, lists of library names
1093- (not filenames!) and search directories. Returns a list of command-line
1094- options suitable for use with some compiler (depending on the two format
1095- strings passed in).
1084+ linking with specific libraries. 'libraries' and 'library_dirs' are,
1085+ respectively, lists of library names (not filenames!) and search
1086+ directories. Returns a list of command-line options suitable for use
1087+ with some compiler (depending on the two format strings passed in).
10961088 """
10971089 lib_opts = []
10981090
@@ -1102,7 +1094,7 @@ def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):
11021094 for dir in runtime_library_dirs :
11031095 opt = compiler .runtime_library_dir_option (dir )
11041096 if isinstance (opt , list ):
1105- lib_opts . extend ( opt )
1097+ lib_opts = lib_opts + opt
11061098 else :
11071099 lib_opts .append (opt )
11081100
@@ -1113,14 +1105,14 @@ def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):
11131105 # pretty nasty way to arrange your C code.
11141106
11151107 for lib in libraries :
1116- lib_dir , lib_name = os .path .split (lib )
1117- if lib_dir != '' :
1108+ ( lib_dir , lib_name ) = os .path .split (lib )
1109+ if lib_dir :
11181110 lib_file = compiler .find_library_file ([lib_dir ], lib_name )
1119- if lib_file is not None :
1111+ if lib_file :
11201112 lib_opts .append (lib_file )
11211113 else :
11221114 compiler .warn ("no library file corresponding to "
11231115 "'%s' found (skipping)" % lib )
11241116 else :
1125- lib_opts .append (compiler .library_option (lib ))
1117+ lib_opts .append (compiler .library_option (lib ))
11261118 return lib_opts
0 commit comments