compile-ios.sh 4.45 KB
Newer Older
Guillaume Roguez's avatar
Guillaume Roguez committed
1 2 3
#! /bin/sh

export BUILDFORIOS=1
4
export MIN_IOS_VERSION=9.3
Guillaume Roguez's avatar
Guillaume Roguez committed
5 6 7 8 9 10
IOS_TARGET_PLATFORM=iPhoneSimulator
RELEASE=0

while test -n "$1"
do
  case "$1" in
11 12 13 14 15 16
    --platform=*)
      IOS_TARGET_PLATFORM="${1#--platform=}"
    ;;
    --host=*)
      HOST="${1#--host=}"
    ;;
Guillaume Roguez's avatar
Guillaume Roguez committed
17 18 19 20 21 22
  esac
  shift
done

if test -z "$HOST"
then
23
  if [ "$IOS_TARGET_PLATFORM" = "all" ]
Guillaume Roguez's avatar
Guillaume Roguez committed
24
  then
25 26 27 28
    ARCHS=("arm64" "x86_64")
  elif [ "$IOS_TARGET_PLATFORM" = "iPhoneSimulator" ]
  then
    ARCHS=("x86_64")
Guillaume Roguez's avatar
Guillaume Roguez committed
29 30
  elif [ "$IOS_TARGET_PLATFORM" = "iPhoneOS" ]
  then
31
    ARCHS=("arm64")
Guillaume Roguez's avatar
Guillaume Roguez committed
32 33
  fi
else
34
  ARCHS=("${HOST%%-*}")
Guillaume Roguez's avatar
Guillaume Roguez committed
35 36
  case "$HOST" in
    aarch64-*)
37 38
      IOS_TARGET_PLATFORM="iPhoneOS"
      ARCHS=("arm64")
Guillaume Roguez's avatar
Guillaume Roguez committed
39 40
    ;;
    x86_64-*)
41 42
      IOS_TARGET_PLATFORM="iPhoneSimulator"
      ARCHS=("x86_64")
Guillaume Roguez's avatar
Guillaume Roguez committed
43 44 45 46 47 48
    ;;
  esac
fi

if [ ! `which gas-preprocessor.pl` ]
then
49 50 51 52 53
  echo 'gas-preprocessor.pl not found. Trying to install...'
  (curl -L https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl \
    -o /usr/local/bin/gas-preprocessor.pl \
    && chmod +x /usr/local/bin/gas-preprocessor.pl) \
    || exit 1
Guillaume Roguez's avatar
Guillaume Roguez committed
54 55 56 57
fi

IOS_TOP_DIR="$(pwd)"

Edric Milaret's avatar
Edric Milaret committed
58
if [ -z "$DAEMON_DIR" ]; then
59 60
  DAEMON_DIR="$(pwd)/../daemon"
  echo "DAEMON_DIR not provided trying to find it in $DAEMON_DIR"
Edric Milaret's avatar
Edric Milaret committed
61 62
fi
if [ ! -d "$DAEMON_DIR" ]; then
63 64 65 66 67 68
  echo 'Daemon not found.'
  echo 'If you cloned the daemon in a custom location override' \
       'use DAEMON_DIR to point to it'
  echo "You can also use our meta repo which contains both:
        https://gerrit-ring.savoirfairelinux.com/#/admin/projects/ring-project"
  exit 1
Edric Milaret's avatar
Edric Milaret committed
69 70
fi

71
if [ -z "$NPROC"  ]; then
72
  NPROC=`sysctl -n hw.ncpu || echo -n 1`
73 74
fi

75 76 77
export IOS_TARGET_PLATFORM
echo "Building for $IOS_TARGET_PLATFORM for $ARCHS"

Edric Milaret's avatar
Edric Milaret committed
78
cd $DAEMON_DIR
Guillaume Roguez's avatar
Guillaume Roguez committed
79 80 81

