blob: 88190bbaecfe4bec875470ee63a35c43e9025dbf [file] [log] [blame]
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -04001#! /bin/sh
2
3export BUILDFORIOS=1
Kateryna Kostiukfd5e6f12022-08-02 11:24:05 -04004export MIN_IOS_VERSION=14.5
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -04005IOS_TARGET_PLATFORM=iPhoneSimulator
6RELEASE=0
7
8while test -n "$1"
9do
10 case "$1" in
Andreas Traczyk8174fe22018-04-16 17:42:09 -040011 --platform=*)
12 IOS_TARGET_PLATFORM="${1#--platform=}"
13 ;;
14 --host=*)
15 HOST="${1#--host=}"
16 ;;
kkostiuk9411e5d2021-06-02 17:48:40 -040017 --release)
18 RELEASE=1
19 ;;
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040020 esac
21 shift
22done
23
24if test -z "$HOST"
25then
Andreas Traczyk8174fe22018-04-16 17:42:09 -040026 if [ "$IOS_TARGET_PLATFORM" = "all" ]
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040027 then
Andreas Traczyk8174fe22018-04-16 17:42:09 -040028 ARCHS=("arm64" "x86_64")
29 elif [ "$IOS_TARGET_PLATFORM" = "iPhoneSimulator" ]
30 then
31 ARCHS=("x86_64")
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040032 elif [ "$IOS_TARGET_PLATFORM" = "iPhoneOS" ]
33 then
Andreas Traczyk8174fe22018-04-16 17:42:09 -040034 ARCHS=("arm64")
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040035 fi
36else
Andreas Traczyk8174fe22018-04-16 17:42:09 -040037 ARCHS=("${HOST%%-*}")
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040038 case "$HOST" in
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040039 aarch64-*)
Andreas Traczyk8174fe22018-04-16 17:42:09 -040040 IOS_TARGET_PLATFORM="iPhoneOS"
41 ARCHS=("arm64")
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040042 ;;
43 x86_64-*)
Andreas Traczyk8174fe22018-04-16 17:42:09 -040044 IOS_TARGET_PLATFORM="iPhoneSimulator"
45 ARCHS=("x86_64")
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040046 ;;
47 esac
48fi
49
Andreas Traczyk8174fe22018-04-16 17:42:09 -040050IOS_TOP_DIR="$(pwd)"
51
52if [ -z "$DAEMON_DIR" ]; then
53 DAEMON_DIR="$(pwd)/../daemon"
54 echo "DAEMON_DIR not provided trying to find it in $DAEMON_DIR"
55fi
56if [ ! -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:
61 https://gerrit-ring.savoirfairelinux.com/#/admin/projects/ring-project"
62 exit 1
63fi
64
Kateryna Kostiuk74230a62022-08-30 09:45:06 -040065if [ ! `which gas-preprocessor.pl` ]
66then
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
73fi
74
Andreas Traczyk8174fe22018-04-16 17:42:09 -040075if [ -z "$NPROC" ]; then
76 NPROC=`sysctl -n hw.ncpu || echo -n 1`
77fi
78
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040079export IOS_TARGET_PLATFORM
80echo "Building for $IOS_TARGET_PLATFORM for $ARCHS"
81
Edric Milareta68931d2016-07-05 09:53:18 -040082cd $DAEMON_DIR
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040083
84for ARCH in "${ARCHS[@]}"
85do
Andreas Traczyk8174fe22018-04-16 17:42:09 -040086 mkdir -p contrib/native-$ARCH
87 cd contrib/native-$ARCH
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040088
Andreas Traczyk8174fe22018-04-16 17:42:09 -040089 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 Roguezd0a1faf2016-06-29 15:55:37 -040098
Andreas Traczyk8174fe22018-04-16 17:42:09 -040099 SDKROOT=`xcode-select -print-path`/Platforms/${IOS_TARGET_PLATFORM}.platform/Developer/SDKs/${IOS_TARGET_PLATFORM}${SDK_VERSION}.sdk
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400100
Kateryna Kostiukceebbe42022-07-19 17:36:13 -0400101 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 Roguezd0a1faf2016-06-29 15:55:37 -0400108
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400109 CC="xcrun -sdk $SDK clang"
110 CXX="xcrun -sdk $SDK clang++"
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400111
Kateryna Kostiuk46b3f9b2020-08-03 12:44:16 -0400112 SDKROOT="$SDKROOT" ../bootstrap --host="$HOST" --disable-libav --disable-plugin --disable-libarchive --enable-ffmpeg
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400113
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400114 echo "Building contrib"
115 make fetch
116 make -j$NPROC || exit 1
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400117
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400118 cd ../..
119 echo "Building daemon"
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400120
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400121 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 Roguezd0a1faf2016-06-29 15:55:37 -0400128
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400129 if [ "$RELEASE" = "1" ]
130 then
131 CFLAGS+=" -O3"
132 fi
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400133
Kateryna Kostiukb0c3a5e2020-07-10 10:15:13 -0400134 CXXFLAGS="-stdlib=libc++ -std=c++17 $CFLAGS"
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400135 LDFLAGS="$CFLAGS"
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400136
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400137 ./autogen.sh || exit 1
138 mkdir -p "build-ios-$ARCH"
139 cd build-ios-$ARCH
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400140
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400141 RING_CONF="--host=$HOST \
142 --without-dbus \
Kateryna Kostiuk46b3f9b2020-08-03 12:44:16 -0400143 --disable-plugin \
144 --disable-libarchive \
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400145 --enable-static \
146 --disable-shared \
147 --prefix=$IOS_TOP_DIR/DEPS/$ARCH"
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400148
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400149 if [ "$RELEASE" = "0" ]
150 then
151 RING_CONF+=" --enable-debug"
152 fi
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400153
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400154 $DAEMON_DIR/configure $RING_CONF \
155 CC="$CC $CFLAGS" \
156 CXX="$CXX $CXXFLAGS" \
Kateryna Kostiukcae6c0e2020-03-12 11:28:57 -0400157 OBJCXX="$CXX $CXXFLAGS" \
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400158 LD="$LD" \
159 CFLAGS="$CFLAGS" \
160 CXXFLAGS="$CXXFLAGS" \
161 LDFLAGS="$LDFLAGS" || exit 1
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400162
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400163 # We need to copy this file or else it's just an empty file
164 rsync -a $DAEMON_DIR/src/buildinfo.cpp ./src/buildinfo.cpp
165
166 make -j$NPROC || exit 1
167 make install || exit 1
168
169 rsync -ar $DAEMON_DIR/contrib/$HOST/lib/*.a $IOS_TOP_DIR/DEPS/$ARCH/lib/
kkostiuk74d1ae42021-06-17 11:10:15 -0400170 # copy headers for extension
171 rsync -ar $DAEMON_DIR/contrib/$HOST/include/opendht $IOS_TOP_DIR/DEPS/$ARCH/include/
172 rsync -ar $DAEMON_DIR/contrib/$HOST/include/msgpack.hpp $IOS_TOP_DIR/DEPS/$ARCH/include/
173 rsync -ar $DAEMON_DIR/contrib/$HOST/include/gnutls $IOS_TOP_DIR/DEPS/$ARCH/include/
174 rsync -ar $DAEMON_DIR/contrib/$HOST/include/json $IOS_TOP_DIR/DEPS/$ARCH/include/
175 rsync -ar $DAEMON_DIR/contrib/$HOST/include/msgpack $IOS_TOP_DIR/DEPS/$ARCH/include/
kkostiuke10e6572022-07-26 15:41:12 -0400176 rsync -ar $DAEMON_DIR/contrib/$HOST/include/yaml-cpp $IOS_TOP_DIR/DEPS/$ARCH/include/
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400177 cd $IOS_TOP_DIR/DEPS/$ARCH/lib/
178 for i in *.a ; do mv "$i" "${i/-$HOST.a/.a}" ; done
179
180 cd $DAEMON_DIR
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400181done
182
183cd $IOS_TOP_DIR
184
185FAT_DIR=$IOS_TOP_DIR/fat
186mkdir -p $FAT_DIR
187
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400188if ((${#ARCHS[@]} == "2"))
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400189then
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400190 mkdir -p $FAT_DIR/lib
191 echo "Making fat lib for ${ARCHS[0]} and ${ARCHS[1]}"
192 LIBFILES=$IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/*.a
193 for f in $LIBFILES
194 do
195 libFile=${f##*/}
196 echo "Processing $libFile lib..."
197 #There is only 2 ARCH max... So let's make it simple
198 lipo -create "$IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/$libFile" \
199 "$IOS_TOP_DIR/DEPS/${ARCHS[1]}/lib/$libFile" \
200 -output "$FAT_DIR/lib/$libFile"
201 done
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400202else
Andreas Traczyk8174fe22018-04-16 17:42:09 -0400203 echo "No need for fat lib"
204 rsync -ar --delete $IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/*.a $FAT_DIR/lib
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400205fi
206
207rsync -ar --delete $IOS_TOP_DIR/DEPS/${ARCHS[0]}/include/* $FAT_DIR/include