How to build GLib for iOS

Given that you have built libffi and proxy-libintl for iOS, and installed both those to the same PREFIX as this script uses, this will build GLib for you:

#! /bin/bash

export MINVER="5.1" # the minimum supported OS version
export SDKVER="5.1" # SDK version
export PREFIX="$HOME/built-for-ios" # where the library goes

export DEVROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer"
export SDKROOT="${DEVROOT}/SDKs/iPhoneOS${SDKVER}.sdk"
export PKG_CONFIG_LIBDIR="${PREFIX}/lib/pkgconfig:${SDKROOT}/usr/lib/pkgconfig"
export COMMON_FLAGS="-arch armv7 -isysroot ${SDKROOT}"
export CPPFLAGS="-I${PREFIX}/include ${COMMON_FLAGS} -miphoneos-version-min=${MINVER}"
export CFLAGS="${CPPFLAGS}"
export LDFLAGS="-L${PREFIX}/lib ${COMMON_FLAGS} -Wl,-iphoneos_version_min,${MINVER}"
export CC="${DEVROOT}/usr/bin/gcc"
export CXX="${DEVROOT}/usr/bin/g++"
export OBJC="${CC}"
export LD="${CC}"

[ ! -d "${PREFIX}" ] && mkdir -p "${PREFIX}"
./configure --prefix="${PREFIX}" \
--build="x86_64-apple-darwin" \
--host="arm-apple-darwin" \
--enable-static \
--disable-shared \
glib_cv_stack_grows=no \
glib_cv_uscore=no \
ac_cv_func_posix_getgrgid_r=yes \
ac_cv_func_posix_getpwuid_r=yes

Leave a Comment