[Numpy-discussion] How to guess the compiler type from distuils?

Francesc Alted faltet@pytables....
Fri Feb 6 10:27:45 CST 2009


A Friday 06 February 2009, Francesc Alted escrigué:
> Hi,
>
> We would like to use the numpy.distutils machinery for numexpr and
> I'd like to add different compiler flags depending on the compiler
> used. Anbody knows a simple way to do this with numpy.distutils (ore
> plain distutils)?

I've figured out how to do it.  For the records, you simply have to 
import this:

from numpy.distutils.command.build_ext import build_ext as 
numpy_build_ext

and then define the next class:

class build_ext(numpy_build_ext):
    def build_extension(self, ext):
        # at this point we know what the C compiler is.
        c = self.compiler
        old_compile_options = None
        # For MS Visual C, we use /O1 instead of the default /Ox,
        # as /Ox takes a long time (~5 mins) to compile.
        # The speed of the code isn't noticeably different.
        if c.compiler_type == 'msvc':
            if not c.initialized:
                c.initialize()
            old_compile_options = c.compile_options[:]
            if '/Ox' in c.compile_options:
                c.compile_options.remove('/Ox')
            c.compile_options.append('/O1')
            ext.extra_compile_args = []
        numpy_build_ext.build_extension(self, ext)
        if old_compile_options is not None:
            self.compiler.compile_options = old_compile_options

where you can taylor compiler options at your will.

Cheers,

-- 
Francesc Alted


More information about the Numpy-discussion mailing list