diff options
author | Greg Ward <gward@python.net> | 1999-10-03 20:45:33 (GMT) |
---|---|---|
committer | Greg Ward <gward@python.net> | 1999-10-03 20:45:33 (GMT) |
commit | 4fecfce4d09eca422af8ad60363bc83005b7c032 (patch) | |
tree | 4032fc11ebdbdef51dae433bab6b4dfe2a926a18 /Lib | |
parent | 3febd6068234f817d22cc778ff8dce2e6bd49da5 (diff) | |
download | cpython-4fecfce4d09eca422af8ad60363bc83005b7c032.zip cpython-4fecfce4d09eca422af8ad60363bc83005b7c032.tar.gz cpython-4fecfce4d09eca422af8ad60363bc83005b7c032.tar.bz2 |
Fixed order of link options: object files now precede library stuff.
Catch up with changes in 'gen_lib_options()':
- change how we call it
- added methods 'library_dir_option()', 'library_option()', and
'find_library_file()' that it calls
Added 'force' flag and changed compile/link methods to respect it.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/distutils/unixccompiler.py | 79 |
1 files changed, 58 insertions, 21 deletions
diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py index f3d9591..8f68919 100644 --- a/Lib/distutils/unixccompiler.py +++ b/Lib/distutils/unixccompiler.py @@ -62,9 +62,10 @@ class UnixCCompiler (CCompiler): def __init__ (self, verbose=0, - dry_run=0): + dry_run=0, + force=0): - CCompiler.__init__ (self, verbose, dry_run) + CCompiler.__init__ (self, verbose, dry_run, force) self.preprocess_options = None self.compile_options = None @@ -121,9 +122,10 @@ class UnixCCompiler (CCompiler): # source and object file, no deep dependency checking involving # header files. Hmmm.) objects = self.object_filenames (sources, output_dir) - skipped = newer_pairwise (sources, objects) - for skipped_pair in skipped: - self.announce ("skipping %s (%s up-to-date)" % skipped_pair) + if not self.force: + skipped = newer_pairwise (sources, objects) + for skipped_pair in skipped: + self.announce ("skipping %s (%s up-to-date)" % skipped_pair) # If anything left to compile, compile it if sources: @@ -202,9 +204,9 @@ class UnixCCompiler (CCompiler): if library_dirs is None: library_dirs = [] - lib_opts = gen_lib_options (self.library_dirs + library_dirs, - self.libraries + libraries, - "-L%s", "-l%s") + lib_opts = gen_lib_options (self, + self.library_dirs + library_dirs, + self.libraries + libraries) if output_dir is not None: output_filename = os.path.join (output_dir, output_filename) @@ -213,17 +215,18 @@ class UnixCCompiler (CCompiler): # doesn't look at any of the libraries we might be linking with. # Note that we have to dance around errors comparing timestamps if # we're in dry-run mode (yuck). - try: - newer = newer_group (objects, output_filename) - except OSError: - if self.dry_run: - newer = 1 - else: - raise - - if newer: - ld_args = self.ldflags_shared + lib_opts + \ - objects + ['-o', output_filename] + if not self.force: + try: + newer = newer_group (objects, output_filename) + except OSError: + if self.dry_run: + newer = 1 + else: + raise + + if self.force or newer: + ld_args = self.ldflags_shared + objects + \ + lib_opts + ['-o', output_filename] if extra_preargs: ld_args[:0] = extra_preargs if extra_postargs: @@ -232,6 +235,10 @@ class UnixCCompiler (CCompiler): else: self.announce ("skipping %s (up-to-date)" % output_filename) + # link_shared_object () + + + # -- Filename-mangling (etc.) methods ------------------------------ def object_filenames (self, source_filenames, output_dir=None): outnames = [] @@ -250,11 +257,41 @@ class UnixCCompiler (CCompiler): outname = os.path.join (output_dir, outname) return outname + def library_filename (self, libname): - return "lib%s%s" % (libname, self._static_lib_ext ) + return "lib%s%s" % (libname, self._static_lib_ext) def shared_library_filename (self, libname): - return "lib%s%s" % (libname, self._shared_lib_ext ) + return "lib%s%s" % (libname, self._shared_lib_ext) + + + def library_dir_option (self, dir): + return "-L" + dir + + def library_option (self, lib): + return "-l" + lib + + + def find_library_file (self, dirs, lib): + + for dir in dirs: + shared = os.path.join (dir, self.shared_library_filename (lib)) + static = os.path.join (dir, self.library_filename (lib)) + + # We're second-guessing the linker here, with not much hard + # data to go on: GCC seems to prefer the shared library, so I'm + # assuming that *all* Unix C compilers do. And of course I'm + # ignoring even GCC's "-static" option. So sue me. + if os.path.exists (shared): + return shared + elif os.path.exists (static): + return static + + else: + # Oops, didn't find it in *any* of 'dirs' + return None + + # find_library_file () # class UnixCCompiler |