Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | |
| 3 | export BUILDFORIOS=1 |
Romain Bertozzi | 4384369 | 2016-11-10 11:09:18 -0500 | [diff] [blame] | 4 | export MIN_IOS_VERSION=9.3 |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 5 | IOS_TARGET_PLATFORM=iPhoneSimulator |
| 6 | RELEASE=0 |
| 7 | |
| 8 | while test -n "$1" |
| 9 | do |
| 10 | case "$1" in |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 11 | --platform=*) |
| 12 | IOS_TARGET_PLATFORM="${1#--platform=}" |
| 13 | ;; |
| 14 | --host=*) |
| 15 | HOST="${1#--host=}" |
| 16 | ;; |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 17 | esac |
| 18 | shift |
| 19 | done |
| 20 | |
| 21 | if test -z "$HOST" |
| 22 | then |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 23 | if [ "$IOS_TARGET_PLATFORM" = "all" ] |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 24 | then |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 25 | ARCHS=("arm64" "x86_64") |
| 26 | elif [ "$IOS_TARGET_PLATFORM" = "iPhoneSimulator" ] |
| 27 | then |
| 28 | ARCHS=("x86_64") |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 29 | elif [ "$IOS_TARGET_PLATFORM" = "iPhoneOS" ] |
| 30 | then |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 31 | ARCHS=("arm64") |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 32 | fi |
| 33 | else |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 34 | ARCHS=("${HOST%%-*}") |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 35 | case "$HOST" in |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 36 | aarch64-*) |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 37 | IOS_TARGET_PLATFORM="iPhoneOS" |
| 38 | ARCHS=("arm64") |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 39 | ;; |
| 40 | x86_64-*) |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 41 | IOS_TARGET_PLATFORM="iPhoneSimulator" |
| 42 | ARCHS=("x86_64") |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 43 | ;; |
| 44 | esac |
| 45 | fi |
| 46 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 47 | if [ ! `which gas-preprocessor.pl` ] |
| 48 | then |
| 49 | echo 'gas-preprocessor.pl not found. Trying to install...' |
| 50 | (curl -L https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl \ |
| 51 | -o /usr/local/bin/gas-preprocessor.pl \ |
| 52 | && chmod +x /usr/local/bin/gas-preprocessor.pl) \ |
| 53 | || exit 1 |
| 54 | fi |
| 55 | |
| 56 | IOS_TOP_DIR="$(pwd)" |
| 57 | |
| 58 | if [ -z "$DAEMON_DIR" ]; then |
| 59 | DAEMON_DIR="$(pwd)/../daemon" |
| 60 | echo "DAEMON_DIR not provided trying to find it in $DAEMON_DIR" |
| 61 | fi |
| 62 | if [ ! -d "$DAEMON_DIR" ]; then |
| 63 | echo 'Daemon not found.' |
| 64 | echo 'If you cloned the daemon in a custom location override' \ |
| 65 | 'use DAEMON_DIR to point to it' |
| 66 | echo "You can also use our meta repo which contains both: |
| 67 | https://gerrit-ring.savoirfairelinux.com/#/admin/projects/ring-project" |
| 68 | exit 1 |
| 69 | fi |
| 70 | |
| 71 | if [ -z "$NPROC" ]; then |
| 72 | NPROC=`sysctl -n hw.ncpu || echo -n 1` |
| 73 | fi |
| 74 | |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 75 | export IOS_TARGET_PLATFORM |
| 76 | echo "Building for $IOS_TARGET_PLATFORM for $ARCHS" |
| 77 | |
Edric Milaret | a68931d | 2016-07-05 09:53:18 -0400 | [diff] [blame] | 78 | cd $DAEMON_DIR |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 79 | |
| 80 | for ARCH in "${ARCHS[@]}" |
| 81 | do |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 82 | mkdir -p contrib/native-$ARCH |
| 83 | cd contrib/native-$ARCH |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 84 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 85 | if [ "$ARCH" = "arm64" ] |
| 86 | then |
| 87 | HOST=aarch64-apple-darwin_ios |
| 88 | IOS_TARGET_PLATFORM="iPhoneOS" |
| 89 | else |
| 90 | HOST=$ARCH-apple-darwin_ios |
| 91 | IOS_TARGET_PLATFORM="iPhoneSimulator" |
| 92 | fi |
| 93 | export IOS_TARGET_PLATFORM |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 94 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 95 | SDKROOT=`xcode-select -print-path`/Platforms/${IOS_TARGET_PLATFORM}.platform/Developer/SDKs/${IOS_TARGET_PLATFORM}${SDK_VERSION}.sdk |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 96 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 97 | SDK="`echo "print '${IOS_TARGET_PLATFORM}'.lower()" | python`" |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 98 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 99 | CC="xcrun -sdk $SDK clang" |
| 100 | CXX="xcrun -sdk $SDK clang++" |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 101 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 102 | SDKROOT="$SDKROOT" ../bootstrap --host="$HOST" --disable-libav --enable-ffmpeg |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 103 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 104 | echo "Building contrib" |
| 105 | make fetch |
| 106 | make -j$NPROC || exit 1 |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 107 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 108 | cd ../.. |
| 109 | echo "Building daemon" |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 110 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 111 | CFLAGS="-arch $ARCH -isysroot $SDKROOT" |
| 112 | if [ "$IOS_TARGET_PLATFORM" = "iPhoneOS" ] |
| 113 | then |
| 114 | CFLAGS+=" -miphoneos-version-min=$MIN_IOS_VERSION -fembed-bitcode" |
| 115 | else |
| 116 | CFLAGS+=" -mios-simulator-version-min=$MIN_IOS_VERSION" |
| 117 | fi |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 118 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 119 | if [ "$RELEASE" = "1" ] |
| 120 | then |
| 121 | CFLAGS+=" -O3" |
| 122 | fi |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 123 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 124 | CXXFLAGS="-stdlib=libc++ -std=c++14 $CFLAGS" |
| 125 | LDFLAGS="$CFLAGS" |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 126 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 127 | ./autogen.sh || exit 1 |
| 128 | mkdir -p "build-ios-$ARCH" |
| 129 | cd build-ios-$ARCH |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 130 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 131 | RING_CONF="--host=$HOST \ |
| 132 | --without-dbus \ |
| 133 | --enable-static \ |
| 134 | --disable-shared \ |
| 135 | --prefix=$IOS_TOP_DIR/DEPS/$ARCH" |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 136 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 137 | if [ "$RELEASE" = "0" ] |
| 138 | then |
| 139 | RING_CONF+=" --enable-debug" |
| 140 | fi |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 141 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 142 | $DAEMON_DIR/configure $RING_CONF \ |
| 143 | CC="$CC $CFLAGS" \ |
| 144 | CXX="$CXX $CXXFLAGS" \ |
| 145 | LD="$LD" \ |
| 146 | CFLAGS="$CFLAGS" \ |
| 147 | CXXFLAGS="$CXXFLAGS" \ |
| 148 | LDFLAGS="$LDFLAGS" || exit 1 |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 149 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 150 | # We need to copy this file or else it's just an empty file |
| 151 | rsync -a $DAEMON_DIR/src/buildinfo.cpp ./src/buildinfo.cpp |
| 152 | |
| 153 | make -j$NPROC || exit 1 |
| 154 | make install || exit 1 |
| 155 | |
| 156 | rsync -ar $DAEMON_DIR/contrib/$HOST/lib/*.a $IOS_TOP_DIR/DEPS/$ARCH/lib/ |
| 157 | cd $IOS_TOP_DIR/DEPS/$ARCH/lib/ |
| 158 | for i in *.a ; do mv "$i" "${i/-$HOST.a/.a}" ; done |
| 159 | |
| 160 | cd $DAEMON_DIR |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 161 | done |
| 162 | |
| 163 | cd $IOS_TOP_DIR |
| 164 | |
| 165 | FAT_DIR=$IOS_TOP_DIR/fat |
| 166 | mkdir -p $FAT_DIR |
| 167 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 168 | if ((${#ARCHS[@]} == "2")) |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 169 | then |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 170 | mkdir -p $FAT_DIR/lib |
| 171 | echo "Making fat lib for ${ARCHS[0]} and ${ARCHS[1]}" |
| 172 | LIBFILES=$IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/*.a |
| 173 | for f in $LIBFILES |
| 174 | do |
| 175 | libFile=${f##*/} |
| 176 | echo "Processing $libFile lib..." |
| 177 | #There is only 2 ARCH max... So let's make it simple |
| 178 | lipo -create "$IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/$libFile" \ |
| 179 | "$IOS_TOP_DIR/DEPS/${ARCHS[1]}/lib/$libFile" \ |
| 180 | -output "$FAT_DIR/lib/$libFile" |
| 181 | done |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 182 | else |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 183 | echo "No need for fat lib" |
| 184 | rsync -ar --delete $IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/*.a $FAT_DIR/lib |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 185 | fi |
| 186 | |
| 187 | rsync -ar --delete $IOS_TOP_DIR/DEPS/${ARCHS[0]}/include/* $FAT_DIR/include |