Skip to content

Instantly share code, notes, and snippets.

@automactic
Last active August 16, 2017 21:56
Show Gist options
  • Save automactic/924a95de3cbf568fba419e66fbe08a5b to your computer and use it in GitHub Desktop.
Save automactic/924a95de3cbf568fba419e66fbe08a5b to your computer and use it in GitHub Desktop.
fat_lib.py
import subprocess
import distutils.dir_util
import os
def generate_fat_libs(root: str, archs: [str], output: str):
def get_lib_names(dir: str) -> [str]:
libs = []
for file in os.listdir(dir):
if file.endswith('.dylib') and not os.path.islink(dir + '/' + file):
libs.append(file)
if file.endswith('.a'):
libs.append(file)
return libs
def lipo(root: str, archs: [str], output: str, lib_name: str):
cmd = ['lipo', '-create']
for arch in archs:
cmd.append('{arch}/INSTALL/lib/{lib}'.format(arch=arch, lib=lib_name))
cmd.append('-output')
cmd.append('{output}/INSTALL/lib/{lib}'.format(output=output, lib=lib_name))
subprocess.run(cmd, cwd=root)
def copy_headers(root: str, arch: str, output: str):
source = '{root}/{arch}/INSTALL/include'.format(root=root, arch=arch)
destination = '{root}/{output}/INSTALL/include'.format(root=root, output=output)
distutils.dir_util.copy_tree(source, destination)
if len(archs) < 2:
return
subprocess.run(['mkdir', '-p', '{}/INSTALL/lib'.format(output)], cwd=root)
copy_headers(root, archs[0], output)
libs = get_lib_names('{}/{}/INSTALL/lib'.format(root, archs[0]))
for lib in libs:
lipo(root, archs, output, lib)
generate_fat_libs('/Volumes/Data/Developer/kiwix-build',
['BUILD_iOS_arm64', 'BUILD_iOS_armv7s', 'BUILD_iOS_x86_64'],
'BUILD_iOS_Shared')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment