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