blob: 6742f56b33bae8739c383ddc1f44ec48c6c8630f [file] [log] [blame]
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -04001#! /bin/sh
2
3export BUILDFORIOS=1
Romain Bertozzi43843692016-11-10 11:09:18 -05004export MIN_IOS_VERSION=9.3
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -04005IOS_TARGET_PLATFORM=iPhoneSimulator
6RELEASE=0
7
8while test -n "$1"
9do
10 case "$1" in
11 --platform=*)
12 IOS_TARGET_PLATFORM="${1#--platform=}"
13 ;;
14 --host=*)
15 HOST="${1#--host=}"
16 ;;
17 esac
18 shift
19done
20
21if test -z "$HOST"
22then
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
30else
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
44fi
45
46export IOS_TARGET_PLATFORM
47echo "Building for $IOS_TARGET_PLATFORM for $ARCHS"
48
49SDKROOT=`xcode-select -print-path`/Platforms/${IOS_TARGET_PLATFORM}.platform/Developer/SDKs/${IOS_TARGET_PLATFORM}${SDK_VERSION}.sdk
50
51if [ ! `which gas-preprocessor.pl` ]
52then
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
58fi
59
60SDK="`echo "print '${IOS_TARGET_PLATFORM}'.lower()" | python`"
61
62CC="xcrun -sdk $SDK clang"
63CXX="xcrun -sdk $SDK clang++"
64
65IOS_TOP_DIR="$(pwd)"
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040066
Edric Milareta68931d2016-07-05 09:53:18 -040067if [ -z "$DAEMON_DIR" ]; then
68 DAEMON_DIR="$(pwd)/../daemon"
69 echo "DAEMON_DIR not provided trying to find it in $DAEMON_DIR"
70fi
71if [ ! -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
78fi
79
Romain Bertozzi0fefaa32017-01-06 09:19:55 -050080if [ -z "$NPROC" ]; then
81 NPROC=`sysctl -n hw.ncpu || echo -n 1`
82fi
83
Edric Milareta68931d2016-07-05 09:53:18 -040084cd $DAEMON_DIR
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040085
86for ARCH in "${ARCHS[@]}"
87do
88 mkdir -p contrib/native-$ARCH
89 cd contrib/native-$ARCH
90
91 if test -z "$HOST"
92 then
Edric Milareta68931d2016-07-05 09:53:18 -040093 if [ "$ARCH" = "arm64" ]
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040094 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 Bertozzi0fefaa32017-01-06 09:19:55 -0500104 make fetch
105 make -j$NPROC || exit 1
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400106
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
123 CXXFLAGS="-std=c++11 -stdlib=libc++ $CFLAGS"
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 Bertozzi0fefaa32017-01-06 09:19:55 -0500153 make -j$NPROC || exit 1
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400154 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
161done
162
163cd $IOS_TOP_DIR
164
165FAT_DIR=$IOS_TOP_DIR/fat
166mkdir -p $FAT_DIR
167
168if ((${#ARCHS[@]} > "1"))
169then
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
180else
181 echo "No need for fat lib"
182 rsync -ar --delete $IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/*.a $FAT_DIR/lib
183fi
184
185rsync -ar --delete $IOS_TOP_DIR/DEPS/${ARCHS[0]}/include/* $FAT_DIR/include