Commit 1659bb90 authored by Greg Ward's avatar Greg Ward

Changed to use 'spawn()', now that it exists.

Added 'verbose' and 'dry_run' parameters to constructor.
Changed 'compile()', 'link_*()' to default lists arguments to None
  rather than empty list.
Added implementations of the filename-mangling methods mandated by
  the CCompiler interface.
parent 3e528252
...@@ -17,7 +17,7 @@ the "typical" Unix-style command-line C compiler: ...@@ -17,7 +17,7 @@ the "typical" Unix-style command-line C compiler:
__rcsid__ = "$Id$" __rcsid__ = "$Id$"
import string import string, re
from types import * from types import *
from sysconfig import \ from sysconfig import \
CC, CCSHARED, CFLAGS, OPT, LDSHARED, LDFLAGS, RANLIB, AR, SO CC, CCSHARED, CFLAGS, OPT, LDSHARED, LDFLAGS, RANLIB, AR, SO
...@@ -42,25 +42,35 @@ from ccompiler import CCompiler ...@@ -42,25 +42,35 @@ from ccompiler import CCompiler
class UnixCCompiler (CCompiler): class UnixCCompiler (CCompiler):
# XXX any -I and -D options that we get from Makefile (via sysconfig) # XXX perhaps there should really be *three* kinds of include
# are preserved, but not treated specially: that is, they are not put # directories: those built in to the preprocessor, those from Python's
# in the self.include_dirs and self.macros, etc. lists that we inherit # Makefiles, and those supplied to {add,set}_include_dirs(). Currently
# from CCompiler. I'm not sure if this is right, wrong or indifferent, # we make no distinction between the latter two at this point; it's all
# but it should probably be a documented part of the CCompiler API: # up to the client class to select the include directories to use above
# ie. there are *three* kinds of include directories, those from the # and beyond the compiler's defaults. That is, both the Python include
# compiler, those from Python's Makefiles, and those supplied to # directories and any module- or package-specific include directories
# {add,set}_include_dirs() -- and 'set_include_dirs()' only overrides # are specified via {add,set}_include_dirs(), and there's no way to
# the last kind! I suspect the same applies to libraries and library # distinguish them. This might be a bug.
# directories -- anything else?
def __init__ (self,
def __init__ (self): verbose=0,
dry_run=0):
CCompiler.__init__ (self)
CCompiler.__init__ (self, verbose, dry_run)
self.preprocess_options = None self.preprocess_options = None
self.compile_options = None self.compile_options = None
# munge CC and OPT together in case there are flags stuck in CC # Munge CC and OPT together in case there are flags stuck in CC.
# Note that using these variables from sysconfig immediately makes
# this module specific to building Python extensions and
# inappropriate as a general-purpose C compiler front-end. So sue
# me. Note also that we use OPT rather than CFLAGS, because CFLAGS
# is the flags used to compile Python itself -- not only are there
# -I options in there, they are the *wrong* -I options. We'll
# leave selection of include directories up to the class using
# UnixCCompiler!
(self.cc, self.ccflags) = \ (self.cc, self.ccflags) = \
_split_command (CC + ' ' + OPT) _split_command (CC + ' ' + OPT)
self.ccflags_shared = string.split (CCSHARED) self.ccflags_shared = string.split (CCSHARED)
...@@ -71,8 +81,13 @@ class UnixCCompiler (CCompiler): ...@@ -71,8 +81,13 @@ class UnixCCompiler (CCompiler):
def compile (self, def compile (self,
sources, sources,
macros=[], macros=None,
includes=[]): includes=None):
if macros is None:
macros = []
if includes is None:
includes = []
if type (macros) is not ListType: if type (macros) is not ListType:
raise TypeError, \ raise TypeError, \
...@@ -92,7 +107,8 @@ class UnixCCompiler (CCompiler): ...@@ -92,7 +107,8 @@ class UnixCCompiler (CCompiler):
sources sources
# this will change to 'spawn' when I have it! # this will change to 'spawn' when I have it!
print string.join ([self.cc] + cc_args, ' ') #print string.join ([self.cc] + cc_args, ' ')
self.spawn ([self.cc] + cc_args)
# XXX punting on 'link_static_lib()' for now -- it might be better for # XXX punting on 'link_static_lib()' for now -- it might be better for
...@@ -114,17 +130,39 @@ class UnixCCompiler (CCompiler): ...@@ -114,17 +130,39 @@ class UnixCCompiler (CCompiler):
def link_shared_object (self, def link_shared_object (self,
objects, objects,
output_filename, output_filename,
libraries=[], libraries=None,
library_dirs=[]): library_dirs=None):
if libraries is None:
libraries = []
if library_dirs is None:
library_dirs = []
lib_opts = _gen_lib_options (self.libraries + libraries, lib_opts = _gen_lib_options (self.libraries + libraries,
self.library_dirs + library_dirs) self.library_dirs + library_dirs)
ld_args = self.ldflags_shared + lib_opts + \ ld_args = self.ldflags_shared + lib_opts + \
objects + ['-o', output_filename] objects + ['-o', output_filename]
print string.join ([self.ld_shared] + ld_args, ' ') #print string.join ([self.ld_shared] + ld_args, ' ')
self.spawn ([self.ld_shared] + ld_args)
def object_filenames (self, source_filenames):
outnames = []
for inname in source_filenames:
outnames.append (re.sub (r'\.(c|C|cc|cxx)$', '.o', inname))
return outnames
def shared_object_filename (self, source_filename):
return re.sub (r'\.(c|C|cc|cxx)$', SO)
def library_filename (self, libname):
return "lib%s.a" % libname
def shared_library_filename (self, libname):
return "lib%s.so" % libname
# class UnixCCompiler # class UnixCCompiler
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment