|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# Created by James Moore on 3/25/14. |
| 4 | +# Copyright (c) 2014 The Serval Project. All rights reserved. |
| 5 | + |
| 6 | +# set -x |
| 7 | + |
| 8 | +# if we're building inside of xcode we need to back up a level |
| 9 | +if [[ -n $DEVELOPER_DIR ]]; then |
| 10 | + cd .. |
| 11 | + pwd |
| 12 | +fi |
| 13 | + |
| 14 | +# Add the homebrew tools to the path since automake no longer is apart of Xcode |
| 15 | +PATH=/usr/local/bin:$PATH |
| 16 | +ARCHS="armv7 armv7s arm64 i386 x86_64" |
| 17 | +SDK_VERSION=8.0 |
| 18 | +SDK_TARGET=7.1 |
| 19 | +PREFIX=$(pwd)/build |
| 20 | +DEVELOPER=`xcode-select -print-path` |
| 21 | +SYMROOT="build" |
| 22 | + |
| 23 | +command -v autoreconf >/dev/null 2>&1 || { echo "In order to build this library you must have the autoreconf tool installed. It's available via homebrew."; exit 1; } |
| 24 | + |
| 25 | +buildIOS() |
| 26 | +{ |
| 27 | + ARCH=$1 |
| 28 | + HOST="" |
| 29 | + PREFIX="/tmp/servald" |
| 30 | + |
| 31 | + if [[ "${ARCH}" == "i386" ]]; then |
| 32 | + PLATFORM="iPhoneSimulator" |
| 33 | + HOST="--host=i386-apple-darwin" |
| 34 | + elif [[ "${ARCH}" == "x86_64" ]]; then |
| 35 | + PLATFORM="iPhoneSimulator" |
| 36 | + else |
| 37 | + PLATFORM="iPhoneOS" |
| 38 | + HOST="--host=arm-apple-darwin" |
| 39 | + PREFIX="/Library/servald" |
| 40 | + fi |
| 41 | + |
| 42 | + CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer" |
| 43 | + CROSS_SDK="${PLATFORM}${SDK_VERSION}.sdk" |
| 44 | + SDKROOT="${CROSS_TOP}/SDKs/${CROSS_SDK}" |
| 45 | + |
| 46 | + export CFLAGS="-arch ${ARCH} -pipe -no-cpp-precomp -isysroot $SDKROOT -I$SDKROOT/usr/include -miphoneos-version-min=${SDK_TARGET}" |
| 47 | + export CC="clang" |
| 48 | + |
| 49 | + echo "=> Building libserval for ${PLATFORM} ${SDK_TARGET} ${ARCH}" |
| 50 | + |
| 51 | + LOG_PATH="${SYMROOT}/libserval-${ARCH}.log" |
| 52 | + ./configure $HOST --prefix $PREFIX &> "$LOG_PATH" || { echo "configure failed; see $LOG_PATH"; exit 1; } |
| 53 | + |
| 54 | + make libserval.a >> "$LOG_PATH" 2>&1 || { echo "make failed; see $LOG_PATH"; exit 1; } |
| 55 | + cp libserval.a ${SYMROOT}/libserval-${ARCH}.a |
| 56 | + make clean >> "$LOG_PATH" 2>&1 || { echo "make clean failed; see $LOG_PATH"; exit 1; } |
| 57 | + |
| 58 | +} |
| 59 | + |
| 60 | +# |
| 61 | +# Start the build |
| 62 | +# |
| 63 | + |
| 64 | +if [[ $ACTION == "clean" ]]; then |
| 65 | + echo "=> Cleaning..." |
| 66 | + rm ${SYMROOT}/libserval.a 2> /dev/null |
| 67 | + rm -rf ${SYMROOT}/libserval-* 2> /dev/null |
| 68 | + rm -rf ${SYMROOT}/include 2> /dev/null |
| 69 | + exit |
| 70 | +fi |
| 71 | + |
| 72 | +if [[ -f ${SYMROOT}/libserval.a ]]; then |
| 73 | + echo "libserval has already been built...skipping" |
| 74 | + exit |
| 75 | +fi |
| 76 | + |
| 77 | +# Generate configure |
| 78 | +autoreconf -f -i |
| 79 | + |
| 80 | +mkdir -p ${SYMROOT} |
| 81 | + |
| 82 | +for arch in ${ARCHS}; do |
| 83 | + buildIOS "${arch}" |
| 84 | +done |
| 85 | + |
| 86 | +echo "=> Building fat binary" |
| 87 | + |
| 88 | +lipo \ |
| 89 | + "${SYMROOT}/libserval-armv7.a" \ |
| 90 | + "${SYMROOT}/libserval-armv7s.a" \ |
| 91 | + "${SYMROOT}/libserval-arm64.a" \ |
| 92 | + "${SYMROOT}/libserval-i386.a" \ |
| 93 | + "${SYMROOT}/libserval-x86_64.a" \ |
| 94 | + -create -output ${SYMROOT}/libserval.a || { echo "failed building fat library"; exit 1; } |
| 95 | + |
| 96 | +echo "=> Copying Headers" |
| 97 | +mkdir -p ${SYMROOT}/include |
| 98 | +cp *.h ios/confdefs.h ${SYMROOT}/include |
| 99 | + |
| 100 | +echo "=> Done" |
0 commit comments