Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 1 | """distutils.unixccompiler |
| 2 | |
| 3 | Contains the UnixCCompiler class, a subclass of CCompiler that handles |
| 4 | the "typical" Unix-style command-line C compiler: |
| 5 | * macros defined with -Dname[=value] |
| 6 | * macros undefined with -Uname |
| 7 | * include search directories specified with -Idir |
| 8 | * libraries specified with -lllib |
| 9 | * library search directories specified with -Ldir |
| 10 | * compile handled by 'cc' (or similar) executable with -c option: |
| 11 | compiles .c to .o |
| 12 | * link static library handled by 'ar' command (possibly with 'ranlib') |
| 13 | * link shared library handled by 'cc -shared' |
| 14 | """ |
| 15 | |
| 16 | # created 1999/07/05, Greg Ward |
| 17 | |
Greg Ward | 3ce77fd | 2000-03-02 01:49:45 +0000 | [diff] [blame] | 18 | __revision__ = "$Id$" |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 19 | |
Greg Ward | 8037cb1 | 1999-09-13 03:12:53 +0000 | [diff] [blame] | 20 | import string, re, os |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 21 | from types import * |
Greg Ward | 8037cb1 | 1999-09-13 03:12:53 +0000 | [diff] [blame] | 22 | from copy import copy |
Greg Ward | 1c79330 | 2000-04-14 00:48:15 +0000 | [diff] [blame] | 23 | from distutils import sysconfig |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 24 | from distutils.ccompiler import CCompiler, gen_preprocess_options, gen_lib_options |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 25 | |
| 26 | # XXX Things not currently handled: |
| 27 | # * optimization/debug/warning flags; we just use whatever's in Python's |
| 28 | # Makefile and live with it. Is this adequate? If not, we might |
| 29 | # have to have a bunch of subclasses GNUCCompiler, SGICCompiler, |
| 30 | # SunCCompiler, and I suspect down that road lies madness. |
| 31 | # * even if we don't know a warning flag from an optimization flag, |
| 32 | # we need some way for outsiders to feed preprocessor/compiler/linker |
| 33 | # flags in to us -- eg. a sysadmin might want to mandate certain flags |
| 34 | # via a site config file, or a user might want to set something for |
| 35 | # compiling this module distribution only via the setup.py command |
| 36 | # line, whatever. As long as these options come from something on the |
| 37 | # current system, they can be as system-dependent as they like, and we |
| 38 | # should just happily stuff them into the preprocessor/compiler/linker |
| 39 | # options and carry on. |
| 40 | |
| 41 | |
| 42 | class UnixCCompiler (CCompiler): |
| 43 | |
Greg Ward | 5e71744 | 1999-08-14 23:53:53 +0000 | [diff] [blame] | 44 | # XXX perhaps there should really be *three* kinds of include |
| 45 | # directories: those built in to the preprocessor, those from Python's |
| 46 | # Makefiles, and those supplied to {add,set}_include_dirs(). Currently |
| 47 | # we make no distinction between the latter two at this point; it's all |
| 48 | # up to the client class to select the include directories to use above |
| 49 | # and beyond the compiler's defaults. That is, both the Python include |
| 50 | # directories and any module- or package-specific include directories |
| 51 | # are specified via {add,set}_include_dirs(), and there's no way to |
| 52 | # distinguish them. This might be a bug. |
Greg Ward | 65f4a3b | 1999-08-29 18:23:32 +0000 | [diff] [blame] | 53 | |
Greg Ward | 0e3530b | 1999-09-29 12:22:50 +0000 | [diff] [blame] | 54 | compiler_type = 'unix' |
| 55 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 56 | # Needed for the filename generation methods provided by the |
| 57 | # base class, CCompiler. |
| 58 | src_extensions = [".c",".C",".cc",".cxx",".cpp"] |
| 59 | obj_extension = ".o" |
| 60 | static_lib_extension = ".a" |
Greg Ward | 1c79330 | 2000-04-14 00:48:15 +0000 | [diff] [blame] | 61 | shared_lib_extension = sysconfig.SO |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 62 | static_lib_format = shared_lib_format = "lib%s%s" |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 63 | |
| 64 | # Command to create a static library: seems to be pretty consistent |
| 65 | # across the major Unices. Might have to move down into the |
| 66 | # constructor if we need platform-specific guesswork. |
Greg Ward | 1c79330 | 2000-04-14 00:48:15 +0000 | [diff] [blame] | 67 | archiver = sysconfig.AR |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 68 | archiver_options = "-cr" |
Greg Ward | 1c79330 | 2000-04-14 00:48:15 +0000 | [diff] [blame] | 69 | ranlib = sysconfig.RANLIB |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 70 | |
| 71 | |
Greg Ward | 5e71744 | 1999-08-14 23:53:53 +0000 | [diff] [blame] | 72 | def __init__ (self, |
| 73 | verbose=0, |
Greg Ward | 4fecfce | 1999-10-03 20:45:33 +0000 | [diff] [blame] | 74 | dry_run=0, |
| 75 | force=0): |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 76 | |
Greg Ward | 4fecfce | 1999-10-03 20:45:33 +0000 | [diff] [blame] | 77 | CCompiler.__init__ (self, verbose, dry_run, force) |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 78 | |
| 79 | self.preprocess_options = None |
| 80 | self.compile_options = None |
| 81 | |
Greg Ward | 5e71744 | 1999-08-14 23:53:53 +0000 | [diff] [blame] | 82 | # Munge CC and OPT together in case there are flags stuck in CC. |
| 83 | # Note that using these variables from sysconfig immediately makes |
| 84 | # this module specific to building Python extensions and |
| 85 | # inappropriate as a general-purpose C compiler front-end. So sue |
| 86 | # me. Note also that we use OPT rather than CFLAGS, because CFLAGS |
| 87 | # is the flags used to compile Python itself -- not only are there |
| 88 | # -I options in there, they are the *wrong* -I options. We'll |
| 89 | # leave selection of include directories up to the class using |
| 90 | # UnixCCompiler! |
| 91 | |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 92 | (self.cc, self.ccflags) = \ |
Greg Ward | 1c79330 | 2000-04-14 00:48:15 +0000 | [diff] [blame] | 93 | _split_command (sysconfig.CC + ' ' + sysconfig.OPT) |
| 94 | self.ccflags_shared = string.split (sysconfig.CCSHARED) |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 95 | |
| 96 | (self.ld_shared, self.ldflags_shared) = \ |
Greg Ward | 1c79330 | 2000-04-14 00:48:15 +0000 | [diff] [blame] | 97 | _split_command (sysconfig.LDSHARED) |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 98 | |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 99 | self.ld_exec = self.cc |
| 100 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 101 | # __init__ () |
| 102 | |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 103 | |
| 104 | def compile (self, |
| 105 | sources, |
Greg Ward | 8037cb1 | 1999-09-13 03:12:53 +0000 | [diff] [blame] | 106 | output_dir=None, |
Greg Ward | 5e71744 | 1999-08-14 23:53:53 +0000 | [diff] [blame] | 107 | macros=None, |
Greg Ward | 04d7832 | 1999-12-12 16:57:47 +0000 | [diff] [blame] | 108 | include_dirs=None, |
Greg Ward | ba233fb | 2000-02-09 02:17:00 +0000 | [diff] [blame] | 109 | debug=0, |
Greg Ward | 0e3530b | 1999-09-29 12:22:50 +0000 | [diff] [blame] | 110 | extra_preargs=None, |
| 111 | extra_postargs=None): |
Greg Ward | 5e71744 | 1999-08-14 23:53:53 +0000 | [diff] [blame] | 112 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 113 | (output_dir, macros, include_dirs) = \ |
| 114 | self._fix_compile_args (output_dir, macros, include_dirs) |
| 115 | (objects, skip_sources) = self._prep_compile (sources, output_dir) |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 116 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 117 | # Figure out the options for the compiler command line. |
| 118 | pp_opts = gen_preprocess_options (macros, include_dirs) |
Greg Ward | ef6f515 | 2000-02-03 23:07:19 +0000 | [diff] [blame] | 119 | cc_args = ['-c'] + pp_opts + self.ccflags + self.ccflags_shared |
Greg Ward | ba233fb | 2000-02-09 02:17:00 +0000 | [diff] [blame] | 120 | if debug: |
| 121 | cc_args[:0] = ['-g'] |
Greg Ward | ef6f515 | 2000-02-03 23:07:19 +0000 | [diff] [blame] | 122 | if extra_preargs: |
| 123 | cc_args[:0] = extra_preargs |
| 124 | if extra_postargs is None: |
| 125 | extra_postargs = [] |
Greg Ward | 8037cb1 | 1999-09-13 03:12:53 +0000 | [diff] [blame] | 126 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 127 | # Compile all source files that weren't eliminated by |
| 128 | # '_prep_compile()'. |
| 129 | for i in range (len (sources)): |
| 130 | src = sources[i] ; obj = objects[i] |
| 131 | if skip_sources[src]: |
| 132 | self.announce ("skipping %s (%s up-to-date)" % (src, obj)) |
| 133 | else: |
| 134 | self.mkpath (os.path.dirname (obj)) |
| 135 | self.spawn ([self.cc] + cc_args + [src, '-o', obj] + extra_postargs) |
Greg Ward | 8037cb1 | 1999-09-13 03:12:53 +0000 | [diff] [blame] | 136 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 137 | # Return *all* object filenames, not just the ones we just built. |
| 138 | return objects |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 139 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 140 | # compile () |
| 141 | |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 142 | |
Greg Ward | 036c805 | 2000-03-10 01:48:32 +0000 | [diff] [blame] | 143 | def create_static_lib (self, |
| 144 | objects, |
| 145 | output_libname, |
| 146 | output_dir=None, |
| 147 | debug=0): |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 148 | |
Greg Ward | e21dabe | 2000-03-26 21:40:19 +0000 | [diff] [blame] | 149 | (objects, output_dir) = self._fix_object_args (objects, output_dir) |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 150 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 151 | output_filename = \ |
| 152 | self.library_filename (output_libname, output_dir=output_dir) |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 153 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 154 | if self._need_link (objects, output_filename): |
Greg Ward | f114657 | 2000-03-01 14:43:49 +0000 | [diff] [blame] | 155 | self.mkpath (os.path.dirname (output_filename)) |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 156 | self.spawn ([self.archiver, |
| 157 | self.archiver_options, |
| 158 | output_filename] + |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 159 | objects + self.objects) |
Greg Ward | 1c79330 | 2000-04-14 00:48:15 +0000 | [diff] [blame] | 160 | |
Greg Ward | 8eef583 | 2000-04-14 13:53:34 +0000 | [diff] [blame] | 161 | # Not many Unices required ranlib anymore -- SunOS 4.x is, I |
| 162 | # think the only major Unix that does. Maybe we need some |
| 163 | # platform intelligence here to skip ranlib if it's not |
| 164 | # needed -- or maybe Python's configure script took care of |
| 165 | # it for us, hence the check for leading colon. |
| 166 | if self.ranlib[0] != ':': |
| 167 | self.spawn ([self.ranlib, output_filename]) |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 168 | else: |
| 169 | self.announce ("skipping %s (up-to-date)" % output_filename) |
| 170 | |
Greg Ward | 036c805 | 2000-03-10 01:48:32 +0000 | [diff] [blame] | 171 | # create_static_lib () |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 172 | |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 173 | |
| 174 | def link_shared_lib (self, |
| 175 | objects, |
| 176 | output_libname, |
Greg Ward | 8037cb1 | 1999-09-13 03:12:53 +0000 | [diff] [blame] | 177 | output_dir=None, |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 178 | libraries=None, |
Greg Ward | 65f4a3b | 1999-08-29 18:23:32 +0000 | [diff] [blame] | 179 | library_dirs=None, |
Greg Ward | e21dabe | 2000-03-26 21:40:19 +0000 | [diff] [blame] | 180 | runtime_library_dirs=None, |
Greg Ward | ba233fb | 2000-02-09 02:17:00 +0000 | [diff] [blame] | 181 | debug=0, |
Greg Ward | 0e3530b | 1999-09-29 12:22:50 +0000 | [diff] [blame] | 182 | extra_preargs=None, |
| 183 | extra_postargs=None): |
Greg Ward | 8037cb1 | 1999-09-13 03:12:53 +0000 | [diff] [blame] | 184 | self.link_shared_object ( |
| 185 | objects, |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 186 | self.shared_library_filename (output_libname), |
Greg Ward | 8037cb1 | 1999-09-13 03:12:53 +0000 | [diff] [blame] | 187 | output_dir, |
| 188 | libraries, |
| 189 | library_dirs, |
Greg Ward | e21dabe | 2000-03-26 21:40:19 +0000 | [diff] [blame] | 190 | runtime_library_dirs, |
Greg Ward | ba233fb | 2000-02-09 02:17:00 +0000 | [diff] [blame] | 191 | debug, |
Greg Ward | 0e3530b | 1999-09-29 12:22:50 +0000 | [diff] [blame] | 192 | extra_preargs, |
| 193 | extra_postargs) |
Greg Ward | 8037cb1 | 1999-09-13 03:12:53 +0000 | [diff] [blame] | 194 | |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 195 | |
| 196 | def link_shared_object (self, |
| 197 | objects, |
| 198 | output_filename, |
Greg Ward | 8037cb1 | 1999-09-13 03:12:53 +0000 | [diff] [blame] | 199 | output_dir=None, |
Greg Ward | 5e71744 | 1999-08-14 23:53:53 +0000 | [diff] [blame] | 200 | libraries=None, |
Greg Ward | 65f4a3b | 1999-08-29 18:23:32 +0000 | [diff] [blame] | 201 | library_dirs=None, |
Greg Ward | e21dabe | 2000-03-26 21:40:19 +0000 | [diff] [blame] | 202 | runtime_library_dirs=None, |
Greg Ward | ba233fb | 2000-02-09 02:17:00 +0000 | [diff] [blame] | 203 | debug=0, |
Greg Ward | 0e3530b | 1999-09-29 12:22:50 +0000 | [diff] [blame] | 204 | extra_preargs=None, |
| 205 | extra_postargs=None): |
Greg Ward | 5e71744 | 1999-08-14 23:53:53 +0000 | [diff] [blame] | 206 | |
Greg Ward | e21dabe | 2000-03-26 21:40:19 +0000 | [diff] [blame] | 207 | (objects, output_dir) = self._fix_object_args (objects, output_dir) |
| 208 | (libraries, library_dirs, runtime_library_dirs) = \ |
| 209 | self._fix_lib_args (libraries, library_dirs, runtime_library_dirs) |
Greg Ward | 04d7832 | 1999-12-12 16:57:47 +0000 | [diff] [blame] | 210 | |
Greg Ward | d03f88a | 2000-03-18 15:19:51 +0000 | [diff] [blame] | 211 | lib_opts = gen_lib_options (self, |
Greg Ward | e21dabe | 2000-03-26 21:40:19 +0000 | [diff] [blame] | 212 | library_dirs, runtime_library_dirs, |
Greg Ward | d03f88a | 2000-03-18 15:19:51 +0000 | [diff] [blame] | 213 | libraries) |
Greg Ward | 10ca82b | 2000-02-10 02:51:32 +0000 | [diff] [blame] | 214 | if type (output_dir) not in (StringType, NoneType): |
| 215 | raise TypeError, "'output_dir' must be a string or None" |
Greg Ward | 8037cb1 | 1999-09-13 03:12:53 +0000 | [diff] [blame] | 216 | if output_dir is not None: |
| 217 | output_filename = os.path.join (output_dir, output_filename) |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 218 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 219 | if self._need_link (objects, output_filename): |
| 220 | ld_args = (self.ldflags_shared + objects + self.objects + |
| 221 | lib_opts + ['-o', output_filename]) |
Greg Ward | ba233fb | 2000-02-09 02:17:00 +0000 | [diff] [blame] | 222 | if debug: |
| 223 | ld_args[:0] = ['-g'] |
Greg Ward | 0e3530b | 1999-09-29 12:22:50 +0000 | [diff] [blame] | 224 | if extra_preargs: |
| 225 | ld_args[:0] = extra_preargs |
| 226 | if extra_postargs: |
| 227 | ld_args.extend (extra_postargs) |
Greg Ward | f114657 | 2000-03-01 14:43:49 +0000 | [diff] [blame] | 228 | self.mkpath (os.path.dirname (output_filename)) |
Greg Ward | 8037cb1 | 1999-09-13 03:12:53 +0000 | [diff] [blame] | 229 | self.spawn ([self.ld_shared] + ld_args) |
| 230 | else: |
| 231 | self.announce ("skipping %s (up-to-date)" % output_filename) |
Greg Ward | 5e71744 | 1999-08-14 23:53:53 +0000 | [diff] [blame] | 232 | |
Greg Ward | 4fecfce | 1999-10-03 20:45:33 +0000 | [diff] [blame] | 233 | # link_shared_object () |
| 234 | |
| 235 | |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 236 | def link_executable (self, |
| 237 | objects, |
| 238 | output_progname, |
| 239 | output_dir=None, |
| 240 | libraries=None, |
| 241 | library_dirs=None, |
Greg Ward | e21dabe | 2000-03-26 21:40:19 +0000 | [diff] [blame] | 242 | runtime_library_dirs=None, |
Greg Ward | ba233fb | 2000-02-09 02:17:00 +0000 | [diff] [blame] | 243 | debug=0, |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 244 | extra_preargs=None, |
| 245 | extra_postargs=None): |
| 246 | |
Greg Ward | e21dabe | 2000-03-26 21:40:19 +0000 | [diff] [blame] | 247 | (objects, output_dir) = self._fix_object_args (objects, output_dir) |
| 248 | (libraries, library_dirs, runtime_library_dirs) = \ |
| 249 | self._fix_lib_args (libraries, library_dirs, runtime_library_dirs) |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 250 | |
Greg Ward | d03f88a | 2000-03-18 15:19:51 +0000 | [diff] [blame] | 251 | lib_opts = gen_lib_options (self, |
Greg Ward | e21dabe | 2000-03-26 21:40:19 +0000 | [diff] [blame] | 252 | library_dirs, runtime_library_dirs, |
Greg Ward | d03f88a | 2000-03-18 15:19:51 +0000 | [diff] [blame] | 253 | libraries) |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 254 | output_filename = output_progname # Unix-ism! |
| 255 | if output_dir is not None: |
| 256 | output_filename = os.path.join (output_dir, output_filename) |
| 257 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 258 | if self._need_link (objects, output_filename): |
| 259 | ld_args = objects + self.objects + lib_opts + ['-o', output_filename] |
Greg Ward | ba233fb | 2000-02-09 02:17:00 +0000 | [diff] [blame] | 260 | if debug: |
| 261 | ld_args[:0] = ['-g'] |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 262 | if extra_preargs: |
| 263 | ld_args[:0] = extra_preargs |
| 264 | if extra_postargs: |
| 265 | ld_args.extend (extra_postargs) |
Greg Ward | f114657 | 2000-03-01 14:43:49 +0000 | [diff] [blame] | 266 | self.mkpath (os.path.dirname (output_filename)) |
Greg Ward | c9f3187 | 2000-01-09 22:47:53 +0000 | [diff] [blame] | 267 | self.spawn ([self.ld_exec] + ld_args) |
| 268 | else: |
| 269 | self.announce ("skipping %s (up-to-date)" % output_filename) |
| 270 | |
| 271 | # link_executable () |
| 272 | |
| 273 | |
Greg Ward | 32c4a8a | 2000-03-06 03:40:29 +0000 | [diff] [blame] | 274 | # -- Miscellaneous methods ----------------------------------------- |
| 275 | # These are all used by the 'gen_lib_options() function, in |
| 276 | # ccompiler.py. |
| 277 | |
Greg Ward | 4fecfce | 1999-10-03 20:45:33 +0000 | [diff] [blame] | 278 | def library_dir_option (self, dir): |
| 279 | return "-L" + dir |
| 280 | |
Greg Ward | d03f88a | 2000-03-18 15:19:51 +0000 | [diff] [blame] | 281 | def runtime_library_dir_option (self, dir): |
| 282 | return "-R" + dir |
| 283 | |
Greg Ward | 4fecfce | 1999-10-03 20:45:33 +0000 | [diff] [blame] | 284 | def library_option (self, lib): |
| 285 | return "-l" + lib |
| 286 | |
| 287 | |
| 288 | def find_library_file (self, dirs, lib): |
| 289 | |
| 290 | for dir in dirs: |
| 291 | shared = os.path.join (dir, self.shared_library_filename (lib)) |
| 292 | static = os.path.join (dir, self.library_filename (lib)) |
| 293 | |
| 294 | # We're second-guessing the linker here, with not much hard |
| 295 | # data to go on: GCC seems to prefer the shared library, so I'm |
| 296 | # assuming that *all* Unix C compilers do. And of course I'm |
| 297 | # ignoring even GCC's "-static" option. So sue me. |
| 298 | if os.path.exists (shared): |
| 299 | return shared |
| 300 | elif os.path.exists (static): |
| 301 | return static |
| 302 | |
| 303 | else: |
| 304 | # Oops, didn't find it in *any* of 'dirs' |
| 305 | return None |
| 306 | |
| 307 | # find_library_file () |
Greg Ward | 65f4a3b | 1999-08-29 18:23:32 +0000 | [diff] [blame] | 308 | |
Greg Ward | 170bdc0 | 1999-07-10 02:04:22 +0000 | [diff] [blame] | 309 | # class UnixCCompiler |
| 310 | |
| 311 | |
| 312 | def _split_command (cmd): |
| 313 | """Split a command string up into the progam to run (a string) and |
| 314 | the list of arguments; return them as (cmd, arglist).""" |
| 315 | args = string.split (cmd) |
| 316 | return (args[0], args[1:]) |