Skip to content

Instantly share code, notes, and snippets.

@mobileben
Last active October 22, 2021 12:44
Show Gist options
  • Save mobileben/52b3af9714df3fd5a3253854543389d7 to your computer and use it in GitHub Desktop.
Save mobileben/52b3af9714df3fd5a3253854543389d7 to your computer and use it in GitHub Desktop.
Freetype 2 iOS Build Script
#!/bin/bash
#
# Filename: build-freetype-ios.sh
# Author: Benjamin Lee
# Copyright: (c) Copyright 2018 2n Productions
# License: MIT
#
# Copyright (c) 2017-2018 2n Productions
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished
# to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Quick and dirty script to build freetype.
LIBNAME=libfreetype
PLATFORMPATH="/Applications/Xcode.app/Contents/Developer/Platforms"
TOOLSPATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin"
WITHOUT_PACKAGES="--without-zlib --without-png --without-bzip2"
DEPLOYMENT_SDKVERSION="9.3"
pwd=`pwd`
findLatestSDKVersion()
{
sdks=`ls $PLATFORMPATH/$1.platform/Developer/SDKs`
arr=()
for sdk in $sdks
do
arr[${#arr[@]}]=$sdk
done
# Last item will be the current SDK, since it is alpha ordered
count=${#arr[@]}
if [ $count -gt 0 ]; then
sdk=${arr[$count-1]:${#1}}
num=`expr ${#sdk}-4`
SDKVERSION=${sdk:0:$num}
else
SDKVERSION=$DEPLOYMENT_SDKVERSION
fi
}
buildit()
{
target=$1
hosttarget=$1
platform=$2
if [[ $hosttarget == "x86_64" ]]; then
hostarget="i386"
elif [[ $hosttarget == "arm"* ]]; then
hosttarget="arm"
fi
export CC="$(xcrun -sdk iphoneos -find clang)"
export CXX="$(xcrun -sdk iphoneos -find clang++)"
export CPP="$CC -E"
COMMON_CFLAGS="-arch ${target} -isysroot $PLATFORMPATH/$platform.platform/Developer/SDKs/$platform$SDKVERSION.sdk -miphoneos-version-min=$DEPLOYMENT_SDKVERSION -pipe -std=gnu99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -I$PLATFORMDIR/$platform.platform/Developer/SDKs/$platform$SDKVERSION.sdk/usr/include/libxml2"
export CFLAGS="$COMMON_CFLAGS"
export CXXFLAGS="$COMMON_CFLAGS"
export AR=$(xcrun -sdk iphoneos -find ar)
export RANLIB=$(xcrun -sdk iphoneos -find ranlib)
export CPPFLAGS="-arch ${target} -isysroot $PLATFORMPATH/$platform.platform/Developer/SDKs/$platform$SDKVERSION.sdk -miphoneos-version-min=$DEPLOYMENT_SDKVERSION"
export LDFLAGS="-arch ${target} -isysroot $PLATFORMPATH/$platform.platform/Developer/SDKs/$platform$SDKVERSION.sdk"
mkdir -p $pwd/output/$target
./configure --prefix="$pwd/output/$target" --disable-arm-neon --disable-shared --enable-static --host=$hosttarget-apple-darwin $WITHOUT_PACKAGES
make clean
make
make install
}
findLatestSDKVersion iPhoneOS
# It is possible to pass clang multiple architectures, however I'm building once slice at a time
buildit armv7 iPhoneOS
buildit armv7s iPhoneOS
buildit arm64 iPhoneOS
buildit arm64e iPhoneOS
buildit i386 iPhoneSimulator
buildit x86_64 iPhoneSimulator
LIPO=$(xcrun -sdk iphoneos -find lipo)
$LIPO -create $pwd/output/armv7/lib/$LIBNAME.a $pwd/output/armv7s/lib/$LIBNAME.a $pwd/output/arm64/lib/$LIBNAME.a $pwd/output/arm64e/lib/$LIBNAME.a $pwd/output/x86_64/lib/$LIBNAME.a $pwd/output/i386/lib/$LIBNAME.a -output $pwd/output/$LIBNAME.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment