Пример #1
0
def gumath_ext():
    include_dirs = ["libgumath", "ndtypes/python/ndtypes", "xnd/python/xnd"] + INCLUDES
    library_dirs = ["libgumath", "ndtypes/libndtypes", "xnd/libxnd"] + LIBS
    depends = []
    sources = ["python/gumath/_gumath.c"]

    if sys.platform == "win32":
        libraries = ["libndtypes-0.2.0dev3.dll", "libxnd-0.2.0dev3.dll", "libgumath-0.2.0dev3.dll"]
        extra_compile_args = ["/DNDT_IMPORT", "/DXND_IMPORT", "/DGM_IMPORT"]
        extra_link_args = []
        runtime_library_dirs = []

        if BUILD_ALL:
           from distutils.msvc9compiler import MSVCCompiler
           MSVCCompiler().initialize()
           os.chdir("vcbuild")
           os.environ['LIBNDTYPESINCLUDE'] = os.path.normpath("../ndtypes/libndtypes")
           os.environ['LIBNDTYPESDIR'] = os.path.normpath("../ndtypes/libndtypes")
           os.environ['LIBXNDINCLUDE'] = os.path.normpath("../xnd/libxnd")
           os.environ['LIBXNDDIR'] = os.path.normpath("../xnd/libxnd")
           if ARCH == "64bit":
                 os.system("vcbuild64.bat")
           else:
                 os.system("vcbuild32.bat")
           os.chdir("..")

    else:
        extra_compile_args = ["-Wextra", "-Wno-missing-field-initializers", "-std=c11"]
        if sys.platform == "darwin":
            libraries = ["ndtypes", "xnd", "gumath"]
            extra_link_args = ["-Wl,-rpath,@loader_path"]
            runtime_library_dirs = []
        else:
            libraries = [":%s" % LIBNDTYPES, ":%s" % LIBXND, ":%s" % LIBSHARED]
            extra_link_args = []
            runtime_library_dirs = ["$ORIGIN"]

        if BUILD_ALL:
           cflags = '"-I%s -I%s"' % tuple(CONFIGURE_INCLUDES)
           ldflags = '"-L%s -L%s"' % tuple(CONFIGURE_LIBS)
           os.system("./configure CFLAGS=%s LDFLAGS=%s && make" % (cflags, ldflags))

    return Extension (
      "gumath._gumath",
      include_dirs = include_dirs,
      library_dirs = library_dirs,
      depends = depends,
      sources = sources,
      libraries = libraries,
      extra_compile_args = extra_compile_args,
      extra_link_args = extra_link_args,
      runtime_library_dirs = runtime_library_dirs
    )
Пример #2
0
 def test_remove_entire_manifest(self):
     from distutils.msvc9compiler import MSVCCompiler
     tempdir = self.mkdtemp()
     manifest = os.path.join(tempdir, 'manifest')
     f = open(manifest, 'w')
     try:
         f.write(_MANIFEST_WITH_ONLY_MSVC_REFERENCE)
     finally:
         f.close()
     compiler = MSVCCompiler()
     got = compiler._remove_visual_c_ref(manifest)
     self.assertIsNone(got)
Пример #3
0
    def compile_wrapper_python26(self):
        # For Python-2.6 we build with Visual Studio; trying to get a
        # MingW32-built .exe to load the extensions we bundle for Python-2.6
        # seems very difficult. We hope that our version of Visual Studio
        # was close enough to the version that Python is built with so
        # that if Python runs, we run.
        #
        # We use some distutils internals to locate the Visual Studio
        # command line tools
        #
        from distutils.msvc9compiler import MSVCCompiler
        compiler = MSVCCompiler()
        # This looks for the tools and then adds them to os.environ['Path']
        compiler.initialize()

        python_topdir = os.path.dirname(os.path.dirname(shutil.__file__))
        python_include = os.path.join(python_topdir, "include")
        python_lib = os.path.join(python_topdir, "libs")

        wrapper_c = os.path.join(self.topdir, "tools", "build_msi",
                                 "wrapper.c")

        wrapper_rc = os.path.join(self.tempdir, "wrapper.rc")
        f = open(wrapper_rc, "w")
        f.write("""LANGUAGE 0, 0
100	 ICON	%s
""" % os.path.join(self.treedir, "Reinteract.ico"))
        f.close()

        # We can use distutils to do the basic compilation
        objects = compiler.compile([wrapper_c, wrapper_rc],
                                   output_dir=self.tempdir,
                                   include_dirs=[python_include])

        # But have to do the linking a bit more manually since distutils
        # doesn't know how to handle creating .exe files
        wrapper = os.path.join(self.tempdir, "Reinteract.exe")
        manifest = os.path.join(self.tempdir, "Reinteract.exe.manifest")
        extra_libs = [
            'user32.lib',  # For MessageBox
        ]
        check_call([
            compiler.linker, "/MANIFEST", "/MANIFESTFILE:" +
            manifest, "/LIBPATH:" + python_lib, "/OUT:" + wrapper
        ] + objects + extra_libs)

        # Embed the manifest into the executable
        check_call([
            'mt.exe', '-manifest', manifest,
            '-outputresource:' + wrapper + ';1'
        ])

        self.add_file(wrapper, 'bin', feature='core')
Пример #4
0
def ndtypes_ext():
    include_dirs = ["libndtypes"]
    library_dirs = ["libndtypes"]
    depends = ["libndtypes/ndtypes.h", "python/ndtypes/pyndtypes.h"]
    sources = ["python/ndtypes/_ndtypes.c"]

    if sys.platform == "win32":
        libraries = ["libndtypes-0.2.0dev3.dll"]
        extra_compile_args = ["/DNDT_IMPORT"]
        extra_link_args = []
        runtime_library_dirs = []

        if BUILD_ALL:
            from distutils.msvc9compiler import MSVCCompiler
            MSVCCompiler().initialize()
            os.chdir("vcbuild")
            if ARCH == "64bit":
                os.system("vcbuild64.bat")
            else:
                os.system("vcbuild32.bat")
            os.chdir("..")

    else:
        libraries = [":%s" % LIBSHARED]
        extra_compile_args = [
            "-Wextra", "-Wno-missing-field-initializers", "-std=c11"
        ]
        if sys.platform == "darwin":
            libraries = ["ndtypes"]
            extra_link_args = ["-Wl,-rpath,@loader_path"]
            runtime_library_dirs = []
        else:
            libraries = [":%s" % LIBSHARED]
            extra_link_args = []
            runtime_library_dirs = ["$ORIGIN"]

        if BUILD_ALL:
            make = "make -j%d" % int(PARALLEL) if PARALLEL else "make"
            if WITH_VALGRIND:
                os.system("./configure --with-valgrind && %s" % make)
            else:
                os.system("./configure && %s" % make)

    return Extension("ndtypes._ndtypes",
                     include_dirs=include_dirs,
                     library_dirs=library_dirs,
                     depends=depends,
                     sources=sources,
                     libraries=libraries,
                     extra_compile_args=extra_compile_args,
                     extra_link_args=extra_link_args,
                     runtime_library_dirs=runtime_library_dirs)
Пример #5
0
def xnd_ext():
    include_dirs = ["libxnd", "ndtypes/python/ndtypes"] + INCLUDES
    library_dirs = ["libxnd", "ndtypes/libndtypes"] + LIBS
    depends = ["libxnd/xnd.h", "python/xnd/util.h", "python/xnd/pyxnd.h"]
    sources = ["python/xnd/_xnd.c"]

    if sys.platform == "win32":
        libraries = ["libndtypes-0.2.0dev3.dll", "libxnd-0.2.0dev3.dll"]
        extra_compile_args = ["/DXND_IMPORT"]
        extra_link_args = []
        runtime_library_dirs = []

        if BUILD_ALL:
            from distutils.msvc9compiler import MSVCCompiler
            MSVCCompiler().initialize()
            os.chdir("vcbuild")
            os.environ['LIBNDTYPESINCLUDE'] = os.path.normpath(
                CONFIGURE_INCLUDES)
            os.environ['LIBNDTYPESDIR'] = os.path.normpath(CONFIGURE_LIBS)
            if ARCH == "64bit":
                os.system("vcbuild64.bat")
            else:
                os.system("vcbuild32.bat")
            os.chdir("..")

    else:
        extra_compile_args = [
            "-Wextra", "-Wno-missing-field-initializers", "-std=c11"
        ]
        if sys.platform == "darwin":
            libraries = ["ndtypes", "xnd"]
            extra_link_args = ["-Wl,-rpath,@loader_path"]
            runtime_library_dirs = []
        else:
            libraries = [":%s" % LIBNDTYPES, ":%s" % LIBSHARED]
            extra_link_args = []
            runtime_library_dirs = ["$ORIGIN"]

        if BUILD_ALL:
            os.system(
                "./configure --with-includes='%s' --with-libs='%s' && make" %
                (CONFIGURE_INCLUDES, CONFIGURE_LIBS))

    return Extension("xnd._xnd",
                     include_dirs=include_dirs,
                     library_dirs=library_dirs,
                     depends=depends,
                     sources=sources,
                     libraries=libraries,
                     extra_compile_args=extra_compile_args,
                     extra_link_args=extra_link_args,
                     runtime_library_dirs=runtime_library_dirs)
