def link_module(compiler, object_name, shared_name, extra_objects = [], extra_link_flags = [], linker_flag_prefix = None): linker_flags = get_linker_flags(extra_link_flags, linker_flag_prefix) if isinstance(compiler, (list,tuple)): linker_cmd = list(compiler) else: linker_cmd = [compiler] linker_cmd += [object_name] linker_cmd += linker_flags linker_cmd += list(extra_objects) linker_cmd += ['-o', shared_name] env = os.environ.copy() if not windows: env["LD_LIBRARY_PATH"] = python_lib_dir run_cmd(linker_cmd, env = env, label = "Linking")
def link_module( compiler, object_name, shared_name, extra_objects = [], extra_link_flags = [], linker_flag_prefix = None): linker_flags = get_linker_flags(extra_link_flags, linker_flag_prefix) if isinstance(compiler, (list,tuple)): linker_cmd = list(compiler) else: linker_cmd = [compiler] linker_cmd += [object_name] linker_cmd += linker_flags linker_cmd += list(extra_objects) linker_cmd += ['-o', shared_name] env = os.environ.copy() if not windows: env["LD_LIBRARY_PATH"] = python_lib_dir run_cmd(linker_cmd, env = env, label = "Linking")
def compile_with_distutils(extension_name, src_filename, extra_objects = [], extra_compiler_flags = [], extra_link_flags = [], print_commands = False): # copied largely from pyxbuild from distutils.dist import Distribution from distutils.extension import Extension compiler_flags = get_compiler_flags(extra_compiler_flags) # don't need -shared in the flags since the default CC on Mac OS # might specify -bundle instead and the two are mutually exclusive linker_flags = get_linker_flags(extra_link_flags, shared=False) ext = Extension(name=extension_name, sources=[src_filename], include_dirs = include_dirs, extra_objects=extra_objects, extra_compile_args=compiler_flags, extra_link_args=linker_flags) script_args = ['build_ext', '--quiet'] setup_args = {"script_name": None, "script_args": script_args, } dist = Distribution(setup_args) if not dist.ext_modules: dist.ext_modules = [] dist.ext_modules.append(ext) # I have no idea how distutils works or why I have to do any of this config_files = dist.find_config_files() try: config_files.remove('setup.cfg') except ValueError: pass dist.parse_config_files(config_files) dist.parse_command_line() obj_build_ext = dist.get_command_obj("build_ext") dist.run_commands() shared_name = obj_build_ext.get_outputs()[0] return shared_name