[Distutils] Compiler options

M.-A. Lemburg mal@lemburg.com
Mon Apr 2 12:15:01 2001


Konrad Hinsen wrote:
> 
> Judging from a quick glance at the relevant modules, there seems to be
> no provision in Distutils to change the compiler options (specifically
> optimization and debug options) from the values used during Python
> installation. Is this true and if so, is this a temporary
> implementation restriction or an intentional design decision?

Funny, I stumbled into the same problem just a few days ago when
I wrapped the 2.0.1 release of mxODBC. I found that the MS VC
default options did not turn on optimization and that some
important flags were missing.

After looking at the distutils code, I found that there is no
way to subclass the compiler class *and* hvae distutils use it,
so I eventually ended up with a hack:

#
# mx MSVC Compiler extension
#
# We want some extra options for the MSVCCompiler, so we add them
# here. This is an awful hack, but there seems to be no other way to
# subclass a standard distutils C compiler class...

from distutils.msvccompiler import MSVCCompiler

# remember old __init__
old_MSVCCompiler__init__ = MSVCCompiler.__init__

def mx_msvccompiler__init__(self, *args, **kws):

    apply(old_MSVCCompiler__init__, (self,) + args, kws)
    self.compile_options.extend(['/O2','/Gf','/GB','/GD'])

# "install" new __init__
MSVCCompiler.__init__ = mx_msvccompiler__init__

I think it would be worthwhile thinking about a more generic
way to implement such compiler specific option changes...

-- 
Marc-Andre Lemburg
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Pages:                           http://www.lemburg.com/python/