コード例 #1
0
def build_apron_util():
    apron_util_src = os.path.join("pyapron", "apron_util.c")
    apron_util_obj = os.path.join(ROOT_DIR,
                                  os.path.join("pyapron", "apron_util.o"))
    cc = UnixCCompiler()
    cc.add_include_dir(APRON_DIR)
    cc.add_include_dir(os.path.join(ROOT_DIR, "include"))
    cc.add_library_dir(APRON_LIB_DIR)
    cc.set_libraries(["apron_debug"])
    cc.compile([apron_util_src], extra_preargs=["-fPIC"])
    cc.link_shared_lib([apron_util_obj], "apronutil", output_dir=APRON_LIB_DIR)
コード例 #2
0
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")
コード例 #3
0
ファイル: cross.py プロジェクト: 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")