Created
March 4, 2019 07:22
-
-
Save litesync/d7c484ccfd9552d88249ade4ebc69bba to your computer and use it in GitHub Desktop.
Compile libuv for iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PLATFORMPATH="/Applications/Xcode.app/Contents/Developer/Platforms" | |
TOOLSPATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin" | |
export IPHONEOS_DEPLOYMENT_TARGET="8.0" | |
pwd=`pwd` | |
findLatestSDKVersion() | |
{ | |
sdks=`ls $PLATFORMPATH/$1.platform/Developer/SDKs` | |
arr=() | |
for sdk in $sdks | |
do | |
echo $sdk | |
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="8.0" | |
fi | |
} | |
buildit() | |
{ | |
target=$1 | |
hosttarget=$1 | |
platform=$2 | |
if [[ $hosttarget == "x86_64" ]]; then | |
xxhosttarget="i386" | |
elif [[ $hosttarget == "arm64" ]]; then | |
hosttarget="arm" | |
fi | |
echo "" | |
echo "-------------------------------------------------------------------------------" | |
echo " Compiling for $platform on $target" | |
echo "-------------------------------------------------------------------------------" | |
export PLATFORM=$platform | |
export CC="$(xcrun -sdk iphoneos -find clang)" | |
export STRIP="$(xcrun -sdk iphoneos -find strip)" | |
export LD="$(xcrun -sdk iphoneos -find ld)" | |
export CPP="$CC -E" | |
export CFLAGS="-arch ${target} -isysroot $PLATFORMPATH/$platform.platform/Developer/SDKs/$platform$SDKVERSION.sdk -miphoneos-version-min=$SDKMINVERSION" | |
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=$SDKMINVERSION" | |
export LDFLAGS="-arch ${target} -isysroot $PLATFORMPATH/$platform.platform/Developer/SDKs/$platform$SDKVERSION.sdk" | |
./configure --prefix="$pwd/output/$target" --host=$hosttarget-apple-darwin | |
make clean | |
make | |
make install | |
install_name_tool -id libuv.1.dylib $pwd/output/$target/lib/libuv.1.dylib | |
} | |
findLatestSDKVersion iPhoneOS | |
SDKMINVERSION="8.0" | |
buildit armv7 iPhoneOS | |
buildit armv7s iPhoneOS | |
buildit arm64 iPhoneOS | |
buildit i386 iPhoneSimulator | |
buildit x86_64 iPhoneSimulator | |
LIPO=$(xcrun -sdk iphoneos -find lipo) | |
$LIPO -create $pwd/output/armv7/lib/libuv.a $pwd/output/armv7s/lib/libuv.a $pwd/output/arm64/lib/libuv.a $pwd/output/x86_64/lib/libuv.a $pwd/output/i386/lib/libuv.a -output libuv.a | |
$LIPO -create $pwd/output/armv7/lib/libuv.1.dylib $pwd/output/armv7s/lib/libuv.1.dylib $pwd/output/arm64/lib/libuv.1.dylib $pwd/output/x86_64/lib/libuv.1.dylib $pwd/output/i386/lib/libuv.1.dylib -output libuv.1.dylib | |
install_name_tool -id @rpath/libuv.1.dylib libuv.1.dylib | |
echo "done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions
Save this file on the libuv root folder and do:
The script will create 2 fat libraries, one static
libuv.a
and other dynamiclibuv.1.dylib
.Both contain code for
armv7
armv7s
arm64
i386
x86_64