Skip to content

Instantly share code, notes, and snippets.

@vimalthilak
Forked from BennettSmith/.gitignore
Last active August 29, 2015 14:17
Show Gist options
  • Save vimalthilak/fe03ee90e1b9cb3e6bf2 to your computer and use it in GitHub Desktop.
Save vimalthilak/fe03ee90e1b9cb3e6bf2 to your computer and use it in GitHub Desktop.

Revisions

  1. @BennettSmith BennettSmith revised this gist Sep 20, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion build-protobuf.sh
    Original file line number Diff line number Diff line change
    @@ -328,7 +328,8 @@ then
    fi
    mv "${PREFIX}" "${PREFIX}-master"
    else
    if [ -d "${PREFIX}-${PROTOBUF_VERSION}"
    if [ -d "${PREFIX}-${PROTOBUF_VERSION}" ]
    then
    rm -rf "${PREFIX}-${PROTOBUF_VERSION}"
    fi
    mv "${PREFIX}" "${PREFIX}-${PROTOBUF_VERSION}"
  2. @BennettSmith BennettSmith revised this gist Sep 20, 2014. 2 changed files with 116 additions and 28 deletions.
    2 changes: 2 additions & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -1 +1,3 @@
    protobuf
    protobuf-2.6.0
    protobuf-master
    142 changes: 114 additions & 28 deletions build-protobuf-2.6.0.sh → build-protobuf.sh
    Original file line number Diff line number Diff line change
    @@ -2,21 +2,10 @@

    echo "$(tput setaf 2)"
    echo "###################################################################"
    echo "# Fetch Google Protobuf from the GitHub repo. We are going to"
    echo "# build the master branch, so this is bleeding edge stuff! ;-)"
    echo "# Preparing to build Google Protobuf"
    echo "###################################################################"
    echo "$(tput sgr0)"

    PROTOBUF_SRC_DIR=/tmp/protobuf
    (
    if [ -d ${PROTOBUF_SRC_DIR} ]
    then
    rm -rf ${PROTOBUF_SRC_DIR}
    fi
    cd `dirname ${PROTOBUF_SRC_DIR}`
    git clone https://github.com/google/protobuf.git
    )

    # The results will be stored relative to the location
    # where you stored this script, **not** relative to
    # the location of the protobuf git repo.
    @@ -27,13 +16,15 @@ then
    fi
    mkdir -p "${PREFIX}/platform"

    ###################################################################
    # Build variables. The stuff in this section controls the outcome
    # of the build process. It selects the iOS SDK version based
    # on how xcrun is currently configured.
    ###################################################################
    # A "YES" value will build the latest code from GitHub on the master branch.
    # A "NO" value will use the 2.6.0 tarball downloaded from googlecode.com.
    USE_GIT_MASTER=NO

    DARWIN=darwin13.4.0
    PROTOBUF_GIT_URL=https://github.com/google/protobuf.git
    PROTOBUF_GIT_DIRNAME=protobuf
    PROTOBUF_VERSION=2.6.0
    PROTOBUF_RELEASE_URL=https://protobuf.googlecode.com/svn/rc/protobuf-${PROTOBUF_VERSION}.tar.gz
    PROTOBUF_RELEASE_DIRNAME=protobuf-${PROTOBUF_VERSION}

    BUILD_MACOSX_X86_64=YES

    @@ -44,6 +35,10 @@ BUILD_IOS_ARMV7=YES
    BUILD_IOS_ARMV7S=YES
    BUILD_IOS_ARM64=YES

    PROTOBUF_SRC_DIR=/tmp/protobuf

    DARWIN=darwin13.4.0

    XCODEDIR=`xcode-select --print-path`
    IOS_SDK_VERSION=`xcrun --sdk iphoneos --show-sdk-version`
    MIN_SDK_VERSION=7.1
    @@ -57,15 +52,95 @@ IPHONEOS_SYSROOT=`xcrun --sdk iphoneos --show-sdk-path`
    IPHONESIMULATOR_PLATFORM=`xcrun --sdk iphonesimulator --show-sdk-platform-path`
    IPHONESIMULATOR_SYSROOT=`xcrun --sdk iphonesimulator --show-sdk-path`

    CC=clang
    CFLAGS="--verbose -DNDEBUG -g -O0 -pipe -fPIC -fcxx-exceptions"
    # Uncomment if you want to see more information about each invocation
    # of clang as the builds proceed.
    # CLANG_VERBOSE="--verbose"

    CC=clang
    CXX=clang
    CXXFLAGS="--verbose ${CFLAGS} -std=c++11 -stdlib=libc++"

    CFLAGS="${CLANG_VERBOSE} -DNDEBUG -g -O0 -pipe -fPIC -fcxx-exceptions"
    CXXFLAGS="${CLANG_VERBOSE} ${CFLAGS} -std=c++11 -stdlib=libc++"

    LDFLAGS="-stdlib=libc++"
    LIBS="-lc++ -lc++abi"

    echo "PREFIX ..................... ${PREFIX}"
    echo "USE_GIT_MASTER ............. ${USE_GIT_MASTER}"
    echo "PROTOBUF_GIT_URL ........... ${PROTOBUF_GIT_URL}"
    echo "PROTOBUF_GIT_DIRNAME ....... ${PROTOBUF_GIT_DIRNAME}"
    echo "PROTOBUF_VERSION ........... ${PROTOBUF_VERSION}"
    echo "PROTOBUF_RELEASE_URL ....... ${PROTOBUF_RELEASE_URL}"
    echo "PROTOBUF_RELEASE_DIRNAME ... ${PROTOBUF_RELEASE_DIRNAME}"
    echo "BUILD_MACOSX_X86_64 ........ ${BUILD_MACOSX_X86_64}"
    echo "BUILD_I386_IOSSIM .......... ${BUILD_I386_IOSSIM}"
    echo "BUILD_X86_64_IOSSIM ........ ${BUILD_X86_64_IOSSIM}"
    echo "BUILD_IOS_ARMV7 ............ ${BUILD_IOS_ARMV7}"
    echo "BUILD_IOS_ARMV7S ........... ${BUILD_IOS_ARMV7S}"
    echo "BUILD_IOS_ARM64 ............ ${BUILD_IOS_ARM64}"
    echo "PROTOBUF_SRC_DIR ........... ${PROTOBUF_SRC_DIR}"
    echo "DARWIN ..................... ${DARWIN}"
    echo "XCODEDIR ................... ${XCODEDIR}"
    echo "IOS_SDK_VERSION ............ ${IOS_SDK_VERSION}"
    echo "MIN_SDK_VERSION ............ ${MIN_SDK_VERSION}"
    echo "MACOSX_PLATFORM ............ ${MACOSX_PLATFORM}"
    echo "MACOSX_SYSROOT ............. ${MACOSX_SYSROOT}"
    echo "IPHONEOS_PLATFORM .......... ${IPHONEOS_PLATFORM}"
    echo "IPHONEOS_SYSROOT ........... ${IPHONEOS_SYSROOT}"
    echo "IPHONESIMULATOR_PLATFORM ... ${IPHONESIMULATOR_PLATFORM}"
    echo "IPHONESIMULATOR_SYSROOT .... ${IPHONESIMULATOR_SYSROOT}"
    echo "CC ......................... ${CC}"
    echo "CFLAGS ..................... ${CFLAGS}"
    echo "CXX ........................ ${CXX}"
    echo "CXXFLAGS ................... ${CXXFLAGS}"
    echo "LDFLAGS .................... ${LDFLAGS}"
    echo "LIBS ....................... ${LIBS}"

    while true; do
    read -p "Proceed with build? (y/n) " yn
    case $yn in
    [Yy]* ) break;;
    [Nn]* ) exit;;
    * ) echo "Please answer yes or no.";;
    esac
    done

    echo "$(tput setaf 2)"
    echo "###################################################################"
    echo "# Fetch Google Protobuf"
    echo "###################################################################"
    echo "$(tput sgr0)"

    (
    if [ -d ${PROTOBUF_SRC_DIR} ]
    then
    rm -rf ${PROTOBUF_SRC_DIR}
    fi

    cd `dirname ${PROTOBUF_SRC_DIR}`

    if [ "${USE_GIT_MASTER}" == "YES" ]
    then
    git clone ${PROTOBUF_GIT_URL}
    else
    if [ -d ${PROTOBUF_RELEASE_DIRNAME} ]
    then
    rm -rf "${PROTOBUF_RELEASE_DIRNAME}"
    fi
    curl --location ${PROTOBUF_RELEASE_URL} --output ${PROTOBUF_RELEASE_DIRNAME}.tar.gz
    tar xvf ${PROTOBUF_RELEASE_DIRNAME}.tar.gz
    mv "${PROTOBUF_RELEASE_DIRNAME}" "${PROTOBUF_SRC_DIR}"
    rm ${PROTOBUF_RELEASE_DIRNAME}.tar.gz

    # Remove the version of Google Test included with the release.
    # We will replace it with version 1.7.0 in a later step.
    if [ -d "${PROTOBUF_SRC_DIR}/gtest" ]
    then
    rm -r "${PROTOBUF_SRC_DIR}/gtest"
    fi
    fi
    )

    echo "$(tput setaf 2)"
    echo "###################################################################"
    echo "# Fetch Google Test & Prepare the Configure Script"
    @@ -123,6 +198,7 @@ then
    make distclean
    ./configure --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/x86_64-mac "CC=${CC}" "CFLAGS=${CFLAGS} -arch x86_64" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch x86_64" "LDFLAGS=${LDFLAGS}" "LIBS=${LIBS}"
    make
    make check
    make install
    )
    fi
    @@ -221,7 +297,7 @@ fi

    echo "$(tput setaf 2)"
    echo "###################################################################"
    echo "# Create Universal Libraries"
    echo "# Create Universal Libraries and Finalize the packaging"
    echo "###################################################################"
    echo "$(tput sgr0)"

    @@ -232,12 +308,6 @@ echo "$(tput sgr0)"
    lipo x86_64-sim/lib/libprotobuf-lite.a i386-sim/lib/libprotobuf-lite.a arm64-ios/lib/libprotobuf-lite.a armv7s-ios/lib/libprotobuf-lite.a armv7-ios/lib/libprotobuf-lite.a -create -output universal/libprotobuf-lite.a
    )

    echo "$(tput setaf 2)"
    echo "###################################################################"
    echo "# Finalize the packaging"
    echo "###################################################################"
    echo "$(tput setaf 2)"

    (
    cd ${PREFIX}
    mkdir bin
    @@ -246,7 +316,23 @@ echo "$(tput setaf 2)"
    cp -r platform/x86_64-mac/lib/* lib
    cp -r platform/universal/* lib
    rm -rf platform
    lipo -info lib/libprotobuf.a
    lipo -info lib/libprotobuf-lite.a
    )

    if [ "${USE_GIT_MASTER}" == "YES" ]
    then
    if [ -d "${PREFIX}-master" ]
    then
    rm -rf "${PREFIX}-master"
    fi
    mv "${PREFIX}" "${PREFIX}-master"
    else
    if [ -d "${PREFIX}-${PROTOBUF_VERSION}"
    rm -rf "${PREFIX}-${PROTOBUF_VERSION}"
    fi
    mv "${PREFIX}" "${PREFIX}-${PROTOBUF_VERSION}"
    fi

    echo Done!

  3. @BennettSmith BennettSmith revised this gist Sep 20, 2014. 3 changed files with 148 additions and 62 deletions.
    1 change: 1 addition & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    protobuf
    49 changes: 48 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1 +1,48 @@
    The script in this gist can be used to create a universal binary containing the 2.6.0 version of Google Protobuf.
    # Google Protobuf 2.6.0 - Mac OS X and iOS Support

    The script in this gist will help you buid the Google Protobuf library for use
    with Mac OS X and iOS. Other methods (such as homebrew or direct compilation)
    have issues that prevent their use. The libraries built by this script are
    universal and support all iOS device architectures including the simluator.

    # Get the Script

    The easiest way to use this script is to simply clone the gist onto your
    machine using the following command:

    ```
    $ git clone https://gist.github.com/9487468ae3375d0db0cc.git build-protobuf
    ```

    # Performing the Build

    The script will automatically download the tarball from Google Code, so
    all you need to do is run the script.

    ```
    $ cd build-protobuf
    $ ./build-protobuf-2.6.0.sh
    ```

    # Results

    Build results are found in a folder called `protobuf`. This folder contains
    `bin`, `include` and `lib` folders.

    # Integration with Xcode

    Create a build rule in your Xcode project with the following settings.

    Process *Source files with names matching:* `*.proto`
    Using *Custom script:*

    cd ${INPUT_FILE_DIR}
    ${SRCROOT}/Google/protobuf/bin/protoc --proto_path=${INPUT_FILE_DIR} ${INPUT_FILE_PATH} --cpp_out=${DERIVED_FILE_DIR}

    Output Files
    $(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).pb.cc
    $(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).pb.h

    Depending on where you choose to install the protobuf build, you will
    need to adjust the path to `protoc`.

    160 changes: 99 additions & 61 deletions build-protobuf-2.6.0.sh
    100644 → 100755
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    #!/bin/bash

    ###################################################################
    # Fetch Google Protobuf from the GitHub repo. We are going to
    # build the master branch, so this is bleeding edge stuff! ;-)
    ###################################################################
    echo "$(tput setaf 2)"
    echo "###################################################################"
    echo "# Fetch Google Protobuf from the GitHub repo. We are going to"
    echo "# build the master branch, so this is bleeding edge stuff! ;-)"
    echo "###################################################################"
    echo "$(tput sgr0)"

    PROTOBUF_SRC_DIR=/tmp/protobuf
    (
    @@ -33,11 +35,14 @@ mkdir -p "${PREFIX}/platform"

    DARWIN=darwin13.4.0

    BUILD_MAXOSX_X86_64=YES
    BUILD_I386_IOS=YES
    BUILD_MACOSX_X86_64=YES

    BUILD_I386_IOSSIM=YES
    BUILD_X86_64_IOSSIM=YES

    BUILD_IOS_ARMV7=YES
    BUILD_IOS_ARMV7S=YES
    BUILD_IOS_ARMV64=YES
    BUILD_IOS_ARM64=YES

    XCODEDIR=`xcode-select --print-path`
    IOS_SDK_VERSION=`xcrun --sdk iphoneos --show-sdk-version`
    @@ -61,33 +66,42 @@ CXXFLAGS="--verbose ${CFLAGS} -std=c++11 -stdlib=libc++"
    LDFLAGS="-stdlib=libc++"
    LIBS="-lc++ -lc++abi"

    ###################################################################
    # The following section is lifted from the autogen.sh script that
    # is part of the protobuf source code. It verifies we are in the
    # correct folder and fetches the version if Google Test that is
    # used by for unit tests.
    ###################################################################
    echo "$(tput setaf 2)"
    echo "###################################################################"
    echo "# Fetch Google Test & Prepare the Configure Script"
    echo "# (note: This section is lifted from autogen.sh)"
    echo "###################################################################"
    echo "$(tput sgr0)"

    # Check that we're being run from the right directory.
    if test ! -f src/google/protobuf/stubs/common.h; then
    cat >&2 << __EOF__
    (
    cd ${PROTOBUF_SRC_DIR}

    # Check that we're being run from the right directory.
    if test ! -f src/google/protobuf/stubs/common.h
    then
    cat >&2 << __EOF__
    Could not find source code. Make sure you are running this script from the
    root of the distribution tree.
    __EOF__
    exit 1
    fi
    exit 1
    fi

    # Check that gtest is present. Older versions of protobuf were stored in SVN
    # and the gtest directory was setup as an SVN external. Now, protobuf is
    # stored in GitHub and the gtest directory is not included. The commands
    # below will grab the latest version of gtest. Currently that is 1.7.0.
    if test ! -e gtest; then
    echo "Google Test not present. Fetching gtest-1.7.0 from the web..."
    curl --location http://googletest.googlecode.com/files/gtest-1.7.0.zip --output gtest-1.7.0.zip
    unzip gtest-1.7.0.zip
    rm gtest-1.7.0.zip
    mv gtest-1.7.0 gtest
    fi
    # Check that gtest is present. Older versions of protobuf were stored in SVN
    # and the gtest directory was setup as an SVN external. Now, protobuf is
    # stored in GitHub and the gtest directory is not included. The commands
    # below will grab the latest version of gtest. Currently that is 1.7.0.
    if test ! -e gtest
    then
    echo "Google Test not present. Fetching gtest-1.7.0 from the web..."
    curl --location http://googletest.googlecode.com/files/gtest-1.7.0.zip --output gtest-1.7.0.zip
    unzip gtest-1.7.0.zip
    rm gtest-1.7.0.zip
    mv gtest-1.7.0 gtest
    fi

    autoreconf -f -i -Wall,no-obsolete
    rm -rf autom4te.cache config.h.in~
    )

    ###################################################################
    # This section contains the build commands to create the native
    @@ -96,116 +110,140 @@ fi
    # susequent iOS builds.
    ###################################################################

    echo "$(tput setaf 2)"
    echo "###################################################################"
    echo "# x86_64 for Mac OS X"
    echo "###################################################################"
    echo "$(tput sgr0)"

    if [ "${BUILD_MACOSX_X86_64}" == "YES" ]
    then
    (
    cd ${PROTOBUF_SRC_DIR}
    make distclean
    ./configure --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/x86_64 "CC=${CC}" "CFLAGS=${CFLAGS} -arch x86_64" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch x86_64" "LDFLAGS=${LDFLAGS}" "LIBS=${LIBS}"
    ./configure --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/x86_64-mac "CC=${CC}" "CFLAGS=${CFLAGS} -arch x86_64" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch x86_64" "LDFLAGS=${LDFLAGS}" "LIBS=${LIBS}"
    make
    make install
    )
    fi

    PROTOC=${PREFIX}/platform/x86_64-mac/bin/protoc

    ###################################################################
    # This section contains the build commands for each of the
    # architectures that will be included in the universal binaries.
    ###################################################################

    echo "$(tput setaf 2)"
    echo "###########################"
    echo "# i386 for iPhone Simulator"
    echo "###########################"
    echo "$(tput sgr0)"

    if [ "${BUILD_I386_IOSSIM}" == "YES" ]
    then
    (
    cd ${PROTOBUF_SRC_DIR}
    make distclean
    ./configure --build=x86_64-apple-${DARWIN} --host=i386-apple-${DARWIN} --with-protoc=${PROTOC} --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/i386-sim "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch i386 -isysroot ${IPHONESIMULATOR_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch i386 -isysroot ${IPHONESIMULATOR_SYSROOT}" LDFLAGS="-arch i386 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
    make
    make install
    )
    fi

    echo "$(tput setaf 2)"
    echo "#############################"
    echo "# x86_64 for iPhone Simulator"
    echo "#############################"
    echo "$(tput sgr0)"

    if [ "${BUILD_I386_IOS}" == "YES" ]
    if [ "${BUILD_X86_64_IOSSIM}" == "YES" ]
    then
    (
    cd ${PROTOBUF_SRC_DIR}
    make distclean
    ./configure --build=x86_64-apple-${DARWIN} --host=i386-apple-${DARWIN} --with-protoc=${PREFIX}/platform/x86_64/bin/protoc --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/i386 "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch i386 -isysroot ${IPHONESIMULATOR_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch i386 -isysroot ${IPHONESIMULATOR_SYSROOT}" LDFLAGS="-arch i386 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
    ./configure --build=x86_64-apple-${DARWIN} --host=x86_64-apple-${DARWIN} --with-protoc=${PROTOC} --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/x86_64-sim "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch x86_64 -isysroot ${IPHONESIMULATOR_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch x86_64 -isysroot ${IPHONESIMULATOR_SYSROOT}" LDFLAGS="-arch x86_64 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
    make
    make install
    )
    fi

    echo "$(tput setaf 2)"
    echo "##################"
    echo "# armv7 for iPhone"
    echo "##################"
    echo "$(tput sgr0)"

    if [ "${BUILD_IOS_ARMV7}" == "YES" ]
    then
    (
    cd ${PROTOBUF_SRC_DIR}
    make distclean
    ./configure --build=x86_64-apple-${DARWIN} --host=armv7-apple-${DARWIN} --with-protoc=${PREFIX}/platform/x86_64/bin/protoc --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/armv7 "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch armv7 -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch armv7 -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch armv7 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
    ./configure --build=x86_64-apple-${DARWIN} --host=armv7-apple-${DARWIN} --with-protoc=${PROTOC} --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/armv7-ios "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch armv7 -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch armv7 -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch armv7 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
    make
    make install
    )
    fi

    echo "$(tput setaf 2)"
    echo "###################"
    echo "# armv7s for iPhone"
    echo "###################"
    echo "$(tput sgr0)"

    if [ "${BUILD_IOS_ARMV7S}" == "YES" ]
    then
    (
    cd ${PROTOBUF_SRC_DIR}
    make distclean
    ./configure --build=x86_64-apple-${DARWIN} --host=armv7s-apple-${DARWIN} --with-protoc=${PREFIX}/platform/x86_64/bin/protoc --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/armv7s "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch armv7s -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch armv7s -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch armv7s -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
    ./configure --build=x86_64-apple-${DARWIN} --host=armv7s-apple-${DARWIN} --with-protoc=${PROTOC} --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/armv7s-ios "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch armv7s -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch armv7s -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch armv7s -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
    make
    make install
    )
    fi

    ########################################
    # Patch Protobuf 2.5.0 for 64bit support
    ########################################

    # (
    # cd /tmp/${PROTOBUF_FOLDER}
    # make distclean
    # curl https://gist.github.com/BennettSmith/7111094/raw/171695f70b102de2301f5b45d9e9ab3167b4a0e8/0001-Add-generic-GCC-support-for-atomic-operations.patch --output /tmp/0001-Add-generic-GCC-support-for-atomic-operations.patch
    # curl https://gist.github.com/BennettSmith/7111094/raw/a4e85ffc82af00ae7984020300db51a62110db48/0001-Add-generic-gcc-header-to-Makefile.am.patch --output /tmp/0001-Add-generic-gcc-header-to-Makefile.am.patch
    # patch -p1 < /tmp/0001-Add-generic-GCC-support-for-atomic-operations.patch
    # patch -p1 < /tmp/0001-Add-generic-gcc-header-to-Makefile.am.patch
    # rm /tmp/0001-Add-generic-GCC-support-for-atomic-operations.patch
    # rm /tmp/0001-Add-generic-gcc-header-to-Makefile.am.patch
    # )

    echo "$(tput setaf 2)"
    echo "##################"
    echo "# arm64 for iPhone"
    echo "##################"
    echo "$(tput sgr0)"

    if [ "${BUILD_IOS_ARMV64}" == "YES" ]
    if [ "${BUILD_IOS_ARM64}" == "YES" ]
    then
    (
    ./configure --build=x86_64-apple-${DARWIN} --host=arm --with-protoc=${PREFIX}/platform/x86_64/bin/protoc --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/arm64 "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch arm64 -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch arm64 -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch arm64 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
    cd ${PROTOBUF_SRC_DIR}
    make distclean
    ./configure --build=x86_64-apple-${DARWIN} --host=arm --with-protoc=${PROTOC} --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/arm64-ios "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch arm64 -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch arm64 -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch arm64 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
    make
    make install
    )
    fi

    ###################################################################
    # Create Universal Libraries
    ###################################################################
    echo "$(tput setaf 2)"
    echo "###################################################################"
    echo "# Create Universal Libraries"
    echo "###################################################################"
    echo "$(tput sgr0)"

    (
    cd ${PREFIX}/platform
    mkdir universal
    lipo x86_64/lib/libprotobuf.a arm64/lib/libprotobuf.a armv7s/lib/libprotobuf.a armv7/lib/libprotobuf.a i386/lib/libprotobuf.a -create -output universal/libprotobuf.a
    lipo x86_64/lib/libprotobuf-lite.a arm64/lib/libprotobuf-lite.a armv7s/lib/libprotobuf-lite.a armv7/lib/libprotobuf-lite.a i386/lib/libprotobuf-lite.a -create -output universal/libprotobuf-lite.a
    lipo x86_64-sim/lib/libprotobuf.a i386-sim/lib/libprotobuf.a arm64-ios/lib/libprotobuf.a armv7s-ios/lib/libprotobuf.a armv7-ios/lib/libprotobuf.a -create -output universal/libprotobuf.a
    lipo x86_64-sim/lib/libprotobuf-lite.a i386-sim/lib/libprotobuf-lite.a arm64-ios/lib/libprotobuf-lite.a armv7s-ios/lib/libprotobuf-lite.a armv7-ios/lib/libprotobuf-lite.a -create -output universal/libprotobuf-lite.a
    )

    ###################################################################
    # Finalize the packaging
    ###################################################################
    echo "$(tput setaf 2)"
    echo "###################################################################"
    echo "# Finalize the packaging"
    echo "###################################################################"
    echo "$(tput setaf 2)"

    (
    cd ${PREFIX}
    mkdir bin
    mkdir lib
    cp -r platform/x86_64/bin/protoc bin
    cp -r platform/x86_64/lib/* lib
    cp -r platform/x86_64-mac/bin/protoc bin
    cp -r platform/x86_64-mac/lib/* lib
    cp -r platform/universal/* lib
    rm -rf platform
    )
  4. @BennettSmith BennettSmith revised this gist Sep 20, 2014. 1 changed file with 214 additions and 0 deletions.
    214 changes: 214 additions & 0 deletions build-protobuf-2.6.0.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,214 @@
    #!/bin/bash

    ###################################################################
    # Fetch Google Protobuf from the GitHub repo. We are going to
    # build the master branch, so this is bleeding edge stuff! ;-)
    ###################################################################

    PROTOBUF_SRC_DIR=/tmp/protobuf
    (
    if [ -d ${PROTOBUF_SRC_DIR} ]
    then
    rm -rf ${PROTOBUF_SRC_DIR}
    fi
    cd `dirname ${PROTOBUF_SRC_DIR}`
    git clone https://github.com/google/protobuf.git
    )

    # The results will be stored relative to the location
    # where you stored this script, **not** relative to
    # the location of the protobuf git repo.
    PREFIX=`pwd`/protobuf
    if [ -d ${PREFIX} ]
    then
    rm -rf "${PREFIX}"
    fi
    mkdir -p "${PREFIX}/platform"

    ###################################################################
    # Build variables. The stuff in this section controls the outcome
    # of the build process. It selects the iOS SDK version based
    # on how xcrun is currently configured.
    ###################################################################

    DARWIN=darwin13.4.0

    BUILD_MAXOSX_X86_64=YES
    BUILD_I386_IOS=YES
    BUILD_IOS_ARMV7=YES
    BUILD_IOS_ARMV7S=YES
    BUILD_IOS_ARMV64=YES

    XCODEDIR=`xcode-select --print-path`
    IOS_SDK_VERSION=`xcrun --sdk iphoneos --show-sdk-version`
    MIN_SDK_VERSION=7.1

    MACOSX_PLATFORM=${XCODEDIR}/Platforms/MacOSX.platform
    MACOSX_SYSROOT=${MACOSX_PLATFORM}/Developer/MacOSX10.9.sdk

    IPHONEOS_PLATFORM=`xcrun --sdk iphoneos --show-sdk-platform-path`
    IPHONEOS_SYSROOT=`xcrun --sdk iphoneos --show-sdk-path`

    IPHONESIMULATOR_PLATFORM=`xcrun --sdk iphonesimulator --show-sdk-platform-path`
    IPHONESIMULATOR_SYSROOT=`xcrun --sdk iphonesimulator --show-sdk-path`

    CC=clang
    CFLAGS="--verbose -DNDEBUG -g -O0 -pipe -fPIC -fcxx-exceptions"

    CXX=clang
    CXXFLAGS="--verbose ${CFLAGS} -std=c++11 -stdlib=libc++"

    LDFLAGS="-stdlib=libc++"
    LIBS="-lc++ -lc++abi"

    ###################################################################
    # The following section is lifted from the autogen.sh script that
    # is part of the protobuf source code. It verifies we are in the
    # correct folder and fetches the version if Google Test that is
    # used by for unit tests.
    ###################################################################

    # Check that we're being run from the right directory.
    if test ! -f src/google/protobuf/stubs/common.h; then
    cat >&2 << __EOF__
    Could not find source code. Make sure you are running this script from the
    root of the distribution tree.
    __EOF__
    exit 1
    fi

    # Check that gtest is present. Older versions of protobuf were stored in SVN
    # and the gtest directory was setup as an SVN external. Now, protobuf is
    # stored in GitHub and the gtest directory is not included. The commands
    # below will grab the latest version of gtest. Currently that is 1.7.0.
    if test ! -e gtest; then
    echo "Google Test not present. Fetching gtest-1.7.0 from the web..."
    curl --location http://googletest.googlecode.com/files/gtest-1.7.0.zip --output gtest-1.7.0.zip
    unzip gtest-1.7.0.zip
    rm gtest-1.7.0.zip
    mv gtest-1.7.0 gtest
    fi

    ###################################################################
    # This section contains the build commands to create the native
    # protobuf library for Mac OS X. This is done first so we have
    # a copy of the protoc compiler. It will be used in all of the
    # susequent iOS builds.
    ###################################################################

    echo "###################################################################"
    echo "# x86_64 for Mac OS X"
    echo "###################################################################"

    if [ "${BUILD_MACOSX_X86_64}" == "YES" ]
    then
    (
    make distclean
    ./configure --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/x86_64 "CC=${CC}" "CFLAGS=${CFLAGS} -arch x86_64" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch x86_64" "LDFLAGS=${LDFLAGS}" "LIBS=${LIBS}"
    make
    make install
    )
    fi

    ###################################################################
    # This section contains the build commands for each of the
    # architectures that will be included in the universal binaries.
    ###################################################################

    echo "###########################"
    echo "# i386 for iPhone Simulator"
    echo "###########################"

    if [ "${BUILD_I386_IOS}" == "YES" ]
    then
    (
    make distclean
    ./configure --build=x86_64-apple-${DARWIN} --host=i386-apple-${DARWIN} --with-protoc=${PREFIX}/platform/x86_64/bin/protoc --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/i386 "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch i386 -isysroot ${IPHONESIMULATOR_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch i386 -isysroot ${IPHONESIMULATOR_SYSROOT}" LDFLAGS="-arch i386 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
    make
    make install
    )
    fi

    echo "##################"
    echo "# armv7 for iPhone"
    echo "##################"

    if [ "${BUILD_IOS_ARMV7}" == "YES" ]
    then
    (
    make distclean
    ./configure --build=x86_64-apple-${DARWIN} --host=armv7-apple-${DARWIN} --with-protoc=${PREFIX}/platform/x86_64/bin/protoc --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/armv7 "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch armv7 -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch armv7 -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch armv7 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
    make
    make install
    )
    fi

    echo "###################"
    echo "# armv7s for iPhone"
    echo "###################"

    if [ "${BUILD_IOS_ARMV7S}" == "YES" ]
    then
    (
    make distclean
    ./configure --build=x86_64-apple-${DARWIN} --host=armv7s-apple-${DARWIN} --with-protoc=${PREFIX}/platform/x86_64/bin/protoc --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/armv7s "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch armv7s -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch armv7s -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch armv7s -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
    make
    make install
    )
    fi

    ########################################
    # Patch Protobuf 2.5.0 for 64bit support
    ########################################

    # (
    # cd /tmp/${PROTOBUF_FOLDER}
    # make distclean
    # curl https://gist.github.com/BennettSmith/7111094/raw/171695f70b102de2301f5b45d9e9ab3167b4a0e8/0001-Add-generic-GCC-support-for-atomic-operations.patch --output /tmp/0001-Add-generic-GCC-support-for-atomic-operations.patch
    # curl https://gist.github.com/BennettSmith/7111094/raw/a4e85ffc82af00ae7984020300db51a62110db48/0001-Add-generic-gcc-header-to-Makefile.am.patch --output /tmp/0001-Add-generic-gcc-header-to-Makefile.am.patch
    # patch -p1 < /tmp/0001-Add-generic-GCC-support-for-atomic-operations.patch
    # patch -p1 < /tmp/0001-Add-generic-gcc-header-to-Makefile.am.patch
    # rm /tmp/0001-Add-generic-GCC-support-for-atomic-operations.patch
    # rm /tmp/0001-Add-generic-gcc-header-to-Makefile.am.patch
    # )

    echo "##################"
    echo "# arm64 for iPhone"
    echo "##################"

    if [ "${BUILD_IOS_ARMV64}" == "YES" ]
    then
    (
    ./configure --build=x86_64-apple-${DARWIN} --host=arm --with-protoc=${PREFIX}/platform/x86_64/bin/protoc --disable-shared --prefix=${PREFIX} --exec-prefix=${PREFIX}/platform/arm64 "CC=${CC}" "CFLAGS=${CFLAGS} -miphoneos-version-min=${MIN_SDK_VERSION} -arch arm64 -isysroot ${IPHONEOS_SYSROOT}" "CXX=${CXX}" "CXXFLAGS=${CXXFLAGS} -arch arm64 -isysroot ${IPHONEOS_SYSROOT}" LDFLAGS="-arch arm64 -miphoneos-version-min=${MIN_SDK_VERSION} ${LDFLAGS}" "LIBS=${LIBS}"
    make
    make install
    )
    fi

    ###################################################################
    # Create Universal Libraries
    ###################################################################

    (
    cd ${PREFIX}/platform
    mkdir universal
    lipo x86_64/lib/libprotobuf.a arm64/lib/libprotobuf.a armv7s/lib/libprotobuf.a armv7/lib/libprotobuf.a i386/lib/libprotobuf.a -create -output universal/libprotobuf.a
    lipo x86_64/lib/libprotobuf-lite.a arm64/lib/libprotobuf-lite.a armv7s/lib/libprotobuf-lite.a armv7/lib/libprotobuf-lite.a i386/lib/libprotobuf-lite.a -create -output universal/libprotobuf-lite.a
    )

    ###################################################################
    # Finalize the packaging
    ###################################################################

    (
    cd ${PREFIX}
    mkdir bin
    mkdir lib
    cp -r platform/x86_64/bin/protoc bin
    cp -r platform/x86_64/lib/* lib
    cp -r platform/universal/* lib
    rm -rf platform
    )

    echo Done!

  5. @BennettSmith BennettSmith created this gist Sep 20, 2014.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    The script in this gist can be used to create a universal binary containing the 2.6.0 version of Google Protobuf.