Example #1
0
    def get_ethtool_macro():
        # see: https://github.com/giampaolo/psutil/issues/659
        from distutils.unixccompiler import UnixCCompiler
        from distutils.errors import CompileError

        with tempfile.NamedTemporaryFile(suffix='.c', delete=False,
                                         mode="wt") as f:
            f.write("#include <linux/ethtool.h>")

        @atexit.register
        def on_exit():
            try:
                os.remove(f.name)
            except OSError:
                pass

        compiler = UnixCCompiler()
        try:
            with silenced_output('stderr'):
                with silenced_output('stdout'):
                    compiler.compile([f.name])
        except CompileError:
            return ("PSUTIL_ETHTOOL_MISSING_TYPES", 1)
        else:
            return None
Example #2
0
 def __init__(self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     status, details = check_config_h()
     self.debug_print("Python's GCC status: %s (details: %s)" % (status, details))
     if status is not CONFIG_H_OK:
         self.warn(
             "Python's pyconfig.h doesn't seem to support your compiler. Reason: %s. Compiling may fail because of undefined preprocessor macros."
             % details
         )
     self.gcc_version, self.ld_version, self.dllwrap_version = get_versions()
     self.debug_print(
         self.compiler_type
         + ": gcc %s, ld %s, dllwrap %s\n" % (self.gcc_version, self.ld_version, self.dllwrap_version)
     )
     if self.ld_version >= "2.10.90":
         self.linker_dll = "gcc"
     else:
         self.linker_dll = "dllwrap"
     if self.ld_version >= "2.13":
         shared_option = "-shared"
     else:
         shared_option = "-mdll -static"
     self.set_executables(
         compiler="gcc -mcygwin -O -Wall",
         compiler_so="gcc -mcygwin -mdll -O -Wall",
         compiler_cxx="g++ -mcygwin -O -Wall",
         linker_exe="gcc -mcygwin",
         linker_so="%s -mcygwin %s" % (self.linker_dll, shared_option),
     )
     if self.gcc_version == "2.91.57":
         self.dll_libraries = ["msvcrt"]
         self.warn("Consider upgrading to a newer version of gcc")
     else:
         self.dll_libraries = get_msvcr()
Example #3
0
    def __init__(self, verbose=0, dry_run=0, force=0):

        UnixCCompiler.__init__(self, verbose, dry_run, force)

        (status, details) = check_config_h()
        self.debug_print("Python's GCC status: %s (details: %s)" %
                         (status, details))
        if status is not CONFIG_H_OK:
            self.warn(
                "Python's pyconfig.h doesn't seem to support your compiler.  "
                + ("Reason: %s." % details) +
                "Compiling may fail because of undefined preprocessor macros.")

        (self.gcc_version, self.ld_version) = \
            get_versions()
        self.debug_print(self.compiler_type + ": gcc %s, ld %s\n" %
                         (self.gcc_version, self.ld_version))

        # Hard-code GCC because that's what this is all about.
        # XXX optimization, warnings etc. should be customizable.
        self.set_executables(
            compiler='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
            compiler_so='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
            linker_exe='gcc -Zomf -Zmt -Zcrtdll',
            linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll')

        # want the gcc library statically linked (so that we don't have
        # to distribute a version dependent on the compiler we have)
        self.dll_libraries = ["gcc"]
Example #4
0
    def get_ethtool_macro():
        # see: https://github.com/giampaolo/psutil/issues/659
        from distutils.unixccompiler import UnixCCompiler
        from distutils.errors import CompileError

        with tempfile.NamedTemporaryFile(
                suffix='.c', delete=False, mode="wt") as f:
            f.write("#include <linux/ethtool.h>")

        @atexit.register
        def on_exit():
            try:
                os.remove(f.name)
            except OSError:
                pass

        compiler = UnixCCompiler()
        try:
            with silenced_output('stderr'):
                with silenced_output('stdout'):
                    compiler.compile([f.name])
        except CompileError:
            return ("PSUTIL_ETHTOOL_MISSING_TYPES", 1)
        else:
            return None
 def __init__(self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     status, details = check_config_h()
     self.debug_print("Python's GCC status: %s (details: %s)" %
                      (status, details))
     if status is not CONFIG_H_OK:
         self.warn(
             "Python's pyconfig.h doesn't seem to support your compiler. Reason: %s. Compiling may fail because of undefined preprocessor macros."
             % details)
     self.gcc_version, self.ld_version, self.dllwrap_version = get_versions(
     )
     self.debug_print(
         self.compiler_type + ': gcc %s, ld %s, dllwrap %s\n' %
         (self.gcc_version, self.ld_version, self.dllwrap_version))
     if self.ld_version >= '2.10.90':
         self.linker_dll = 'gcc'
     else:
         self.linker_dll = 'dllwrap'
     if self.ld_version >= '2.13':
         shared_option = '-shared'
     else:
         shared_option = '-mdll -static'
     self.set_executables(compiler='gcc -mcygwin -O -Wall',
                          compiler_so='gcc -mcygwin -mdll -O -Wall',
                          compiler_cxx='g++ -mcygwin -O -Wall',
                          linker_exe='gcc -mcygwin',
                          linker_so='%s -mcygwin %s' %
                          (self.linker_dll, shared_option))
     if self.gcc_version == '2.91.57':
         self.dll_libraries = ['msvcrt']
         self.warn('Consider upgrading to a newer version of gcc')
     else:
         self.dll_libraries = get_msvcr()
    def __init__ (self,
                  verbose=0,
                  dry_run=0,
                  force=0):

        UnixCCompiler.__init__ (self, verbose, dry_run, force)

        (status, details) = check_config_h()
        self.debug_print("Python's GCC status: %s (details: %s)" %
                         (status, details))
        if status is not CONFIG_H_OK:
            self.warn(
                "Python's pyconfig.h doesn't seem to support your compiler.  " +
                ("Reason: %s." % details) +
                "Compiling may fail because of undefined preprocessor macros.")

        (self.gcc_version, self.ld_version) = \
            get_versions()
        self.debug_print(self.compiler_type + ": gcc %s, ld %s\n" %
                         (self.gcc_version,
                          self.ld_version) )

        # Hard-code GCC because that's what this is all about.
        # XXX optimization, warnings etc. should be customizable.
        self.set_executables(compiler='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
                             compiler_so='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
                             linker_exe='gcc -Zomf -Zmt -Zcrtdll',
                             linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll')

        # want the gcc library statically linked (so that we don't have
        # to distribute a version dependent on the compiler we have)
        self.dll_libraries=["gcc"]
Example #7
0
 def __init__(self):
     # Check to ensure that nvcc can be located
     try:
         subprocess.check_output('nvcc --help', shell=True)
     except CalledProcessError:
         print >> sys.stderr, 'Could not find nvcc, the nvidia cuda compiler'
         sys.exit(1)
     UnixCCompiler.__init__(self)
Example #8
0
 def __init__(self):
     # Check to ensure that nvcc can be located
     try:
         subprocess.check_output('nvcc --help', shell=True)
     except CalledProcessError:
         print >> sys.stderr, 'Could not find nvcc, the nvidia cuda compiler'
         sys.exit(1)
     UnixCCompiler.__init__(self)
Example #9
0
 def __init__ (self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__ (self, verbose, dry_run, force)
     cc = 'icc'
     self.set_executables(compiler=cc,
                          compiler_so=cc,
                          compiler_cxx=cc,
                          linker_exe=cc,
                          linker_so=cc + ' -shared')
Example #10
0
 def __init__(self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     compiler = self.cc_exe
     self.set_executables(compiler=compiler,
                          compiler_so=compiler,
                          compiler_cxx=compiler,
                          linker_exe=compiler,
                          linker_so=compiler + ' -shared')
 def __init__ (self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__ (self, verbose,dry_run, force)
     compiler = self.cc_exe
     self.set_executables(compiler=compiler,
                          compiler_so=compiler,
                          compiler_cxx=compiler,
                          linker_exe=compiler,
                          linker_so=compiler + ' -shared')
    def __init__(self, verbose=0, dry_run=0, force=0):

        UnixCCompiler.__init__(self, verbose, dry_run, force)

        status, details = check_config_h()
        self.debug_print("Python's GCC status: %s (details: %s)" %
                         (status, details))
        if status is not CONFIG_H_OK:
            self.warn(
                "Python's pyconfig.h doesn't seem to support your compiler. "
                "Reason: %s. "
                "Compiling may fail because of undefined preprocessor macros."
                % details)

        self.gcc_version, self.ld_version, self.dllwrap_version = \
            get_versions()
        self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
                         (self.gcc_version,
                          self.ld_version,
                          self.dllwrap_version) )

        # ld_version >= "2.10.90" and < "2.13" should also be able to use
        # gcc -mdll instead of dllwrap
        # Older dllwraps had own version numbers, newer ones use the
        # same as the rest of binutils ( also ld )
        # dllwrap 2.10.90 is buggy
        if self.ld_version >= "2.10.90":
            self.linker_dll = "gcc"
        else:
            self.linker_dll = "dllwrap"

        # ld_version >= "2.13" support -shared so use it instead of
        # -mdll -static
        if self.ld_version >= "2.13":
            shared_option = "-shared"
        else:
            shared_option = "-mdll -static"

        # Hard-code GCC because that's what this is all about.
        # XXX optimization, warnings etc. should be customizable.
        self.set_executables(compiler='gcc -mcygwin -O -Wall',
                             compiler_so='gcc -mcygwin -mdll -O -Wall',
                             compiler_cxx='g++ -mcygwin -O -Wall',
                             linker_exe='gcc -mcygwin',
                             linker_so=('%s -mcygwin %s' %
                                        (self.linker_dll, shared_option)))

        # cygwin and mingw32 need different sets of libraries
        if self.gcc_version == "2.91.57":
            # cygwin shouldn't need msvcrt, but without the dlls will crash
            # (gcc version 2.91.57) -- perhaps something about initialization
            self.dll_libraries=["msvcrt"]
            self.warn(
                "Consider upgrading to a newer version of gcc")
        else:
            # Include the appropriate MSVC runtime library if Python was built
            # with MSVC 7.0 or later.
            self.dll_libraries = get_msvcr()
Example #13
0
    def __init__ (self, verbose=0, dry_run=0, force=0):

        UnixCCompiler.__init__ (self, verbose, dry_run, force)

        (status, details) = check_config_h()
        self.debug_print("Python's GCC status: %s (details: %s)" %
                         (status, details))
        if status is not CONFIG_H_OK:
            self.warn(
                "Python's pyconfig.h doesn't seem to support your compiler. "
                "Reason: %s. "
                "Compiling may fail because of undefined preprocessor macros."
                % details)

        self.gcc_version, self.ld_version, self.dllwrap_version = \
            get_versions()
        self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
                         (self.gcc_version,
                          self.ld_version,
                          self.dllwrap_version) )

        # ld_version >= "2.10.90" and < "2.13" should also be able to use
        # gcc -mdll instead of dllwrap
        # Older dllwraps had own version numbers, newer ones use the
        # same as the rest of binutils ( also ld )
        # dllwrap 2.10.90 is buggy
        if self.ld_version >= "2.10.90":
            self.linker_dll = "gcc"
        else:
            self.linker_dll = "dllwrap"

        # ld_version >= "2.13" support -shared so use it instead of
        # -mdll -static
        if self.ld_version >= "2.13":
            shared_option = "-shared"
        else:
            shared_option = "-mdll -static"

        # Hard-code GCC because that's what this is all about.
        # XXX optimization, warnings etc. should be customizable.
        self.set_executables(compiler='gcc -mcygwin -O -Wall',
                             compiler_so='gcc -mcygwin -mdll -O -Wall',
                             compiler_cxx='g++ -mcygwin -O -Wall',
                             linker_exe='gcc -mcygwin',
                             linker_so=('%s -mcygwin %s' %
                                        (self.linker_dll, shared_option)))

        # cygwin and mingw32 need different sets of libraries
        if self.gcc_version == "2.91.57":
            # cygwin shouldn't need msvcrt, but without the dlls will crash
            # (gcc version 2.91.57) -- perhaps something about initialization
            self.dll_libraries=["msvcrt"]
            self.warn(
                "Consider upgrading to a newer version of gcc")
        else:
            # Include the appropriate MSVC runtime library if Python was built
            # with MSVC 7.0 or later.
            self.dll_libraries = get_msvcr()
Example #14
0
 def __init__ (self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__ (self, verbose,dry_run, force)
     self.cc_exe = 'icc -O3 -fPIC -fp-model strict -fomit-frame-pointer -openmp -xHost -w '
     compiler = self.cc_exe
     self.set_executables(compiler=compiler,
                          compiler_so=compiler,
                          compiler_cxx=compiler,
                          linker_exe=compiler,
                          linker_so=compiler + ' -shared')
Example #15
0
 def __init__(self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     self.cc_exe = 'icc -O3 -g -fPIC -fp-model strict -fomit-frame-pointer -openmp -axCORE-AVX2 -xSSE4.2 '
     compiler = self.cc_exe
     self.set_executables(compiler=compiler,
                          compiler_so=compiler,
                          compiler_cxx=compiler,
                          linker_exe=compiler,
                          linker_so=compiler + ' -shared')
Example #16
0
 def __init__(self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     cc_compiler = self.cc_exe
     cxx_compiler = self.cxx_exe
     self.set_executables(compiler=cc_compiler + ' -O3 -fPIC',
                          compiler_so=cc_compiler + ' -O3 -fPIC',
                          compiler_cxx=cxx_compiler + ' -O3 -fPIC',
                          linker_exe=cc_compiler + ' -lamath',
                          linker_so=cc_compiler + ' -lamath -shared')
Example #17
0
 def __init__(self, verbose = 0, dry_run = 0, force = 0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     status, details = check_config_h()
     self.debug_print("Python's GCC status: %s (details: %s)" % (status, details))
     if status is not CONFIG_H_OK:
         self.warn("Python's pyconfig.h doesn't seem to support your compiler.  " + 'Reason: %s.' % details + 'Compiling may fail because of undefined preprocessor macros.')
     self.gcc_version, self.ld_version = get_versions()
     self.debug_print(self.compiler_type + ': gcc %s, ld %s\n' % (self.gcc_version, self.ld_version))
     self.set_executables(compiler='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall', compiler_so='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall', linker_exe='gcc -Zomf -Zmt -Zcrtdll', linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll')
     self.dll_libraries = ['gcc']
Example #18
0
 def preprocess(self,
                source,
                output_file=None,
                macros=None,
                include_dirs=None,
                extra_preargs=None,
                extra_postargs=None):
     print("PREPROCESS")
     UnixCCompiler.preprocess(self, source, output_file, macros,
                              include_dirs, extra_preargs, exta_postargs)
Example #19
0
 def __init__(self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     self.cc_exe = 'icc -m64 -fPIC'
     compiler = self.cc_exe
     self.set_executables(compiler=compiler,
                          compiler_so=compiler,
                          compiler_cxx=compiler,
                          archiver='xiar' + ' cru',
                          linker_exe=compiler,
                          linker_so=compiler + ' -shared')
Example #20
0
 def __init__(self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     self.cc_exe = 'icc -m64 -fPIC'
     compiler = self.cc_exe
     self.set_executables(compiler=compiler,
                          compiler_so=compiler,
                          compiler_cxx=compiler,
                          archiver='xiar' + ' cru',
                          linker_exe=compiler,
                          linker_so=compiler + ' -shared')
Example #21
0
 def __init__(self, verbose = 0, dry_run = 0, force = 0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     status, details = check_config_h()
     self.debug_print("Python's GCC status: %s (details: %s)" % (status, details))
     if status is not CONFIG_H_OK:
         self.warn("Python's pyconfig.h doesn't seem to support your compiler.  " + 'Reason: %s.' % details + 'Compiling may fail because of undefined preprocessor macros.')
     self.gcc_version, self.ld_version = get_versions()
     self.debug_print(self.compiler_type + ': gcc %s, ld %s\n' % (self.gcc_version, self.ld_version))
     self.set_executables(compiler='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall', compiler_so='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall', linker_exe='gcc -Zomf -Zmt -Zcrtdll', linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll')
     self.dll_libraries = ['gcc']
Example #22
0
 def __init__(self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     self.cc_exe = ('icc -m64 -fPIC -fp-model strict -O3 '
                    '-fomit-frame-pointer -openmp -xSSE4.2')
     compiler = self.cc_exe
     self.set_executables(compiler=compiler,
                          compiler_so=compiler,
                          compiler_cxx=compiler,
                          archiver='xiar' + ' cru',
                          linker_exe=compiler + ' -shared-intel',
                          linker_so=compiler + ' -shared -shared-intel')
Example #23
0
    def link(
        self,
        target_desc,
        objects,
        output_filename,
        output_dir=None,
        libraries=None,
        library_dirs=None,
        runtime_library_dirs=None,
        export_symbols=None,
        debug=0,
        extra_preargs=None,
        extra_postargs=None,
        build_temp=None,
        target_lang=None,
    ):
        extra_preargs = copy.copy(extra_preargs or [])
        libraries = copy.copy(libraries or [])
        objects = copy.copy(objects or [])
        libraries.extend(self.dll_libraries)
        if export_symbols is not None and (target_desc != self.EXECUTABLE or self.linker_dll == "gcc"):
            temp_dir = os.path.dirname(objects[0])
            dll_name, dll_extension = os.path.splitext(os.path.basename(output_filename))
            def_file = os.path.join(temp_dir, dll_name + ".def")
            lib_file = os.path.join(temp_dir, "lib" + dll_name + ".a")
            contents = ["LIBRARY %s" % os.path.basename(output_filename), "EXPORTS"]
            for sym in export_symbols:
                contents.append(sym)

            self.execute(write_file, (def_file, contents), "writing %s" % def_file)
            if self.linker_dll == "dllwrap":
                extra_preargs.extend(["--output-lib", lib_file])
                extra_preargs.extend(["--def", def_file])
            else:
                objects.append(def_file)
        if not debug:
            extra_preargs.append("-s")
        UnixCCompiler.link(
            self,
            target_desc,
            objects,
            output_filename,
            output_dir,
            libraries,
            library_dirs,
            runtime_library_dirs,
            None,
            debug,
            extra_preargs,
            extra_postargs,
            build_temp,
            target_lang,
        )
        return
 def __init__(self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     self.cc_exe = ('icc -m64 -fPIC -fp-model strict -O3 '
                    '-fomit-frame-pointer -openmp -xSSE4.2')
     compiler = self.cc_exe
     self.set_executables(compiler=compiler,
                          compiler_so=compiler,
                          compiler_cxx=compiler,
                          archiver='xiar' + ' cru',
                          linker_exe=compiler + ' -shared-intel',
                          linker_so=compiler + ' -shared -shared-intel')
    def link(self, target_desc, objects,
             output_filename, output_dir=None, libraries=None,
             library_dirs=None, runtime_library_dirs=None,
             export_symbols=None, debug=0, extra_preargs=None,
             extra_postargs=None, build_temp=None, target_lang=None):

        print "LINK"
        UnixCCompiler.link(self, target_desc, objects,
                           output_filename, output_dir, libraries,
                           library_dirs, runtime_library_dirs,
                           export_symbols, debug, extra_preargs,
                           extra_postargs, build_temp, target_lang)
Example #26
0
    def link(
        self,
        target_desc,
        objects,
        output_filename,
        output_dir=None,
        libraries=None,
        library_dirs=None,
        runtime_library_dirs=None,
        export_symbols=None,
        debug=0,
        extra_preargs=None,
        extra_postargs=None,
        build_temp=None,
        target_lang=None,
    ):
        extra_preargs = copy.copy(extra_preargs or [])
        libraries = copy.copy(libraries or [])
        objects = copy.copy(objects or [])
        libraries.extend(self.dll_libraries)
        if export_symbols is not None and target_desc != self.EXECUTABLE:
            temp_dir = os.path.dirname(objects[0])
            dll_name, dll_extension = os.path.splitext(os.path.basename(output_filename))
            def_file = os.path.join(temp_dir, dll_name + ".def")
            contents = [
                "LIBRARY %s INITINSTANCE TERMINSTANCE" % os.path.splitext(os.path.basename(output_filename))[0],
                "DATA MULTIPLE NONSHARED",
                "EXPORTS",
            ]
            for sym in export_symbols:
                contents.append('  "%s"' % sym)

            self.execute(write_file, (def_file, contents), "writing %s" % def_file)
            objects.append(def_file)
        if not debug:
            extra_preargs.append("-s")
        UnixCCompiler.link(
            self,
            target_desc,
            objects,
            output_filename,
            output_dir,
            libraries,
            library_dirs,
            runtime_library_dirs,
            None,
            debug,
            extra_preargs,
            extra_postargs,
            build_temp,
            target_lang,
        )
        return
Example #27
0
 def link(
     self,
     target_desc,
     objects,
     output_filename,
     output_dir,
     libraries,
     library_dirs,
     runtime_library_dirs,
     export_symbols=None,  # export_symbols, we do this in our def-file
     debug=0,
     extra_preargs=None,
     extra_postargs=None,
     build_temp=None,
     target_lang=None,
 ):
     if self.gcc_version < "3.0.0":
         distutils.cygwinccompiler.CygwinCCompiler.link(
             self,
             target_desc,
             objects,
             output_filename,
             output_dir,
             libraries,
             library_dirs,
             runtime_library_dirs,
             None,  # export_symbols, we do this in our def-file
             debug,
             extra_preargs,
             extra_postargs,
             build_temp,
             target_lang,
         )
     else:
         UnixCCompiler.link(
             self,
             target_desc,
             objects,
             output_filename,
             output_dir,
             libraries,
             library_dirs,
             runtime_library_dirs,
             None,  # export_symbols, we do this in our def-file
             debug,
             extra_preargs,
             extra_postargs,
             build_temp,
             target_lang,
         )
Example #28
0
 def __init__(self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     self.cc_exe = ('icc -m64 -fPIC -fp-model strict -O3 '
                    '-fomit-frame-pointer -openmp -xSSE4.2')
     compiler = self.cc_exe
     if platform.system() == 'Darwin':
         shared_flag = '-Wl,-undefined,dynamic_lookup'
     else:
         shared_flag = '-shared'
     self.set_executables(compiler=compiler,
                          compiler_so=compiler,
                          compiler_cxx=compiler,
                          archiver='xiar' + ' cru',
                          linker_exe=compiler + ' -shared-intel',
                          linker_so=compiler + ' ' + shared_flag +
                          ' -shared-intel')
 def __init__(self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     self.cc_exe = ('icc -m64 -fPIC -fp-model strict -O3 '
                    '-fomit-frame-pointer -openmp')
     compiler = self.cc_exe
     if platform.system() == 'Darwin':
         shared_flag = '-Wl,-undefined,dynamic_lookup'
     else:
         shared_flag = '-shared'
     self.set_executables(compiler=compiler,
                          compiler_so=compiler,
                          compiler_cxx=compiler,
                          archiver='xiar' + ' cru',
                          linker_exe=compiler + ' -shared-intel',
                          linker_so=compiler + ' ' + shared_flag +
                          ' -shared-intel')
Example #30
0
 def link(
         self,
         target_desc,
         objects,
         output_filename,
         output_dir,
         libraries,
         library_dirs,
         runtime_library_dirs,
         export_symbols=None,  # export_symbols, we do this in our def-file
         debug=0,
         extra_preargs=None,
         extra_postargs=None,
         build_temp=None,
         target_lang=None):
     if self.gcc_version < "3.0.0":
         distutils.cygwinccompiler.CygwinCCompiler.link(
             self,
             target_desc,
             objects,
             output_filename,
             output_dir,
             libraries,
             library_dirs,
             runtime_library_dirs,
             None,  # export_symbols, we do this in our def-file
             debug,
             extra_preargs,
             extra_postargs,
             build_temp,
             target_lang)
     else:
         UnixCCompiler.link(
             self,
             target_desc,
             objects,
             output_filename,
             output_dir,
             libraries,
             library_dirs,
             runtime_library_dirs,
             None,  # export_symbols, we do this in our def-file
             debug,
             extra_preargs,
             extra_postargs,
             build_temp,
             target_lang)
Example #31
0
    def link(self, target_desc, objects, output_filename, output_dir=None,
             libraries=None, library_dirs=None, runtime_library_dirs=None,
             export_symbols=None, debug=0, extra_preargs=None,
             extra_postargs=None, build_temp=None, target_lang=None):
        """Link the objects."""
        # use separate copies, so we can modify the lists
        libraries = copy.copy(libraries or [])
        libraries.extend(self.dll_libraries)
        if os.name == 'nt':
            sysroot = os.path.dirname(os.path.realpath(sys.executable))
            library_dirs = copy.copy(library_dirs or [])
            library_dirs.append(sysroot)

        UnixCCompiler.link(self, target_desc, objects, output_filename,
            output_dir, libraries, library_dirs, runtime_library_dirs,
            None, # export_symbols, we do this in our def-file
            debug, extra_preargs, extra_postargs, build_temp, target_lang)
    def link(self,
             target_desc,
             objects,
             output_filename,
             output_dir=None,
             libraries=None,
             library_dirs=None,
             runtime_library_dirs=None,
             export_symbols=None,
             debug=0,
             extra_preargs=None,
             extra_postargs=None,
             build_temp=None,
             target_lang=None):
        extra_preargs = copy.copy(extra_preargs or [])
        libraries = copy.copy(libraries or [])
        objects = copy.copy(objects or [])
        libraries.extend(self.dll_libraries)
        if export_symbols is not None and (target_desc != self.EXECUTABLE
                                           or self.linker_dll == 'gcc'):
            temp_dir = os.path.dirname(objects[0])
            dll_name, dll_extension = os.path.splitext(
                os.path.basename(output_filename))
            def_file = os.path.join(temp_dir, dll_name + '.def')
            lib_file = os.path.join(temp_dir, 'lib' + dll_name + '.a')
            contents = [
                'LIBRARY %s' % os.path.basename(output_filename), 'EXPORTS'
            ]
            for sym in export_symbols:
                contents.append(sym)

            self.execute(write_file, (def_file, contents),
                         'writing %s' % def_file)
            if self.linker_dll == 'dllwrap':
                extra_preargs.extend(['--output-lib', lib_file])
                extra_preargs.extend(['--def', def_file])
            else:
                objects.append(def_file)
        if not debug:
            extra_preargs.append('-s')
        UnixCCompiler.link(self, target_desc, objects, output_filename,
                           output_dir, libraries, library_dirs,
                           runtime_library_dirs, None, debug, extra_preargs,
                           extra_postargs, build_temp, target_lang)
        return
Example #33
0
 def __init__(self, verbose=0, dry_run=0, force=0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     self.cc_exe = ('icc -fPIC -fp-model precise -O3 '
                    '-fomit-frame-pointer -qopenmp '
                    '-Wall -Wimplicit '
                    '-qoffload-option,mic,compiler,'
                    '\'"-fp-model fast=2 -Wl,-zdefs"\'')
     compiler = self.cc_exe
     if platform.system() == 'Darwin':
         shared_flag = '-Wl,-undefined,dynamic_lookup'
     else:
         shared_flag = '-shared'
     self.set_executables(compiler=compiler,
                          compiler_so=compiler,
                          compiler_cxx=compiler,
                          archiver='xiar' + ' cru',
                          linker_exe=compiler + ' -shared-intel',
                          linker_so=compiler + ' ' + shared_flag +
                          ' -shared-intel')
Example #34
0
    def link(self, target_desc, objects, output_filename, output_dir = None, libraries = None, library_dirs = None, runtime_library_dirs = None, export_symbols = None, debug = 0, extra_preargs = None, extra_postargs = None, build_temp = None, target_lang = None):
        extra_preargs = copy.copy(extra_preargs or [])
        libraries = copy.copy(libraries or [])
        objects = copy.copy(objects or [])
        libraries.extend(self.dll_libraries)
        if export_symbols is not None and target_desc != self.EXECUTABLE:
            temp_dir = os.path.dirname(objects[0])
            dll_name, dll_extension = os.path.splitext(os.path.basename(output_filename))
            def_file = os.path.join(temp_dir, dll_name + '.def')
            contents = ['LIBRARY %s INITINSTANCE TERMINSTANCE' % os.path.splitext(os.path.basename(output_filename))[0], 'DATA MULTIPLE NONSHARED', 'EXPORTS']
            for sym in export_symbols:
                contents.append('  "%s"' % sym)

            self.execute(write_file, (def_file, contents), 'writing %s' % def_file)
            objects.append(def_file)
        if not debug:
            extra_preargs.append('-s')
        UnixCCompiler.link(self, target_desc, objects, output_filename, output_dir, libraries, library_dirs, runtime_library_dirs, None, debug, extra_preargs, extra_postargs, build_temp, target_lang)
        return
Example #35
0
    def __init__(self, verbose=0, dry_run=0, force=0):

        UnixCCompiler.__init__(self, verbose, dry_run, force)

        (status, details) = check_config_h()
        self.debug_print("Python's GCC status: %s (details: %s)" %
                         (status, details))
        if status is not CONFIG_H_OK:
            self.warn(
                "Python's pyconfig.h doesn't seem to support your compiler. "
                "Reason: %s. "
                "Compiling may fail because of undefined preprocessor macros."
                % details)

        # want the gcc library statically linked (so that we don't have
        # to distribute a version dependent on the compiler we have)
        # self.dll_libraries=["gcc"]
        # was removed by the python 3.9 update, as I doubt it makes sense
        self.dll_libraries = []
Example #36
0
    def __init__(self, verbose=0, dry_run=0, force=0):
        UnixCCompiler.__init__(self, verbose, dry_run, force)

        v = self.get_version()
        self.cc_exe = ('icc -fPIC -fp-model strict -O3 -fomit-frame-pointer ' +
                       environ.get('CFLAGS', '').strip())
        compiler = self.cc_exe

        if platform.system() == 'Darwin':
            shared_flag = '-Wl,-undefined,dynamic_lookup'
        else:
            shared_flag = '-shared'
        self.set_executables(compiler=compiler,
                             compiler_so=compiler,
                             compiler_cxx=compiler,
                             archiver='xiar' + ' cru',
                             linker_exe=compiler + ' -shared-intel',
                             linker_so=compiler + ' ' + shared_flag +
                             ' -shared-intel ' +
                             environ.get('LDFLAGS', '').strip())
Example #37
0
    def __init__ (self, verbose=0, dry_run=0, force=0):
        UnixCCompiler.__init__ (self, verbose, dry_run, force)
        cc = 'clang'

        cflags = sysconfig.get_config_var ('CFLAGS') or ""
        cflags += os.getenv('CFLAGS', '')
        cshared = sysconfig.get_config_var ('CCSHARED') or ""
        ldflags = sysconfig.get_config_var ('LDFLAGS') or ""
        ldflags += os.getenv('LDFLAGS', '')
        cppflags = os.getenv ('CPPFLAGS', '')

        cargs = ' ' + cflags + ' ' + cppflags
        soargs = ' ' + cflags + ' ' + cshared
        ldargs = ' ' + ldflags
        
        self.set_executables(compiler=cc + cargs,
                             compiler_so=cc + soargs,
                             compiler_cxx=cc,
                             linker_exe=cc + ldflags,
                             linker_so=cc + ' -shared')
Example #38
0
    def __init__(self, verbose=0, dry_run=0, force=0):
        UnixCCompiler.__init__(self, verbose, dry_run, force)

        v = self.get_version()
        mpopt = 'openmp' if v and v < '15' else 'qopenmp'
        self.cc_exe = ('icc -fPIC -fp-model strict -O3 '
                       '-fomit-frame-pointer -{}').format(mpopt)
        compiler = self.cc_exe

        if platform.system() == 'Darwin':
            shared_flag = '-Wl,-undefined,dynamic_lookup'
        else:
            shared_flag = '-shared'
        self.set_executables(compiler=compiler,
                             compiler_so=compiler,
                             compiler_cxx=compiler,
                             archiver='xiar' + ' cru',
                             linker_exe=compiler + ' -shared-intel',
                             linker_so=compiler + ' ' + shared_flag +
                             ' -shared-intel')
Example #39
0
    def __init__(self, verbose=0, dry_run=0, force=0):
        UnixCCompiler.__init__(self, verbose, dry_run, force)

        v = self.get_version()
        mpopt = "openmp" if v and v < "15" else "qopenmp"
        self.cc_exe = ("icc -m64 -fPIC -fp-model strict -O3 "
                       "-fomit-frame-pointer -{}").format(mpopt)
        compiler = self.cc_exe

        if platform.system() == "Darwin":
            shared_flag = "-Wl,-undefined,dynamic_lookup"
        else:
            shared_flag = "-shared"
        self.set_executables(
            compiler=compiler,
            compiler_so=compiler,
            compiler_cxx=compiler,
            archiver="xiar" + " cru",
            linker_exe=compiler + " -shared-intel",
            linker_so=compiler + " " + shared_flag + " -shared-intel",
        )
Example #40
0
    def get_ethtool_macro():
        # see: https://github.com/giampaolo/psutil/issues/659
        from distutils.unixccompiler import UnixCCompiler
        from distutils.errors import CompileError

        with tempfile.NamedTemporaryFile(suffix='.c', delete=False,
                                         mode="wt") as f:
            f.write("#include <linux/ethtool.h>")

        output_dir = tempfile.mkdtemp()
        try:
            compiler = UnixCCompiler()
            # https://github.com/giampaolo/psutil/pull/1568
            if os.getenv('CC'):
                compiler.set_executable('compiler_so', os.getenv('CC'))
            with silenced_output('stderr'):
                with silenced_output('stdout'):
                    compiler.compile([f.name], output_dir=output_dir)
        except CompileError:
            return ("PSUTIL_ETHTOOL_MISSING_TYPES", 1)
        else:
            return None
        finally:
            os.remove(f.name)
            shutil.rmtree(output_dir)
Example #41
0
 def __init__(self, verbose = 0, dry_run = 0, force = 0):
     UnixCCompiler.__init__(self, verbose, dry_run, force)
     status, details = check_config_h()
     self.debug_print("Python's GCC status: %s (details: %s)" % (status, details))
     if status is not CONFIG_H_OK:
         self.warn("Python's pyconfig.h doesn't seem to support your compiler. Reason: %s. Compiling may fail because of undefined preprocessor macros." % details)
     self.gcc_version, self.ld_version, self.dllwrap_version = get_versions()
     self.debug_print(self.compiler_type + ': gcc %s, ld %s, dllwrap %s\n' % (self.gcc_version, self.ld_version, self.dllwrap_version))
     if self.ld_version >= '2.10.90':
         self.linker_dll = 'gcc'
     else:
         self.linker_dll = 'dllwrap'
     if self.ld_version >= '2.13':
         shared_option = '-shared'
     else:
         shared_option = '-mdll -static'
     self.set_executables(compiler='gcc -mcygwin -O -Wall', compiler_so='gcc -mcygwin -mdll -O -Wall', compiler_cxx='g++ -mcygwin -O -Wall', linker_exe='gcc -mcygwin', linker_so='%s -mcygwin %s' % (self.linker_dll, shared_option))
     if self.gcc_version == '2.91.57':
         self.dll_libraries = ['msvcrt']
         self.warn('Consider upgrading to a newer version of gcc')
     else:
         self.dll_libraries = get_msvcr()
Example #42
0
    def __init__(self, verbose=0, dry_run=0, force=0):
        try:
            import tinycc
        except ImportError:
            DistutilsPlatformError(
                "tinycc not installed or not supported for this platform")

        UnixCCompiler.__init__(self, verbose, dry_run, force)

        status, details = check_config_h()
        self.debug_print("Python's GCC status: %s (details: %s)" %
                         (status, details))
        if status is not CONFIG_H_OK:
            self.warn(
                "Python's pyconfig.h doesn't seem to support your compiler. "
                "Reason: %s. "
                "Compiling may fail because of undefined preprocessor macros."
                % details)

        self.tcc_version = _find_exe_version([tinycc.TCC, '-v'])
        self.debug_print(self.compiler_type + ": tcc %s\n" % self.tcc_version)

        self.set_executables(
            compiler=[tinycc.TCC, '-DMS_WIN64', '-D__TINYCC__', '-Wall'],
            compiler_so=[tinycc.TCC, '-DMS_WIN64', '-D__TINYCC__', '-Wall'],
            compiler_cxx=[],
            linker_exe=[tinycc.TCC],
            linker_so=[tinycc.TCC, '-shared'],
        )

        # Include the appropriate MSVC runtime library if Python was built
        # with MSVC 7.0 or later.
        if os.name == 'nt':
            self.dll_libraries = get_msvcr()
        else:
            self.dll_libraries = []
Example #43
0
    def link(self, target_desc, objects, output_filename, output_dir = None, libraries = None, library_dirs = None, runtime_library_dirs = None, export_symbols = None, debug = 0, extra_preargs = None, extra_postargs = None, build_temp = None, target_lang = None):
        extra_preargs = copy.copy(extra_preargs or [])
        libraries = copy.copy(libraries or [])
        objects = copy.copy(objects or [])
        libraries.extend(self.dll_libraries)
        if export_symbols is not None and (target_desc != self.EXECUTABLE or self.linker_dll == 'gcc'):
            temp_dir = os.path.dirname(objects[0])
            dll_name, dll_extension = os.path.splitext(os.path.basename(output_filename))
            def_file = os.path.join(temp_dir, dll_name + '.def')
            lib_file = os.path.join(temp_dir, 'lib' + dll_name + '.a')
            contents = ['LIBRARY %s' % os.path.basename(output_filename), 'EXPORTS']
            for sym in export_symbols:
                contents.append(sym)

            self.execute(write_file, (def_file, contents), 'writing %s' % def_file)
            if self.linker_dll == 'dllwrap':
                extra_preargs.extend(['--output-lib', lib_file])
                extra_preargs.extend(['--def', def_file])
            else:
                objects.append(def_file)
        if not debug:
            extra_preargs.append('-s')
        UnixCCompiler.link(self, target_desc, objects, output_filename, output_dir, libraries, library_dirs, runtime_library_dirs, None, debug, extra_preargs, extra_postargs, build_temp, target_lang)
        return
Example #44
0
    def __init__(self, verbose=0, dry_run=0, force=0):
        try:
            import tinycc
        except ImportError:
            DistutilsPlatformError("tinycc not installed or not supported for this platform")


        UnixCCompiler.__init__(self, verbose, dry_run, force)

        status, details = check_config_h()
        self.debug_print("Python's GCC status: %s (details: %s)" %
                         (status, details))
        if status is not CONFIG_H_OK:
            self.warn(
                "Python's pyconfig.h doesn't seem to support your compiler. "
                "Reason: %s. "
                "Compiling may fail because of undefined preprocessor macros."
                % details)

        self.tcc_version = _find_exe_version([tinycc.TCC, '-v'])
        self.debug_print(self.compiler_type + ": tcc %s\n" % self.tcc_version)

        self.set_executables(
            compiler=[tinycc.TCC, '-DMS_WIN64', '-D__TINYCC__', '-Wall'],
            compiler_so=[tinycc.TCC, '-DMS_WIN64', '-D__TINYCC__', '-Wall'],
            compiler_cxx=[],
            linker_exe=[tinycc.TCC],
            linker_so=[tinycc.TCC, '-shared'],
        )

        # Include the appropriate MSVC runtime library if Python was built
        # with MSVC 7.0 or later.
        if os.name == 'nt':
            self.dll_libraries = get_msvcr()
        else:
            self.dll_libraries = []
Example #45
0
def compile_exe():
    user = os.path.expanduser("~/.pyinitrd")
    if not os.path.exists(user):
        os.mkdir(user)

    src = os.path.join(user, "gen_init_cpio.c")
    if not os.path.exists(src):
        orig = "/usr/src/linux/usr/gen_init_cpio.c"
        if not os.path.exists(orig):
            Exception("Requires Linux kernel sources in %r" % orig)
        shutil.copyfile(orig, src)

    compiler = UnixCCompiler()

    obj = os.path.join(user, "gen_init_cpio.o")
    if not os.path.exists(obj):
        compiler.compile(["gen_init_cpio.c"], user)

    exe = os.path.join(user, "gen_init_cpio")
    if not os.path.exists(exe):
        print("compiling")
        compiler.link_executable([obj], exe, user)

    return exe
Example #46
0
    def run(self):
        if not self.extensions:
            return

        if self.distribution.has_c_libraries():
            build_clib = self.get_finalized_command('build_clib')
            self.libraries.extend(build_clib.get_library_names() or [])
            self.library_dirs.append(build_clib.build_clib)

        from distutils.unixccompiler import UnixCCompiler

        self.compiler = UnixCCompiler(verbose=self.verbose,
                                      dry_run=self.dry_run,
                                      force=self.force)

        self.compiler.shared_lib_extension = ".pyd"  # not used :(

        if self.libraries is not None:
            self.compiler.set_libraries(self.libraries)

        if self.library_dirs is not None:
            self.compiler.set_library_dirs(self.library_dirs)

        python_lib = "python" + self.cross_ver.replace(".", "")

        import os.path, subprocess
        if not os.path.exists(os.path.join(self.cross_dir,
                                           python_lib + ".def")):
            log.info("making def for %s in %s", python_lib, self.cross_dir)
            subprocess.check_call(["gendef", python_lib + ".dll"],
                                  cwd=self.cross_dir)

        python_lib_fname = self.compiler.static_lib_format % (
            python_lib, self.compiler.static_lib_extension)
        if not os.path.exists(os.path.join(self.cross_dir, python_lib_fname)):
            log.info("making link library %s for %s in %s", python_lib_fname,
                     python_lib, self.cross_dir)
            print self.cross_compiler.replace("gcc", "dlltool")
            subprocess.check_call([
                self.cross_compiler.replace(
                    "gcc", "dlltool"), "--dllname", python_lib + ".dll",
                "--def", python_lib + ".def", "--output-lib", python_lib_fname
            ],
                                  cwd=self.cross_dir)

        specs_fname = os.path.join(self.cross_dir, "compiler.specs")
        if not os.path.exists(specs_fname):
            log.info("making compiler specs %s", specs_fname)
            msvcr = msvct_table.get(self.cross_ver)
            newspecs = make_specs(self.cross_compiler, msvcr, int(msvcr[-2:]))
            fh = open(specs_fname, "w")
            fh.write(newspecs)
            fh.close()

        self.compiler.set_executables(
            compiler_so="{} -specs={}".format(self.cross_compiler,
                                              specs_fname),
            linker_so="{} -specs={} -static-libgcc -shared".format(
                self.cross_compiler, specs_fname),
        )

        if "win-amd64" == self.plat_name:
            self.compiler.define_macro("MS_WIN64")

        self.compiler.add_library(python_lib)
        self.compiler.add_library_dir(self.cross_dir)
        self.compiler.add_include_dir(os.path.join(self.cross_dir, 'include'))

        # Now actually compile and link everything.
        self.build_extensions()
    def link_shared_object (self,
                            objects,
                            output_filename,
                            output_dir=None,
                            libraries=None,
                            library_dirs=None,
                            runtime_library_dirs=None,
                            export_symbols=None,
                            debug=0,
                            extra_preargs=None,
                            extra_postargs=None,
                            build_temp=None):
        
        # use separate copies, so we can modify the lists
        extra_preargs = copy.copy(extra_preargs or [])
        libraries = copy.copy(libraries or [])
        
        # Additional libraries
        libraries.extend(self.dll_libraries)
        
        # we want to put some files in the same directory as the 
        # object files are, build_temp doesn't help much

        # where are the object files
        temp_dir = os.path.dirname(objects[0])

        # name of dll to give the helper files (def, lib, exp) the same name
        (dll_name, dll_extension) = os.path.splitext(
            os.path.basename(output_filename))

        # generate the filenames for these files
        def_file = None # this will be done later, if necessary
        exp_file = os.path.join(temp_dir, dll_name + ".exp")
        lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")

        #extra_preargs.append("--verbose")
        if self.linker == "dllwrap":
            extra_preargs.extend([#"--output-exp",exp_file,
                                  "--output-lib",lib_file,
                                 ])
        else:
            # doesn't work: bfd_close build\...\libfoo.a: Invalid operation
            extra_preargs.extend([#"-Wl,--out-implib,%s" % lib_file,
                                 ])
       
        #  check what we got in export_symbols
        if export_symbols is not None:
            # Make .def file
            # (It would probably better to check if we really need this, 
            # but for this we had to insert some unchanged parts of 
            # UnixCCompiler, and this is not what we want.) 
            def_file = os.path.join(temp_dir, dll_name + ".def")
            contents = [
                "LIBRARY %s" % os.path.basename(output_filename),
                "EXPORTS"]
            for sym in export_symbols:
                contents.append(sym)
            self.execute(write_file, (def_file, contents),
                         "writing %s" % def_file)

        if def_file:
            if self.linker == "dllwrap":
                # for dllwrap we have to use a special option
                extra_preargs.append("--def")
            # for gcc/ld it is specified as any other object file    
            extra_preargs.append(def_file)
                                                 
        # who wants symbols and a many times larger output file
        # should explicitly switch the debug mode on 
        # otherwise we let dllwrap/ld strip the output file
        # (On my machine unstripped_file = stripped_file + 254KB
        #   10KB < stripped_file < ??100KB ) 
        if not debug: 
            extra_preargs.append("-s") 
        
        UnixCCompiler.link_shared_object(self,
                            objects,
                            output_filename,
                            output_dir,
                            libraries,
                            library_dirs,
                            runtime_library_dirs,
                            None, # export_symbols, we do this in our def-file
                            debug,
                            extra_preargs,
                            extra_postargs,
                            build_temp)
    def __init__(self, verbose=0, dry_run=0, force=0):

        UnixCCompiler.__init__(self, verbose, dry_run, force)
        self.set_executable("compiler", "nasm")
    def link (self,
              target_desc,
              objects,
              output_filename,
              output_dir=None,
              libraries=None,
              library_dirs=None,
              runtime_library_dirs=None,
              export_symbols=None,
              debug=0,
              extra_preargs=None,
              extra_postargs=None,
              build_temp=None):
        
        # use separate copies, so we can modify the lists
        extra_preargs = copy.copy(extra_preargs or [])
        libraries = copy.copy(libraries or [])
        objects = copy.copy(objects or [])
                
        # Additional libraries
        libraries.extend(self.dll_libraries)

        # handle export symbols by creating a def-file
        # with executables this only works with gcc/ld as linker
        if ((export_symbols is not None) and
            (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
            # (The linker doesn't do anything if output is up-to-date.
            # So it would probably better to check if we really need this,
            # but for this we had to insert some unchanged parts of 
            # UnixCCompiler, and this is not what we want.) 

            # we want to put some files in the same directory as the 
            # object files are, build_temp doesn't help much
            # where are the object files
            temp_dir = os.path.dirname(objects[0])
            # name of dll to give the helper files the same base name
            (dll_name, dll_extension) = os.path.splitext(
                os.path.basename(output_filename))

            # generate the filenames for these files
            def_file = os.path.join(temp_dir, dll_name + ".def")
            exp_file = os.path.join(temp_dir, dll_name + ".exp")
            lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")
       
            # Generate .def file
            contents = [
                "LIBRARY %s" % os.path.basename(output_filename),
                "EXPORTS"]
            for sym in export_symbols:
                contents.append(sym)
            self.execute(write_file, (def_file, contents),
                         "writing %s" % def_file)

            # next add options for def-file and to creating import libraries

            # dllwrap uses different options than gcc/ld
            if self.linker_dll == "dllwrap":
                extra_preargs.extend([#"--output-exp",exp_file,
                                       "--output-lib",lib_file,
                                     ])
                # for dllwrap we have to use a special option
                extra_preargs.extend(["--def", def_file])
            # we use gcc/ld here and can be sure ld is >= 2.9.10
            else:
                # doesn't work: bfd_close build\...\libfoo.a: Invalid operation
                #extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
                # for gcc/ld the def-file is specified as any other object files    
                objects.append(def_file)

        #end: if ((export_symbols is not None) and
        #        (target_desc <> self.EXECUTABLE or self.linker_dll == "gcc")):
                                                 
        # who wants symbols and a many times larger output file
        # should explicitly switch the debug mode on 
        # otherwise we let dllwrap/ld strip the output file
        # (On my machine: 10KB < stripped_file < ??100KB 
        #   unstripped_file = stripped_file + XXX KB
        #  ( XXX=254 for a typical python extension)) 
        if not debug: 
            extra_preargs.append("-s") 
        
        UnixCCompiler.link(self,
                           target_desc,
                           objects,
                           output_filename,
                           output_dir,
                           libraries,
                           library_dirs,
                           runtime_library_dirs,
                           None, # export_symbols, we do this in our def-file
                           debug,
                           extra_preargs,
                           extra_postargs,
                           build_temp)
Example #50
0
"""distutils.cygwinccompiler
Example #51
0
class BuildExtCommand(build_ext):

    def run(self):
        self.run_command('build_yacc')
        self.run_command('build_lex')
        build_ext.run(self)


try:
    static_sepol = os.environ['SEPOL']
except KeyError:
    # try to find libsepol.a. The find_library_file function
    # chooses dynamic libraries over static ones, so
    # this assumes that the static lib is in the same directory
    # as the dynamic lib.
    dynamic_sepol = UnixCCompiler().find_library_file(['/usr/lib64', '/usr/lib'], 'sepol')
    static_sepol = dynamic_sepol.replace(".so", ".a")

ext_py_mods = [Extension('setools.policyrep._qpol',
                         ['setools/policyrep/qpol.i',
                          'libqpol/avrule_query.c',
                          'libqpol/bool_query.c',
                          'libqpol/bounds_query.c',
                          'libqpol/class_perm_query.c',
                          'libqpol/cond_query.c',
                          'libqpol/constraint_query.c',
                          'libqpol/context_query.c',
                          'libqpol/default_object_query.c',
                          'libqpol/expand.c',
                          'libqpol/fs_use_query.c',
                          'libqpol/ftrule_query.c',
Example #52
0
    def link_shared_object(self,
                           objects,
                           output_filename,
                           output_dir=None,
                           libraries=None,
                           library_dirs=None,
                           runtime_library_dirs=None,
                           export_symbols=None,
                           debug=0,
                           extra_preargs=None,
                           extra_postargs=None,
                           build_temp=None):

        # use separate copies, so we can modify the lists
        extra_preargs = copy.copy(extra_preargs or [])
        libraries = copy.copy(libraries or [])

        # Additional libraries
        libraries.extend(self.dll_libraries)

        # we want to put some files in the same directory as the
        # object files are, build_temp doesn't help much

        # where are the object files
        temp_dir = os.path.dirname(objects[0])

        # name of dll to give the helper files (def, lib, exp) the same name
        (dll_name,
         dll_extension) = os.path.splitext(os.path.basename(output_filename))

        # generate the filenames for these files
        def_file = None  # this will be done later, if necessary
        exp_file = os.path.join(temp_dir, dll_name + ".exp")
        lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")

        #extra_preargs.append("--verbose")
        if self.linker == "dllwrap":
            extra_preargs.extend([  #"--output-exp",exp_file,
                "--output-lib",
                lib_file,
            ])
        else:
            # doesn't work: bfd_close build\...\libfoo.a: Invalid operation
            extra_preargs.extend([  #"-Wl,--out-implib,%s" % lib_file,
            ])

        #  check what we got in export_symbols
        if export_symbols is not None:
            # Make .def file
            # (It would probably better to check if we really need this,
            # but for this we had to insert some unchanged parts of
            # UnixCCompiler, and this is not what we want.)
            def_file = os.path.join(temp_dir, dll_name + ".def")
            contents = [
                "LIBRARY %s" % os.path.basename(output_filename), "EXPORTS"
            ]
            for sym in export_symbols:
                contents.append(sym)
            self.execute(write_file, (def_file, contents),
                         "writing %s" % def_file)

        if def_file:
            if self.linker == "dllwrap":
                # for dllwrap we have to use a special option
                extra_preargs.append("--def")
            # for gcc/ld it is specified as any other object file
            extra_preargs.append(def_file)

        # who wants symbols and a many times larger output file
        # should explicitly switch the debug mode on
        # otherwise we let dllwrap/ld strip the output file
        # (On my machine unstripped_file = stripped_file + 254KB
        #   10KB < stripped_file < ??100KB )
        if not debug:
            extra_preargs.append("-s")

        UnixCCompiler.link_shared_object(
            self,
            objects,
            output_filename,
            output_dir,
            libraries,
            library_dirs,
            runtime_library_dirs,
            None,  # export_symbols, we do this in our def-file
            debug,
            extra_preargs,
            extra_postargs,
            build_temp)
    def link(self,
             target_desc,
             objects,
             output_filename,
             output_dir=None,
             libraries=None,
             library_dirs=None,
             runtime_library_dirs=None,
             export_symbols=None,
             debug=0,
             extra_preargs=None,
             extra_postargs=None,
             build_temp=None,
             target_lang=None):

        # use separate copies, so we can modify the lists
        extra_preargs = copy.copy(extra_preargs or [])
        libraries = copy.copy(libraries or [])
        objects = copy.copy(objects or [])

        # Additional libraries
        libraries.extend(self.dll_libraries)

        # handle export symbols by creating a def-file
        # with executables this only works with gcc/ld as linker
        if ((export_symbols is not None) and
            (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
            # (The linker doesn't do anything if output is up-to-date.
            # So it would probably better to check if we really need this,
            # but for this we had to insert some unchanged parts of
            # UnixCCompiler, and this is not what we want.)

            # we want to put some files in the same directory as the
            # object files are, build_temp doesn't help much
            # where are the object files
            temp_dir = os.path.dirname(objects[0])
            # name of dll to give the helper files the same base name
            (dll_name, dll_extension) = os.path.splitext(
                os.path.basename(output_filename))

            # generate the filenames for these files
            def_file = os.path.join(temp_dir, dll_name + ".def")
            lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")

            # Generate .def file
            contents = [
                "LIBRARY %s" % os.path.basename(output_filename), "EXPORTS"
            ]
            for sym in export_symbols:
                contents.append(sym)
            self.execute(write_file, (def_file, contents),
                         "writing %s" % def_file)

            # next add options for def-file and to creating import libraries

            # dllwrap uses different options than gcc/ld
            if self.linker_dll == "dllwrap":
                extra_preargs.extend(["--output-lib", lib_file])
                # for dllwrap we have to use a special option
                extra_preargs.extend(["--def", def_file])
            # we use gcc/ld here and can be sure ld is >= 2.9.10
            else:
                # doesn't work: bfd_close build\...\libfoo.a: Invalid operation
                #extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
                # for gcc/ld the def-file is specified as any object files
                objects.append(def_file)

        #end: if ((export_symbols is not None) and
        #        (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):

        # who wants symbols and a many times larger output file
        # should explicitly switch the debug mode on
        # otherwise we let dllwrap/ld strip the output file
        # (On my machine: 10KB < stripped_file < ??100KB
        #   unstripped_file = stripped_file + XXX KB
        #  ( XXX=254 for a typical python extension))
        if not debug:
            extra_preargs.append("-s")

        UnixCCompiler.link(
            self,
            target_desc,
            objects,
            output_filename,
            output_dir,
            libraries,
            library_dirs,
            runtime_library_dirs,
            None,  # export_symbols, we do this in our def-file
            debug,
            extra_preargs,
            extra_postargs,
            build_temp,
            target_lang)
Example #54
0
File: cross.py Project: eraldop/ae
class cross_build_ext(build_ext):
    user_options = build_ext.user_options + [
        ('cross-dir=', None,
         "Python headers and libraries for cross compilation"),
        ('cross-ver=', None,
         "version for cross compilation"),
        ('cross-compiler=', None,
         "compiler for cross compilation"),
    ]

    def initialize_options(self):
        build_ext.initialize_options(self)
        self.cross_dir = None
        self.cross_ver = None
        self.cross_compiler = None
 
    def finalize_options(self):
        build_ext.finalize_options(self)
        self.set_undefined_options('build',
                ('cross_dir', 'cross_dir'),
                ('cross_ver', 'cross_ver'),
                ('cross_compiler', 'cross_compiler'),
        )

        if self.cross_compiler is None:
            self.cross_compiler = { "win32": "i686-w64-mingw32-gcc",
                                    "win-amd64": "x86_64-w64-mingw32-gcc" }.get(self.plat_name)

    def run(self):
        if not self.extensions:
            return

        if self.distribution.has_c_libraries():
            build_clib = self.get_finalized_command('build_clib')
            self.libraries.extend(build_clib.get_library_names() or [])
            self.library_dirs.append(build_clib.build_clib)

        from distutils.unixccompiler import UnixCCompiler

        self.compiler = UnixCCompiler(verbose=self.verbose,
                                      dry_run=self.dry_run,
                                      force=self.force)
        
        self.compiler.shared_lib_extension = ".pyd" # not used :(

        if self.libraries is not None:
            self.compiler.set_libraries(self.libraries)

        if self.library_dirs is not None:
            self.compiler.set_library_dirs(self.library_dirs)

       
        python_lib = "python"+self.cross_ver.replace(".","")

        import os.path, subprocess
        if not os.path.exists( os.path.join(self.cross_dir, python_lib+".def") ):
            log.info("making def for %s in %s", python_lib, self.cross_dir)
            subprocess.check_call(["gendef", python_lib+".dll"], cwd=self.cross_dir)
       
        python_lib_fname = self.compiler.static_lib_format % (python_lib, self.compiler.static_lib_extension )
        if not os.path.exists( os.path.join(self.cross_dir, python_lib_fname) ):
            log.info("making link library %s for %s in %s", python_lib_fname, python_lib, self.cross_dir)
            print self.cross_compiler.replace("gcc","dlltool")
            subprocess.check_call([self.cross_compiler.replace("gcc","dlltool"), 
                "--dllname", python_lib+".dll",
                "--def", python_lib+".def", 
                "--output-lib", python_lib_fname], cwd=self.cross_dir)

        specs_fname = os.path.join(self.cross_dir, "compiler.specs")
        if not os.path.exists(specs_fname):
            log.info("making compiler specs %s", specs_fname)
            msvcr = msvct_table.get(self.cross_ver)
            newspecs = make_specs(self.cross_compiler, msvcr, int(msvcr[-2:]))
            fh = open(specs_fname, "w")
            fh.write(newspecs)
            fh.close()

        self.compiler.set_executables(
            compiler_so="{} -specs={}".format(self.cross_compiler, specs_fname),
            linker_so="{} -specs={} -static-libgcc -shared".format(self.cross_compiler, specs_fname),
        )


        if "win-amd64" == self.plat_name:
            self.compiler.define_macro("MS_WIN64")
        
        self.compiler.add_library(python_lib)
        self.compiler.add_library_dir(self.cross_dir)
        self.compiler.add_include_dir(os.path.join(self.cross_dir, 'include'))

        # Now actually compile and link everything.
        self.build_extensions()

    def get_ext_filename(self, ext_name):
        return build_ext.get_ext_filename(self, ext_name).replace(".so",".pyd")
    def link (self,
              target_desc,
              objects,
              output_filename,
              output_dir=None,
              libraries=None,
              library_dirs=None,
              runtime_library_dirs=None,
              export_symbols=None,
              debug=0,
              extra_preargs=None,
              extra_postargs=None,
              build_temp=None,
              target_lang=None):

        # use separate copies, so we can modify the lists
        extra_preargs = copy.copy(extra_preargs or [])
        libraries = copy.copy(libraries or [])
        objects = copy.copy(objects or [])

        # Additional libraries
        libraries.extend(self.dll_libraries)

        # handle export symbols by creating a def-file
        # with executables this only works with gcc/ld as linker
        if ((export_symbols is not None) and
            (target_desc != self.EXECUTABLE)):
            # (The linker doesn't do anything if output is up-to-date.
            # So it would probably better to check if we really need this,
            # but for this we had to insert some unchanged parts of
            # UnixCCompiler, and this is not what we want.)

            # we want to put some files in the same directory as the
            # object files are, build_temp doesn't help much
            # where are the object files
            temp_dir = os.path.dirname(objects[0])
            # name of dll to give the helper files the same base name
            (dll_name, dll_extension) = os.path.splitext(
                os.path.basename(output_filename))

            # generate the filenames for these files
            def_file = os.path.join(temp_dir, dll_name + ".def")

            # Generate .def file
            contents = [
                "LIBRARY %s INITINSTANCE TERMINSTANCE" % \
                os.path.splitext(os.path.basename(output_filename))[0],
                "DATA MULTIPLE NONSHARED",
                "EXPORTS"]
            for sym in export_symbols:
                contents.append('  "%s"' % sym)
            self.execute(write_file, (def_file, contents),
                         "writing %s" % def_file)

            # next add options for def-file and to creating import libraries
            # for gcc/ld the def-file is specified as any other object files
            objects.append(def_file)

        #end: if ((export_symbols is not None) and
        #        (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):

        # who wants symbols and a many times larger output file
        # should explicitly switch the debug mode on
        # otherwise we let dllwrap/ld strip the output file
        # (On my machine: 10KB < stripped_file < ??100KB
        #   unstripped_file = stripped_file + XXX KB
        #  ( XXX=254 for a typical python extension))
        if not debug:
            extra_preargs.append("-s")

        UnixCCompiler.link(self,
                           target_desc,
                           objects,
                           output_filename,
                           output_dir,
                           libraries,
                           library_dirs,
                           runtime_library_dirs,
                           None, # export_symbols, we do this in our def-file
                           debug,
                           extra_preargs,
                           extra_postargs,
                           build_temp,
                           target_lang)
Example #56
0
def get_flann_lib():
    '''
    Gets the location of the flann library that users should link against.
    '''
    # Would make sense to have setup.py write out a file containing the location
    # it found (like what CMake does), but that doesn't work with Anaconda envs.
    global _flann_lib
    if _flann_lib is not None:
        return _flann_lib

    import os
    import re
    from subprocess import check_output
    import sys

    so_name = index.__file__

    if sys.platform == 'darwin':
        # this is gross. it'd be better to not have to do all this.
        out = check_output(['otool', '-L', so_name]).decode().splitlines()
        assert out.pop(0) == so_name + ':'
        for line in out:
            assert line[0] == '\t'
            fname = line.split(None, 1)[0]
            if 'libflann' in fname and 'libflann_cpp' not in fname:
                if fname.startswith('@rpath'):
                    o = check_output(['otool', '-l', so_name]).decode()
                    i = o.index('cmd LC_RPATH')
                    lines = o[i:].splitlines()
                    assert lines[0].strip() == 'cmd LC_RPATH'
                    assert re.match(r'cmdsize \d+$', lines[1].strip())
                    m = re.match(r'path (.*) \(offset \d+\)$', lines[2].strip())
                    assert m
                    fname = fname.replace('@rpath', m.group(1))

                fname = fname.replace('@loader_path', os.path.dirname(so_name))
                if '/' not in fname:
                    # relative install_names, dammit
                    # look for it in the standard places...
                    dirs = ['/usr/local/lib', '/usr/lib', '/lib']
                    if 'LIBRARY_PATH' in os.environ:
                        dirs = os.environ['LIBRARY_PATH'].split(':') + dirs

                    from distutils.unixccompiler import UnixCCompiler
                    assert fname.startswith('lib')
                    assert fname.endswith('.dylib')
                    basename = fname[len('lib'):-len('.dylib')]
                    fname = UnixCCompiler().find_library_file(dirs, basename)
                    if fname is None:
                        msg = "Can't find library file lib{}.dylib"
                        raise ValueError(msg.format(basename))
                assert fname.startswith('/')
                _flann_lib = os.path.abspath(fname)
                return _flann_lib
    elif sys.platform.startswith('linux'):
        out = check_output(['ldd', so_name]).decode().splitlines()
        for line in out:
            match = _ldd_re.match(line)
            if not match:
                import warnings
                warnings.warn("Confused by ldd output line: {}".format(line))
                continue
            shortname, path = match.groups()
            if 'libflann' in shortname and 'libflann_cpp' not in shortname:
                if path:
                    _flann_lib = os.path.abspath(path)
                    return _flann_lib
    else:
        raise OSError("get_flann_lib doesn't know how to handle this OS")