Пример #6
0
def ndtypes_ext():
    depends = ["python/gumath/util.h", "python/gumath/kernels.h"]
    sources = ["python/gumath/_gumath.c"]
    include_dirs = ["python/ndtypes", "python/xnd", "python/gumath"]
    library_dirs = ["python/ndtypes", "python/xnd", "python/gumath"]

    if sys.platform == "win32":
        libraries = ["libgumath-0.2.0dev3.dll", "libgumath-0.2.0dev3.dll"]
        extra_compile_args = ["/DIMPORT"]
        extra_link_args = []
        runtime_library_dirs = []

        if BUILD_ALL:
            from distutils.msvc9compiler import MSVCCompiler
            MSVCCompiler().initialize()
            os.chdir("vcbuild")
            os.environ['LIBS'] = os.path.normpath(LIBS)
            if ARCH == "64bit":
                os.system("vcbuild64.bat")
            else:
                os.system("vcbuild32.bat")
            os.chdir("..")

    else:
        extra_compile_args = [
            "-Wextra", "-Wno-missing-field-initializers", "-std=c11"
        ]
        if sys.platform == "darwin":
            libraries = ["ndtypes", "xnd"]
            extra_link_args = ["-Wl,-rpath,@loader_path"]
            runtime_library_dirs = []
        else:
            libraries = [":%s" % LIBNDTYPES, ":%s" % LIBXND, ":%s" % LIBGUMATH]
            extra_link_args = []
            runtime_library_dirs = ["$ORIGIN"]

        if BUILD_ALL:
            os.system(
                "./configure CFLAGS=\"-I$PWD/python/ndtypes -I$PWD/python/xnd\" && make"
            )

    return Extension("gumath._gumath",
                     include_dirs=include_dirs,
                     library_dirs=library_dirs,
                     depends=depends,
                     sources=sources,
                     libraries=libraries,
                     extra_compile_args=extra_compile_args,
                     extra_link_args=extra_link_args,
                     runtime_library_dirs=runtime_library_dirs)
Пример #7
0
 def test_remove_visual_c_ref(self):
     from distutils.msvc9compiler import MSVCCompiler
     tempdir = self.mkdtemp()
     manifest = os.path.join(tempdir, 'manifest')
     f = open(manifest, 'w')
     try:
         f.write(_MANIFEST_WITH_MULTIPLE_REFERENCES)
     finally:
         f.close()
     compiler = MSVCCompiler()
     compiler._remove_visual_c_ref(manifest)
     f = open(manifest)
     try:
         content = '\n'.join([line.rstrip() for line in f.readlines()])
     finally:
         f.close()
     self.assertEqual(content, _CLEANED_MANIFEST)
Пример #8
0
    def test_remove_visual_c_ref(self):
        from distutils.msvc9compiler import MSVCCompiler
        tempdir = self.mkdtemp()
        manifest = os.path.join(tempdir, 'manifest')
        f = open(manifest, 'w')
        f.write(_MANIFEST)
        f.close()

        compiler = MSVCCompiler()
        compiler._remove_visual_c_ref(manifest)

        # see what we got
        f = open(manifest)
        # removing trailing spaces
        content = '\n'.join([line.rstrip() for line in f.readlines()])
        f.close()

        # makes sure the manifest was properly cleaned
        self.assertEquals(content, _CLEANED_MANIFEST)
Пример #9
0
import glob
import os
import re
import sys

if hasattr(sys, 'pypy_version_info'):
    ext_modules = []
else:
    extra_objects = []
    if sys.platform == 'win32':
        # This is a hack because msvc9compiler doesn't support asm files
        # http://bugs.python.org/issue7546

        # Initialize compiler
        from distutils.msvc9compiler import MSVCCompiler
        cc = MSVCCompiler()
        cc.initialize()
        del cc

        if '32 bit' in sys.version:
            extra_objects = ['src/switch_x86_msvc.obj']
            os.system(
                'ml /nologo /c /Fo src\switch_x86_msvc.obj src\switch_x86_msvc.asm'
            )
        else:
            extra_objects = ['src/switch_x64_msvc.obj']
            os.system(
                'ml64 /nologo /c /Fo src\switch_x64_msvc.obj src\switch_x64_msvc.asm'
            )

    ext_modules = [
Пример #10
0
def gumath_extensions():
    add_include_dirs = [
        ".", "libgumath", "ndtypes/python/ndtypes", "xnd/python/xnd"
    ] + INCLUDES
    add_library_dirs = ["libgumath", "ndtypes/libndtypes", "xnd/libxnd"] + LIBS
    add_depends = []
    config_vars = {}

    if sys.platform == "win32":
        add_libraries = [
            "libndtypes-0.2.0dev3.dll", "libxnd-0.2.0dev3.dll",
            "libgumath-0.2.0dev3.dll"
        ]
        add_extra_compile_args = [
            "/DNDT_IMPORT", "/DXND_IMPORT", "/DGM_IMPORT"
        ]
        add_extra_link_args = []
        add_runtime_library_dirs = []

        if BUILD_ALL:
            from distutils.msvc9compiler import MSVCCompiler
            MSVCCompiler().initialize()
            os.chdir("vcbuild")
            os.environ['LIBNDTYPESINCLUDE'] = os.path.normpath(
                CONFIGURE_INCLUDES[0])
            os.environ['LIBNDTYPESDIR'] = os.path.normpath(CONFIGURE_LIBS[0])
            os.environ['LIBXNDINCLUDE'] = os.path.normpath(
                CONFIGURE_INCLUDES[1])
            os.environ['LIBXNDDIR'] = os.path.normpath(CONFIGURE_LIBS[1])
            if ARCH == "64bit":
                os.system("vcbuild64.bat")
            else:
                os.system("vcbuild32.bat")
            os.chdir("..")
    else:
        if BUILD_ALL:
            cflags = '"-I%s -I%s"' % tuple(CONFIGURE_INCLUDES)
            ldflags = '"-L%s -L%s"' % tuple(CONFIGURE_LIBS)
            make = "make -j%d" % int(PARALLEL) if PARALLEL else "make"
            os.system("./configure CFLAGS=%s LDFLAGS=%s && %s" %
                      (cflags, ldflags, make))

        config_vars = get_config_vars()

        add_extra_compile_args = [
            "-Wextra", "-Wno-missing-field-initializers", "-std=c11"
        ]
        if sys.platform == "darwin":
            add_libraries = ["ndtypes", "xnd", "gumath"]
            add_extra_link_args = ["-Wl,-rpath,@loader_path"]
            add_runtime_library_dirs = []
        else:
            add_libraries = [
                ":%s" % LIBNDTYPES,
                ":%s" % LIBXND,
                ":%s" % LIBSHARED
            ]
            add_extra_link_args = []
            add_runtime_library_dirs = ["$ORIGIN"]

        if config_vars["HAVE_CUDA"]:
            add_libraries += ["cudart"]

            for d in [
                    "/usr/cuda/lib", "/usr/cuda/lib64", "/usr/local/cuda/lib/",
                    "/usr/local/cuda/lib64"
            ]:
                if os.path.isdir(d):
                    add_library_dirs.append(d)

    def gumath_ext():
        sources = ["python/gumath/_gumath.c"]

        return Extension("gumath._gumath",
                         include_dirs=add_include_dirs,
                         library_dirs=add_library_dirs,
                         depends=add_depends,
                         sources=sources,
                         libraries=add_libraries,
                         extra_compile_args=add_extra_compile_args,
                         extra_link_args=add_extra_link_args,
                         runtime_library_dirs=add_runtime_library_dirs)

    def functions_ext():
        sources = ["python/gumath/functions.c"]

        return Extension("gumath.functions",
                         include_dirs=add_include_dirs,
                         library_dirs=add_library_dirs,
                         depends=add_depends,
                         sources=sources,
                         libraries=add_libraries,
                         extra_compile_args=add_extra_compile_args,
                         extra_link_args=add_extra_link_args,
                         runtime_library_dirs=add_runtime_library_dirs)

    def cuda_ext():
        sources = ["python/gumath/cuda.c"]

        return Extension("gumath.cuda",
                         include_dirs=add_include_dirs,
                         library_dirs=add_library_dirs,
                         depends=add_depends,
                         sources=sources,
                         libraries=add_libraries,
                         extra_compile_args=add_extra_compile_args,
                         extra_link_args=add_extra_link_args,
                         runtime_library_dirs=add_runtime_library_dirs)

    def examples_ext():
        sources = ["python/gumath/examples.c"]

        return Extension("gumath.examples",
                         include_dirs=add_include_dirs,
                         library_dirs=add_library_dirs,
                         depends=add_depends,
                         sources=sources,
                         libraries=add_libraries,
                         extra_compile_args=add_extra_compile_args,
                         extra_link_args=add_extra_link_args,
                         runtime_library_dirs=add_runtime_library_dirs)

    extensions = [gumath_ext(), functions_ext(), examples_ext()]
    if config_vars.get("HAVE_CUDA"):
        extensions += [cuda_ext()]
    return extensions
Пример #11
0
def cdecimal_ext(machine):
    depends = [
        'basearith.h', 'bits.h', 'constants.h', 'convolute.h', 'crt.h',
        'difradix2.h', 'docstrings.h', 'fnt.h', 'fourstep.h', 'io.h',
        'memory.h', 'mpdecimal.h', 'mpdecimal32.h', 'mpdecimal64.h',
        'mptypes.h', 'numbertheory.h', 'sixstep.h', 'transpose.h',
        'typearith.h', 'umodarith.h'
    ]
    sources = [
        'basearith.c', 'constants.c', 'context.c', 'convolute.c', 'crt.c',
        'difradix2.c', 'fnt.c', 'fourstep.c', 'io.c', 'memory.c',
        'mpdecimal.c', 'numbertheory.c', 'sixstep.c', 'transpose.c'
    ]
    sources.append('cdecimal2.c' if PY_MAJOR == 2 else 'cdecimal3.c')
    extra_compile_args = []
    extra_link_args = []
    extra_objects = []

    if SYSTEM == 'win32':
        define_macros.append(('_CRT_SECURE_NO_WARNINGS', '1'))
        if not machine:  # command line option
            if ARCH == '64bit':
                machine = 'x64'
            else:
                machine = 'ppro'

        if machine == 'x64':
            if not (PY_MAJOR == 2 and PY_MINOR == 5):
                # set the build environment for ml64
                from distutils.msvc9compiler import MSVCCompiler
                cc = MSVCCompiler()
                cc.initialize()
                del cc
            define_macros.extend([('CONFIG_64', '1'), ('MASM', '1')])
            extra_objects = ['vcdiv64.obj']
            os.system("ml64 /c /Cx vcdiv64.asm")
            copy2("mpdecimal64vc.h", "mpdecimal.h")
        elif machine == 'ansi64':
            define_macros.extend([('CONFIG_64', '1'), ('ANSI', '1')])
            copy2("mpdecimal64vc.h", "mpdecimal.h")
        elif machine == 'ppro':
            define_macros.extend([('CONFIG_32', '1'), ('PPRO', '1'),
                                  ('MASM', '1')])
            copy2("mpdecimal32vc.h", "mpdecimal.h")
        elif machine == 'ansi32':
            define_macros.extend([('CONFIG_32', '1'), ('ANSI', '1')])
            copy2("mpdecimal32vc.h", "mpdecimal.h")
        elif machine == 'ansi-legacy':
            define_macros.extend([('CONFIG_32', '1'), ('ANSI', '1'),
                                  ('LEGACY_COMPILER', '1')])
            copy2("mpdecimal32vc.h", "mpdecimal.h")
        else:
            err_exit("unsupported machine: %s" % machine)

    else:
        cc = sysconfig.get_config_var('CC')
        py_size_t = sysconfig.get_config_var('SIZEOF_SIZE_T')
        if py_size_t != 8 and py_size_t != 4:
            err_exit("unsupported architecture: sizeof(size_t) must be 8 or 4")

        depends.append('config.h')
        config_vars = configure(machine, cc, py_size_t)
        if config_vars['SIZEOF_SIZE_T'] != 8 and \
           config_vars['SIZEOF_SIZE_T'] != 4:
            err_exit("unsupported architecture: sizeof(size_t) must be 8 or 4")

        if not machine and py_size_t != config_vars['SIZEOF_SIZE_T']:
            if py_size_t == 8:
                print(MULTILIB_ERR_64)
            elif py_size_t == 4:
                print(MULTILIB_ERR_32)
            sys.exit(1)

        if not machine:
            if config_vars['HAVE_GCC_ASM_FOR_X64']:
                machine = 'x64'
            elif config_vars['HAVE_UINT128_T']:
                machine = 'uint128'
            elif config_vars['HAVE_GCC_ASM_FOR_X87']:
                machine = 'ppro'

        if machine == 'universal':
            add_macros = [('UNIVERSAL', '1')]
        elif py_size_t == 8:
            if machine == 'x64':
                add_macros = [('CONFIG_64', '1'), ('ASM', '1')]
            elif machine == 'uint128':
                add_macros = [('CONFIG_64', '1'), ('ANSI', '1'),
                              ('HAVE_UINT128_T', '1')]
            else:
                add_macros = [('CONFIG_64', '1'), ('ANSI', '1')]
        else:
            if machine == 'ppro' and ('gcc' in cc or 'clang' in cc):
                # suncc: register allocator cannot deal with the inline asm.
                # icc >= 11.0 works as well.
                add_macros = [('CONFIG_32', '1'), ('PPRO', '1'), ('ASM', '1')]
                if config_vars['HAVE_IPA_PURE_CONST_BUG']:
                    # Some versions of gcc miscompile inline asm:
                    # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46491
                    # http://gcc.gnu.org/ml/gcc/2010-11/msg00366.html
                    extra_compile_args.extend(['-fno-ipa-pure-const'])
            else:  # ansi32
                add_macros = [('CONFIG_32', '1'), ('ANSI', '1')]
                if machine == 'ansi-legacy':
                    add_macros.append(('LEGACY_COMPILER', '1'))

        # Uncomment for warnings:
        # extra_compile_args.extend(['-Wall', '-W', '-Wno-missing-field-initializers'])

        # Uncomment for a debug build:
        # extra_compile_args.extend(['-O0', '-g'])

        if os.environ.get("CFLAGS"):
            # Distutils drops -fno-strict-aliasing if CFLAGS are set:
            # http://bugs.python.org/issue10847
            if 'xlc' in cc:
                extra_compile_args.append('-qnoansialias')
            else:
                extra_compile_args.append('-fno-strict-aliasing')

        define_macros.extend(add_macros)

        if config_vars['HAVE_GLIBC_MEMMOVE_BUG']:
            # _FORTIFY_SOURCE wrappers for memmove and bcopy are incorrect:
            # http://sourceware.org/ml/libc-alpha/2010-12/msg00009.html
            undef_macros.append('_FORTIFY_SOURCE')

    ext = Extension('cdecimal',
                    define_macros=define_macros,
                    undef_macros=undef_macros,
                    depends=depends,
                    extra_compile_args=extra_compile_args,
                    extra_link_args=extra_link_args,
                    sources=sources,
                    extra_objects=extra_objects)
    return ext