Skip to content

Instantly share code, notes, and snippets.

@Superbil
Last active May 19, 2017 10:19
Show Gist options
  • Save Superbil/5212127 to your computer and use it in GitHub Desktop.
Save Superbil/5212127 to your computer and use it in GitHub Desktop.
build google protobuf iOS version
export SDKVER="6.1"
configure_for_platform() {
export PLATFORM=$1
export ARCHITECTURE=$2
echo "Platform is $PLATFORM"
if [ "$PLATFORM" == "iPhoneSimulator" ]; then
export ARCH=i686-apple-darwin10
fi
if [ "$PLATFORM" == "iPhoneOS" ]; then
export ARCH=arm-apple-darwin10
fi
export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/$PLATFORM.platform/Developer
export SDKROOT="$DEVROOT/SDKs/$PLATFORM$SDKVER.sdk"
export PKG_CONFIG_PATH="$SDKROOT/usr/lib/pkgconfig:$DEVROOT/usr/lib/pkgconfig"
export AS="xcrun as"
export ASCPP="xcrun as"
export AR="xcrun ar"
export RANLIB="xcrun ranlib"
export CC="xcrun gcc"
export CXX="xcrun g++"
export LD="xcrun ld"
export STRIP="xcrun strip"
export LIBRARY_PATH="$SDKROOT/usr/lib"
export CPPFLAGS=""
export CFLAGS="-arch $ARCHITECTURE -fmessage-length=0 -pipe -fpascal-strings -miphoneos-version-min=4.0 -isysroot=$SDKROOT -I$SDKROOT/usr/include -I$SDKROOT/usr/include/c++/4.2.1/"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-arch $ARCHITECTURE -isysroot='$SDKROOT' -L$SDKROOT/usr/lib/system -L$SDKROOT/usr/lib/"
./configure --host=$ARCH --with-protoc=protoc --enable-static --disable-shared
}
build_target() {
PLATFORM=$1
ARCHITECTURE=$2
SRC_LIB=src/.libs/libprotobuf-lite.a
SRC_LIB_ARCH=ios-build/libprotobuf-lite-$ARCHITECTURE.a
if [ -f $SRC_LIB_ARCH ]; then
return
fi
configure_for_platform $PLATFORM $ARCHITECTURE
make clean
make
cp $SRC_LIB $SRC_LIB_ARCH
}
if [ -z 'which xcrun' ]; then
echo "error: can't find xcrun, must install Xcode Command line tools"
exit 1
fi
# check 'configure' is existed, if no 'configure' need to run 'autogen.sh'
if [ ! -f ./configure ]; then
./autogen.sh
fi
if [ ! -d ios-build ]; then
mkdir ios-build
fi
# build for iPhoneSimulator
build_target iPhoneSimulator i386
# build for iPhoneOS armv7
build_target iPhoneOS armv7
# build for iPhoneOS armv7s
build_target iPhoneOS armv7s
#crate a fat library containing all achitectures in libprotobuf.a
xcrun -sdk iphoneos lipo \
-arch armv7 ios-build/libprotobuf-lite-armv7.a \
-arch armv7s ios-build/libprotobuf-lite-armv7s.a \
-arch i386 ios-build/libprotobuf-lite-i386.a \
-create -output ios-build/libprotobuf.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment