Created
November 30, 2015 09:00
-
-
Save nvh/9b8c60b41df7c665c900 to your computer and use it in GitHub Desktop.
A build script for building a tvOS version for libevent
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 | |
# Builds libevent for tvOS targets: | |
# AppleTVSimulator-x86_64, AppleTVOS-arm64. | |
# | |
# Copyright 2015 Niels van Hoorn <nvh@nvh.io> | |
# | |
# Based on work by Mike Tigas | |
# Copyright 2012 Mike Tigas <mike@tig.as> | |
# | |
# Based on work by Felix Schulze on 16.12.10. | |
# Copyright 2010 Felix Schulze. All rights reserved. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
########################################################################### | |
# Choose your libevent version and your currently-installed iOS SDK version: | |
# | |
VERSION="2.0.22-stable" | |
USERSDKVERSION="" | |
MINIOSVERSION="9.0" | |
VERIFYGPG=true | |
########################################################################### | |
# | |
# Don't change anything under this line! | |
# | |
########################################################################### | |
# No need to change this since xcode build will only compile in the | |
# necessary bits from the libraries we create | |
ARCHS="x86_64 arm64" | |
DEVELOPER=`xcode-select -print-path` | |
#DEVELOPER="/Applications/Xcode.app/Contents/Developer" | |
# for continuous integration | |
# https://travis-ci.org/mtigas/iOS-OnionBrowser | |
if [ "$1" == "--noverify" ]; then | |
VERIFYGPG=false | |
fi | |
if [ "$2" == "--i386only" ]; then | |
ARCHS="i386" | |
fi | |
if [[ ! -z "$TRAVIS" && $TRAVIS ]]; then | |
# Travis CI highest available version | |
echo "==================== TRAVIS CI ====================" | |
SDKVERSION="9.0" | |
else | |
SDKVERSION="$USERSDKVERSION" | |
fi | |
cd "`dirname \"$0\"`" | |
REPOROOT=$(pwd) | |
# Where we'll end up storing things in the end | |
OUTPUTDIR="${REPOROOT}/dependencies" | |
mkdir -p ${OUTPUTDIR}/include | |
mkdir -p ${OUTPUTDIR}/lib | |
BUILDDIR="${REPOROOT}/build" | |
# where we will keep our sources and build from. | |
SRCDIR="${BUILDDIR}/src" | |
mkdir -p $SRCDIR | |
# where we will store intermediary builds | |
INTERDIR="${BUILDDIR}/built" | |
mkdir -p $INTERDIR | |
######################################## | |
cd $SRCDIR | |
# Exit the script if an error happens | |
set -e | |
if [ ! -e "${SRCDIR}/libevent-${VERSION}.tar.gz" ]; then | |
echo "Downloading libevent-${VERSION}.tar.gz" | |
#curl -LO https://github.com/downloads/libevent/libevent/libevent-${VERSION}.tar.gz | |
curl -LO https://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-${VERSION}.tar.gz | |
fi | |
echo "Using libevent-${VERSION}.tar.gz" | |
# up to you to set up `gpg` and add keys to your keychain | |
# may have to import from link on http://www.wangafu.net/~nickm/ or http://www.citi.umich.edu/u/provos/ | |
if $VERIFYGPG; then | |
if [ ! -e "${SRCDIR}/libevent-${VERSION}.tar.gz.asc" ]; then | |
#curl -LO https://github.com/downloads/libevent/libevent/libevent-${VERSION}.tar.gz.asc | |
curl -LO https://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-${VERSION}.tar.gz.asc | |
fi | |
echo "Using libevent-${VERSION}.tar.gz.asc" | |
if out=$(gpg --status-fd 1 --verify "libevent-${VERSION}.tar.gz.asc" "libevent-${VERSION}.tar.gz" 2>/dev/null) && | |
echo "$out" | grep -qs "^\[GNUPG:\] VALIDSIG"; then | |
echo "$out" | egrep "GOODSIG|VALIDSIG" | |
echo "Verified GPG signature for source..." | |
else | |
echo "$out" >&2 | |
echo "COULD NOT VERIFY PACKAGE SIGNATURE..." | |
exit 1 | |
fi | |
fi | |
tar zxf libevent-${VERSION}.tar.gz -C $SRCDIR | |
cd "${SRCDIR}/libevent-${VERSION}" | |
set +e # don't bail out of bash script if ccache doesn't exist | |
CCACHE=`which ccache` | |
if [ $? == "0" ]; then | |
echo "Building with ccache: $CCACHE" | |
CCACHE="${CCACHE} " | |
else | |
echo "Building without ccache" | |
CCACHE="" | |
fi | |
set -e # back to regular "bail out on error" mode | |
export ORIGINALPATH=$PATH | |
for ARCH in ${ARCHS} | |
do | |
if [ "${ARCH}" == "i386" ] || [ "${ARCH}" == "x86_64" ]; | |
then | |
PLATFORM="AppleTVSimulator" | |
EXTRA_CONFIG="" | |
else | |
PLATFORM="AppleTVOS" | |
EXTRA_CONFIG="--host=arm-apple-darwin14" | |
fi | |
mkdir -p "${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" | |
export PATH="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/:${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/usr/bin/:${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin:${DEVELOPER}/usr/bin:${ORIGINALPATH}" | |
export BUILD_TOOLS="${DEVELOPER}" | |
export CC="${CCACHE}`which gcc` --verbose -fembed-bitcode -arch ${ARCH} -mtvos-version-min=${MINIOSVERSION}" | |
#Remove all mentions of fork() | |
LANG=C sed -i -- 's/opt_nofork = 0/opt_nofork = 1/' "./test/tinytest.c" | |
LANG=C sed -i -- 's/fork()/0/' "./test/tinytest.c" | |
LANG=C sed -i -- 's/fork()/0/' "./test/regress_main.c" | |
LANG=C sed -i -- 's/fork()/0/' "./test/regress_thread.c" | |
# export CC="${CCACHE}`which gcc` -arch ${ARCH} -mtvos-version-min=${MINIOSVERSION}" | |
./configure --disable-shared --enable-static --disable-debug-mode ${EXTRA_CONFIG} \ | |
--prefix="${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" \ | |
LDFLAGS="$LDFLAGS -L${OUTPUTDIR}/lib" \ | |
CFLAGS="$CFLAGS -O2 -I${OUTPUTDIR}/include -isysroot ${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk" \ | |
CPPFLAGS="$CPPFLAGS -I${OUTPUTDIR}/include -isysroot ${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk" | |
# Build the application and install it to the fake SDK intermediary dir | |
# we have set up. Make sure to clean up afterward because we will re-use | |
# this source tree to cross-compile other targets. | |
make -j4 | |
make install | |
make clean | |
done | |
######################################## | |
echo "Build library..." | |
# These are the libs that comprise libevent. `libevent_openssl` and `libevent_pthreads` | |
# may not be compiled if those dependencies aren't available. | |
OUTPUT_LIBS="libevent.a libevent_core.a libevent_extra.a libevent_openssl.a libevent_pthreads.a" | |
for OUTPUT_LIB in ${OUTPUT_LIBS}; do | |
INPUT_LIBS="" | |
for ARCH in ${ARCHS}; do | |
if [ "${ARCH}" == "i386" ] || [ "${ARCH}" == "x86_64" ]; | |
then | |
PLATFORM="AppleTVSimulator" | |
else | |
PLATFORM="AppleTVOS" | |
fi | |
INPUT_ARCH_LIB="${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/lib/${OUTPUT_LIB}" | |
if [ -e $INPUT_ARCH_LIB ]; then | |
INPUT_LIBS="${INPUT_LIBS} ${INPUT_ARCH_LIB}" | |
fi | |
done | |
# Combine the three architectures into a universal library. | |
if [ -n "$INPUT_LIBS" ]; then | |
lipo -create $INPUT_LIBS \ | |
-output "${OUTPUTDIR}/lib/${OUTPUT_LIB}" | |
else | |
echo "$OUTPUT_LIB does not exist, skipping (are the dependencies installed?)" | |
fi | |
done | |
for ARCH in ${ARCHS}; do | |
if [ "${ARCH}" == "i386" ] || [ "${ARCH}" == "x86_64" ]; | |
then | |
PLATFORM="AppleTVSimulator" | |
else | |
PLATFORM="AppleTVOS" | |
fi | |
cp -R ${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/include/* ${OUTPUTDIR}/include/ | |
if [ $? == "0" ]; then | |
# We only need to copy the headers over once. (So break out of forloop | |
# once we get first success.) | |
break | |
fi | |
done | |
#################### | |
echo "Building done." | |
echo "Cleaning up..." | |
rm -fr ${INTERDIR} | |
rm -fr "${SRCDIR}/libevent-${VERSION}" | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment