Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | |
| 3 | export BUILDFORIOS=1 |
Kateryna Kostiuk | fd5e6f1 | 2022-08-02 11:24:05 -0400 | [diff] [blame] | 4 | export MIN_IOS_VERSION=14.5 |
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 | ;; |
kkostiuk | 9411e5d | 2021-06-02 17:48:40 -0400 | [diff] [blame] | 17 | --release) |
| 18 | RELEASE=1 |
| 19 | ;; |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 20 | esac |
| 21 | shift |
| 22 | done |
| 23 | |
| 24 | if test -z "$HOST" |
| 25 | then |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 26 | if [ "$IOS_TARGET_PLATFORM" = "all" ] |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 27 | then |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 28 | ARCHS=("arm64" "x86_64") |
| 29 | elif [ "$IOS_TARGET_PLATFORM" = "iPhoneSimulator" ] |
| 30 | then |
| 31 | ARCHS=("x86_64") |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 32 | elif [ "$IOS_TARGET_PLATFORM" = "iPhoneOS" ] |
| 33 | then |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 34 | ARCHS=("arm64") |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 35 | fi |
| 36 | else |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 37 | ARCHS=("${HOST%%-*}") |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 38 | case "$HOST" in |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 39 | aarch64-*) |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 40 | IOS_TARGET_PLATFORM="iPhoneOS" |
| 41 | ARCHS=("arm64") |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 42 | ;; |
| 43 | x86_64-*) |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 44 | IOS_TARGET_PLATFORM="iPhoneSimulator" |
| 45 | ARCHS=("x86_64") |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 46 | ;; |
| 47 | esac |
| 48 | fi |
| 49 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 50 | IOS_TOP_DIR="$(pwd)" |
| 51 | |
| 52 | if [ -z "$DAEMON_DIR" ]; then |
| 53 | DAEMON_DIR="$(pwd)/../daemon" |
| 54 | echo "DAEMON_DIR not provided trying to find it in $DAEMON_DIR" |
| 55 | fi |
| 56 | if [ ! -d "$DAEMON_DIR" ]; then |
| 57 | echo 'Daemon not found.' |
| 58 | echo 'If you cloned the daemon in a custom location override' \ |
| 59 | 'use DAEMON_DIR to point to it' |
| 60 | echo "You can also use our meta repo which contains both: |
Kateryna Kostiuk | 44cd57c | 2022-10-17 20:01:22 -0400 | [diff] [blame] | 61 | https://review.jami.net/admin/repos/jami-project" |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 62 | exit 1 |
| 63 | fi |
| 64 | |
Kateryna Kostiuk | 74230a6 | 2022-08-30 09:45:06 -0400 | [diff] [blame] | 65 | if [ ! `which gas-preprocessor.pl` ] |
| 66 | then |
| 67 | echo 'gas-preprocessor.pl not found. Trying to install...' |
| 68 | mkdir -p "$DAEMON_DIR/extras/tools/build/bin/" |
| 69 | (curl -L https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl \ |
| 70 | -o "$DAEMON_DIR/extras/tools/build/bin/gas-preprocessor.pl" \ |
| 71 | && chmod +x "$DAEMON_DIR/extras/tools/build/bin/gas-preprocessor.pl") |
| 72 | export PATH="$DAEMON_DIR"/extras/tools/build/bin:$PATH |
| 73 | fi |
| 74 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 75 | if [ -z "$NPROC" ]; then |
| 76 | NPROC=`sysctl -n hw.ncpu || echo -n 1` |
| 77 | fi |
| 78 | |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 79 | export IOS_TARGET_PLATFORM |
| 80 | echo "Building for $IOS_TARGET_PLATFORM for $ARCHS" |
| 81 | |
Edric Milaret | a68931d | 2016-07-05 09:53:18 -0400 | [diff] [blame] | 82 | cd $DAEMON_DIR |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 83 | |
| 84 | for ARCH in "${ARCHS[@]}" |
| 85 | do |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 86 | mkdir -p contrib/native-$ARCH |
| 87 | cd contrib/native-$ARCH |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 88 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 89 | if [ "$ARCH" = "arm64" ] |
| 90 | then |
| 91 | HOST=aarch64-apple-darwin_ios |
| 92 | IOS_TARGET_PLATFORM="iPhoneOS" |
| 93 | else |
| 94 | HOST=$ARCH-apple-darwin_ios |
| 95 | IOS_TARGET_PLATFORM="iPhoneSimulator" |
| 96 | fi |
| 97 | export IOS_TARGET_PLATFORM |
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 | 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] | 100 | |
Kateryna Kostiuk | ceebbe4 | 2022-07-19 17:36:13 -0400 | [diff] [blame] | 101 | host=$(sw_vers -productVersion) |
| 102 | if [ "12.0" \> $host ] |
| 103 | then |
| 104 | SDK="`echo "print '${IOS_TARGET_PLATFORM}'.lower()" | python`" |
| 105 | else |
| 106 | SDK="`echo "print('${IOS_TARGET_PLATFORM}'.lower())" | python3`" |
| 107 | fi |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 108 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 109 | CC="xcrun -sdk $SDK clang" |
| 110 | CXX="xcrun -sdk $SDK clang++" |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 111 | |
Kateryna Kostiuk | 46b3f9b | 2020-08-03 12:44:16 -0400 | [diff] [blame] | 112 | SDKROOT="$SDKROOT" ../bootstrap --host="$HOST" --disable-libav --disable-plugin --disable-libarchive --enable-ffmpeg |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 113 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 114 | echo "Building contrib" |
| 115 | make fetch |
| 116 | make -j$NPROC || exit 1 |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 117 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 118 | cd ../.. |
| 119 | echo "Building daemon" |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 120 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 121 | CFLAGS="-arch $ARCH -isysroot $SDKROOT" |
| 122 | if [ "$IOS_TARGET_PLATFORM" = "iPhoneOS" ] |
| 123 | then |
| 124 | CFLAGS+=" -miphoneos-version-min=$MIN_IOS_VERSION -fembed-bitcode" |
| 125 | else |
| 126 | CFLAGS+=" -mios-simulator-version-min=$MIN_IOS_VERSION" |
| 127 | fi |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 128 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 129 | if [ "$RELEASE" = "1" ] |
| 130 | then |
| 131 | CFLAGS+=" -O3" |
| 132 | fi |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 133 | |
Kateryna Kostiuk | b0c3a5e | 2020-07-10 10:15:13 -0400 | [diff] [blame] | 134 | CXXFLAGS="-stdlib=libc++ -std=c++17 $CFLAGS" |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 135 | LDFLAGS="$CFLAGS" |
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 | ./autogen.sh || exit 1 |
| 138 | mkdir -p "build-ios-$ARCH" |
| 139 | cd build-ios-$ARCH |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 140 | |
Kateryna Kostiuk | 44cd57c | 2022-10-17 20:01:22 -0400 | [diff] [blame] | 141 | JAMI_CONF="--host=$HOST \ |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 142 | --without-dbus \ |
Kateryna Kostiuk | 46b3f9b | 2020-08-03 12:44:16 -0400 | [diff] [blame] | 143 | --disable-plugin \ |
| 144 | --disable-libarchive \ |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 145 | --enable-static \ |
Kateryna Kostiuk | e7aae55 | 2023-02-01 14:14:44 -0500 | [diff] [blame] | 146 | --without-upnp \ |
| 147 | --without-natpmp \ |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 148 | --disable-shared \ |
| 149 | --prefix=$IOS_TOP_DIR/DEPS/$ARCH" |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 150 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 151 | if [ "$RELEASE" = "0" ] |
| 152 | then |
Kateryna Kostiuk | 44cd57c | 2022-10-17 20:01:22 -0400 | [diff] [blame] | 153 | JAMI_CONF+=" --enable-debug" |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 154 | fi |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 155 | |
Kateryna Kostiuk | 44cd57c | 2022-10-17 20:01:22 -0400 | [diff] [blame] | 156 | $DAEMON_DIR/configure $JAMI_CONF \ |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 157 | CC="$CC $CFLAGS" \ |
| 158 | CXX="$CXX $CXXFLAGS" \ |
Kateryna Kostiuk | cae6c0e | 2020-03-12 11:28:57 -0400 | [diff] [blame] | 159 | OBJCXX="$CXX $CXXFLAGS" \ |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 160 | LD="$LD" \ |
| 161 | CFLAGS="$CFLAGS" \ |
| 162 | CXXFLAGS="$CXXFLAGS" \ |
| 163 | LDFLAGS="$LDFLAGS" || exit 1 |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 164 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 165 | # We need to copy this file or else it's just an empty file |
| 166 | rsync -a $DAEMON_DIR/src/buildinfo.cpp ./src/buildinfo.cpp |
| 167 | |
| 168 | make -j$NPROC || exit 1 |
| 169 | make install || exit 1 |
| 170 | |
| 171 | rsync -ar $DAEMON_DIR/contrib/$HOST/lib/*.a $IOS_TOP_DIR/DEPS/$ARCH/lib/ |
kkostiuk | 74d1ae4 | 2021-06-17 11:10:15 -0400 | [diff] [blame] | 172 | # copy headers for extension |
| 173 | rsync -ar $DAEMON_DIR/contrib/$HOST/include/opendht $IOS_TOP_DIR/DEPS/$ARCH/include/ |
| 174 | rsync -ar $DAEMON_DIR/contrib/$HOST/include/msgpack.hpp $IOS_TOP_DIR/DEPS/$ARCH/include/ |
| 175 | rsync -ar $DAEMON_DIR/contrib/$HOST/include/gnutls $IOS_TOP_DIR/DEPS/$ARCH/include/ |
| 176 | rsync -ar $DAEMON_DIR/contrib/$HOST/include/json $IOS_TOP_DIR/DEPS/$ARCH/include/ |
| 177 | rsync -ar $DAEMON_DIR/contrib/$HOST/include/msgpack $IOS_TOP_DIR/DEPS/$ARCH/include/ |
kkostiuk | e10e657 | 2022-07-26 15:41:12 -0400 | [diff] [blame] | 178 | rsync -ar $DAEMON_DIR/contrib/$HOST/include/yaml-cpp $IOS_TOP_DIR/DEPS/$ARCH/include/ |
Kateryna Kostiuk | 8a36221 | 2022-09-13 12:01:23 -0400 | [diff] [blame] | 179 | rsync -ar $DAEMON_DIR/contrib/$HOST/include/libavutil $IOS_TOP_DIR/DEPS/$ARCH/include/ |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 180 | cd $IOS_TOP_DIR/DEPS/$ARCH/lib/ |
| 181 | for i in *.a ; do mv "$i" "${i/-$HOST.a/.a}" ; done |
| 182 | |
| 183 | cd $DAEMON_DIR |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 184 | done |
| 185 | |
| 186 | cd $IOS_TOP_DIR |
| 187 | |
| 188 | FAT_DIR=$IOS_TOP_DIR/fat |
| 189 | mkdir -p $FAT_DIR |
| 190 | |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 191 | if ((${#ARCHS[@]} == "2")) |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 192 | then |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 193 | mkdir -p $FAT_DIR/lib |
| 194 | echo "Making fat lib for ${ARCHS[0]} and ${ARCHS[1]}" |
| 195 | LIBFILES=$IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/*.a |
| 196 | for f in $LIBFILES |
| 197 | do |
| 198 | libFile=${f##*/} |
| 199 | echo "Processing $libFile lib..." |
| 200 | #There is only 2 ARCH max... So let's make it simple |
| 201 | lipo -create "$IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/$libFile" \ |
| 202 | "$IOS_TOP_DIR/DEPS/${ARCHS[1]}/lib/$libFile" \ |
| 203 | -output "$FAT_DIR/lib/$libFile" |
| 204 | done |
Guillaume Roguez | d0a1faf | 2016-06-29 15:55:37 -0400 | [diff] [blame] | 205 | else |
Andreas Traczyk | 8174fe2 | 2018-04-16 17:42:09 -0400 | [diff] [blame] | 206 | echo "No need for fat lib" |
| 207 | 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] | 208 | fi |
| 209 | |
| 210 | rsync -ar --delete $IOS_TOP_DIR/DEPS/${ARCHS[0]}/include/* $FAT_DIR/include |