blob: b4ad5d0d0682187a7e2c5d76e6ab6374ffabd7e0 [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
80cd $DAEMON_DIR
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040081
82for ARCH in "${ARCHS[@]}"
83do
84 mkdir -p contrib/native-$ARCH
85 cd contrib/native-$ARCH
86
87 if test -z "$HOST"
88 then
Edric Milareta68931d2016-07-05 09:53:18 -040089 if [ "$ARCH" = "arm64" ]
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -040090 then
91 HOST=aarch64-apple-darwin_ios
92 else
93 HOST=$ARCH-apple-darwin_ios
94 fi
95 fi
96
97 SDKROOT="$SDKROOT" ../bootstrap --host="$HOST" --disable-libav --enable-ffmpeg
98
99 echo "Building contrib"
100 make fetch
Guillaume Roguez143c5342016-08-19 15:57:50 -0400101 make || exit 1
Guillaume Roguezd0a1faf2016-06-29 15:55:37 -0400102
103 cd ../..
104 echo "Building daemon"
105
106 CFLAGS="-arch $ARCH -isysroot $SDKROOT"
107 if [ "$IOS_TARGET_PLATFORM" = "iPhoneOS" ]
108 then
109 CFLAGS+=" -miphoneos-version-min=$MIN_IOS_VERSION -fembed-bitcode"
110 else
111 CFLAGS+=" -mios-simulator-version-min=$MIN_IOS_VERSION"
112 fi
113
114 if [ "$RELEASE" = "1" ]
115 then
116 CFLAGS+=" -O3"
117 fi
118
119 CXXFLAGS="-std=c++11 -stdlib=libc++ $CFLAGS"
120 LDFLAGS="$CFLAGS"
121
122 ./autogen.sh || exit 1
123 mkdir -p "build-ios-$ARCH"
124 cd build-ios-$ARCH
125
126 RING_CONF="--host=$HOST \
127 --without-dbus \
128 --enable-static \
129 --disable-shared \
130 --disable-video \
131 --prefix=$IOS_TOP_DIR/DEPS/$ARCH"
132
133 if [ "$RELEASE" = "0" ]
134 then
135 RING_CONF+=" --enable-debug"
136 fi
137
138 $DAEMON_DIR/configure $RING_CONF \
139 CC="$CC $CFLAGS" \
140 CXX="$CXX $CXXFLAGS" \
141 LD="$LD" \
142 CFLAGS="$CFLAGS" \
143 CXXFLAGS="$CXXFLAGS" \
144 LDFLAGS="$LDFLAGS" || exit 1
145
146 # We need to copy this file or else it's just an empty file
147 rsync -a $DAEMON_DIR/src/buildinfo.cpp ./src/buildinfo.cpp
148
149 make -j4 || exit 1
150 make install || exit 1
151
152 rsync -ar $DAEMON_DIR/contrib/$HOST/lib/*.a $IOS_TOP_DIR/DEPS/$ARCH/lib/
153 cd $IOS_TOP_DIR/DEPS/$ARCH/lib/
154 for i in *.a ; do mv "$i" "${i/-$HOST.a/.a}" ; done
155
156 cd $DAEMON_DIR
157done
158
159cd $IOS_TOP_DIR
160
161FAT_DIR=$IOS_TOP_DIR/fat
162mkdir -p $FAT_DIR
163
164if ((${#ARCHS[@]} > "1"))
165then
166 echo "Making fat lib for $ARCHS"
167 LIBFILES=$IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/*.a
168 for f in $LIBFILES
169 do
170 echo "Processing $f lib..."
171 #There is only 2 ARCH max... So let's make it simple
172 lipo -create "$IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/$f" \
173 "$IOS_TOP_DIR/DEPS/${ARCHS[1]}/lib/$f" \
174 -output "$FAT_DIR/lib/$f"
175 done
176else
177 echo "No need for fat lib"
178 rsync -ar --delete $IOS_TOP_DIR/DEPS/${ARCHS[0]}/lib/*.a $FAT_DIR/lib
179fi
180
181rsync -ar --delete $IOS_TOP_DIR/DEPS/${ARCHS[0]}/include/* $FAT_DIR/include