for ARCH in "${ARCHS[@]}"
do
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
  mkdir -p contrib/native-$ARCH
  cd contrib/native-$ARCH

  if [ "$ARCH" = "arm64" ]
  then
    HOST=aarch64-apple-darwin_ios
    IOS_TARGET_PLATFORM="iPhoneOS"
  else
    HOST=$ARCH-apple-darwin_ios
    IOS_TARGET_PLATFORM="iPhoneSimulator"
  fi
  export IOS_TARGET_PLATFORM

  SDKROOT=`xcode-select -print-path`/Platforms/${IOS_TARGET_PLATFORM}.platform/Developer/SDKs/${IOS_TARGET_PLATFORM}${SDK_VERSION}.sdk

  SDK="`echo "print '${IOS_TARGET_PLATFORM}'.lower()" | python`"

  CC="xcrun -sdk $SDK clang"
  CXX="xcrun -sdk $SDK clang++"

  SDKROOT="$SDKROOT" ../bootstrap --host="$HOST" --disable-libav --enable-ffmpeg

  echo "Building contrib"
  make fetch
  make -j$NPROC || exit 1

  cd ../..
  echo "Building daemon"

  CFLAGS="-arch $ARCH -isysroot $SDKROOT"
  if [ "$IOS_TARGET_PLATFORM" = "iPhoneOS" ]
  then
    CFLAGS+=" -miphoneos-version-min=$MIN_IOS_VERSION -fembed-bitcode"
  else
    CFLAGS+=" -mios-simulator-version-min=$MIN_IOS_VERSION"
  fi

  if [ "$RELEASE" = "1" ]
  then
    CFLAGS+=" -O3"
  fi

  CXXFLAGS="-stdlib=libc++ -std=c++14 $CFLAGS"
  LDFLAGS="$CFLAGS"

  ./autogen.sh || exit 1
  mkdir -p "build-ios-$ARCH"
  cd build-ios-$ARCH

  RING_CONF="--host=$HOST \
             --without-dbus \
             --enable-static \
             --disable-shared \
             --prefix=$IOS_TOP_DIR/DEPS/$ARCH"

  if [ "$RELEASE" = "0" ]
  then
    RING_CONF+=" --enable-debug"
  fi

  $DAEMON_DIR/configure $RING_CONF \
                        CC="$CC $CFLAGS" \
                        CXX="$CXX $CXXFLAGS" \
                        LD="$LD" \
                        CFLAGS="$CFLAGS" \
                        CXXFLAGS="$CXXFLAGS" \
                        LDFLAGS="$LDFLAGS" || exit 1

  # We need to copy this file or else it's just an empty file
  rsync -a $DAEMON_DIR/src/buildinfo.cpp ./src/buildinfo.cpp

  make -j$NPROC || exit 1
  make install || exit 1

  rsync -ar $DAEMON_DIR/contrib/$HOST/lib/*.a $IOS_TOP_DIR/DEPS/$ARCH/lib/
  cd $IOS_TOP_DIR/DEPS/$ARCH/lib/
  for i in *.a ; do mv "$i" "${i/-$HOST.a/.a}" ; done

  cd $DAEMON_DIR
Guillaume Roguez's avatar
Guillaume Roguez committed
161 162 163 164 165 166 167
done

cd $IOS_TOP_DIR

FAT_DIR=$IOS_TOP_DIR/fat
mkdir -p $FAT_DIR

168
if ((${#ARCHS[@]} == "2"))
Guillaume Roguez's avatar
Guillaume Roguez committed
169
then
170 171 172 173 174 175 176 177 178 179 180 181
  mkdir -p $FAT_DIR/lib
  echo "Making fat lib for ${ARCHS[0]} and ${ARCHS[1]}"
  LIBFILES=$IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/*.a
  for f in $LIBFILES
  do
    libFile=${f##*/}
    echo "Processing $libFile lib..."
    #There is only 2 ARCH max... So let's make it simple
    lipo -create  "$IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/$libFile"  \
                  "$IOS_TOP_DIR/DEPS/${ARCHS[1]}/lib/$libFile" \
                  -output "$FAT_DIR/lib/$libFile"
  done
Guillaume Roguez's avatar
Guillaume Roguez committed
182
else
183 184
  echo "No need for fat lib"
  rsync -ar --delete $IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/*.a $FAT_DIR/lib
Guillaume Roguez's avatar
Guillaume Roguez committed
185 186 187
fi

rsync -ar --delete $IOS_TOP_DIR/DEPS/${ARCHS[0]}/include/* $FAT_DIR/include