Generate libffi headers using configure script.
(output_dir, target_arch, os_name, libffi_dir)
| 39 | return False |
| 40 | |
| 41 | def generate_headers(output_dir, target_arch, os_name, libffi_dir): |
| 42 | """Generate libffi headers using configure script.""" |
| 43 | os.makedirs(output_dir, exist_ok=True) |
| 44 | |
| 45 | # Change to libffi directory |
| 46 | original_dir = os.getcwd() |
| 47 | try: |
| 48 | os.chdir(libffi_dir) |
| 49 | |
| 50 | # Create a temporary build directory |
| 51 | build_dir = os.path.join(output_dir, 'build') |
| 52 | os.makedirs(build_dir, exist_ok=True) |
| 53 | |
| 54 | host_triplet = get_host_arch(os_name, target_arch) |
| 55 | |
| 56 | # Run configure script |
| 57 | configure_path = os.path.join(libffi_dir, 'configure') |
| 58 | configure_cmd = [ |
| 59 | configure_path, |
| 60 | f'--host={host_triplet}', |
| 61 | f'--prefix={build_dir}', |
| 62 | '--disable-shared', |
| 63 | '--enable-static', |
| 64 | ] |
| 65 | |
| 66 | print(f"Running configure with: {' '.join(configure_cmd)}") |
| 67 | |
| 68 | if not run_command(configure_cmd): |
| 69 | return False |
| 70 | |
| 71 | # Copy generated headers to output directory |
| 72 | header_files = ['fficonfig.h', 'ffitarget.h', 'include/ffi.h'] |
| 73 | |
| 74 | for header in header_files: |
| 75 | src_path = os.path.join(libffi_dir, header) |
| 76 | dst_path = os.path.join(output_dir, os.path.basename(header)) |
| 77 | |
| 78 | if os.path.exists(src_path): |
| 79 | with open(src_path, 'r') as src: |
| 80 | with open(dst_path, 'w') as dst: |
| 81 | dst.write(src.read()) |
| 82 | print(f"Generated: {dst_path}") |
| 83 | else: |
| 84 | print(f"Warning: {src_path} not found", file=sys.stderr) |
| 85 | |
| 86 | return True |
| 87 | |
| 88 | finally: |
| 89 | os.chdir(original_dir) |
| 90 | |
| 91 | def main(): |
| 92 | parser = argparse.ArgumentParser(description='Generate libffi headers') |
no test coverage detected