forked from chrisballinger/Opus-iOS
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild-libopus.sh
More file actions
executable file
·301 lines (251 loc) · 9.75 KB
/
build-libopus.sh
File metadata and controls
executable file
·301 lines (251 loc) · 9.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/bin/bash
# Builds libopus for iOS as an XCFramework supporting:
# - iOS Device (arm64)
# - iOS Simulator (arm64 for Apple Silicon, x86_64 for Intel)
#
# Copyright 2012 Mike Tigas <mike@tig.as>
#
# Based on work by Felix Schulze on 16.12.10.
# Copyright 2010 Felix Schulze. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
# Choose your libopus version and your currently-installed iOS SDK version:
#
VERSION="1.5.2"
SDKVERSION="26.0"
MINIOSVERSION="16.0"
###########################################################################
#
# Don't change anything under this line!
#
###########################################################################
# by default, we won't build for debugging purposes
if [ "${DEBUG}" == "true" ]; then
echo "Compiling for debugging ..."
OPT_CFLAGS="-O0 -fno-inline -g"
OPT_LDFLAGS=""
OPT_CONFIG_ARGS="--enable-assertions --disable-asm"
else
OPT_CFLAGS="-O3 -ffast-math -g"
OPT_LDFLAGS=""
OPT_CONFIG_ARGS=""
fi
# Architectures to build
# Device: arm64
# Simulator: arm64 (Apple Silicon) + x86_64 (Intel)
DEVICE_ARCHS="arm64"
SIM_ARCHS="arm64 x86_64"
DEVELOPER=`xcode-select -print-path`
cd "`dirname \"$0\"`"
REPOROOT=$(pwd)
# Where we'll end up storing things in the end
OUTPUTDIR="${REPOROOT}/dependencies"
mkdir -p ${OUTPUTDIR}/include
mkdir -p ${OUTPUTDIR}/lib
# Use /tmp for building to avoid permission issues
BUILDDIR="/tmp/opus-ios-build-$$"
mkdir -p ${BUILDDIR}
# where we will keep our sources and build from.
SRCDIR="${BUILDDIR}/src"
mkdir -p $SRCDIR
# where we will store intermediary builds
INTERDIR="${BUILDDIR}/built"
mkdir -p $INTERDIR
echo "Build directory: ${BUILDDIR}"
########################################
cd $SRCDIR
# Exit the script if an error happens
set -e
# Check if tarball exists in repo, otherwise download
TARBALL="${REPOROOT}/build/src/opus-${VERSION}.tar.gz"
if [ -e "${TARBALL}" ]; then
echo "Using existing opus-${VERSION}.tar.gz from build/src/"
cp "${TARBALL}" "${SRCDIR}/"
elif [ ! -e "${SRCDIR}/opus-${VERSION}.tar.gz" ]; then
echo "Downloading opus-${VERSION}.tar.gz"
curl -LO http://downloads.xiph.org/releases/opus/opus-${VERSION}.tar.gz
fi
echo "Using opus-${VERSION}.tar.gz"
tar zxf opus-${VERSION}.tar.gz -C $SRCDIR
cd "${SRCDIR}/opus-${VERSION}"
set +e # don't bail out of bash script if ccache doesn't exist
CCACHE=`which ccache`
if [ $? == "0" ]; then
echo "Building with ccache: $CCACHE"
CCACHE="${CCACHE} "
else
echo "Building without ccache"
CCACHE=""
fi
set -e # back to regular "bail out on error" mode
export ORIGINALPATH=$PATH
########################################
# Build for iOS Device (arm64)
########################################
echo "========================================"
echo "Building for iOS Device..."
echo "========================================"
for ARCH in ${DEVICE_ARCHS}
do
echo "Building Device arch: ${ARCH}"
PLATFORM="iPhoneOS"
EXTRA_CFLAGS="-arch ${ARCH} -target ${ARCH}-apple-ios${MINIOSVERSION}"
EXTRA_CONFIG="--host=arm-apple-darwin"
mkdir -p "${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk"
./configure --enable-float-approx --disable-shared --disable-asm --enable-static --with-pic --disable-extra-programs --disable-doc ${EXTRA_CONFIG} \
--prefix="${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" \
LDFLAGS="$LDFLAGS ${OPT_LDFLAGS} -fPIE -miphoneos-version-min=${MINIOSVERSION} -L${OUTPUTDIR}/lib" \
CFLAGS="$CFLAGS ${EXTRA_CFLAGS} ${OPT_CFLAGS} -fPIE -miphoneos-version-min=${MINIOSVERSION} -I${OUTPUTDIR}/include -isysroot ${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk" \
make -j4
make install
make clean
done
########################################
# Build for iOS Simulator (arm64 + x86_64)
########################################
echo "========================================"
echo "Building for iOS Simulator..."
echo "========================================"
for ARCH in ${SIM_ARCHS}
do
echo "Building Simulator arch: ${ARCH}"
PLATFORM="iPhoneSimulator"
if [ "${ARCH}" == "arm64" ]; then
# Apple Silicon simulator
EXTRA_CFLAGS="-arch ${ARCH} -target ${ARCH}-apple-ios${MINIOSVERSION}-simulator"
EXTRA_CONFIG="--host=arm-apple-darwin"
else
# Intel simulator
EXTRA_CFLAGS="-arch ${ARCH} -target ${ARCH}-apple-ios${MINIOSVERSION}-simulator"
EXTRA_CONFIG="--host=x86_64-apple-darwin"
fi
mkdir -p "${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk"
./configure --enable-float-approx --disable-shared --disable-asm --enable-static --with-pic --disable-extra-programs --disable-doc ${EXTRA_CONFIG} \
--prefix="${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" \
LDFLAGS="$LDFLAGS ${OPT_LDFLAGS} -fPIE -mios-simulator-version-min=${MINIOSVERSION} -L${OUTPUTDIR}/lib" \
CFLAGS="$CFLAGS ${EXTRA_CFLAGS} ${OPT_CFLAGS} -fPIE -mios-simulator-version-min=${MINIOSVERSION} -I${OUTPUTDIR}/include -isysroot ${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk" \
make -j4
make install
make clean
done
########################################
echo "Creating framework from static libraries..."
########################################
# Create device framework
echo "Creating iOS Device framework..."
DEVICE_FRAMEWORK_DIR="${INTERDIR}/frameworks/device/opus.framework"
mkdir -p "${DEVICE_FRAMEWORK_DIR}/Headers"
# Create device static lib
lipo -create "${INTERDIR}/iPhoneOS${SDKVERSION}-arm64.sdk/lib/libopus.a" \
-output "${DEVICE_FRAMEWORK_DIR}/opus"
# Copy headers
cp -R ${INTERDIR}/iPhoneOS${SDKVERSION}-arm64.sdk/include/opus/* "${DEVICE_FRAMEWORK_DIR}/Headers/"
# Create module map
mkdir -p "${DEVICE_FRAMEWORK_DIR}/Modules"
cat > "${DEVICE_FRAMEWORK_DIR}/Modules/module.modulemap" << EOF
framework module opus {
umbrella header "opus.h"
export *
module * { export * }
}
EOF
# Create Info.plist
cat > "${DEVICE_FRAMEWORK_DIR}/Info.plist" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>opus</string>
<key>CFBundleIdentifier</key>
<string>org.opus-codec.opus</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>opus</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>${VERSION}</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>MinimumOSVersion</key>
<string>${MINIOSVERSION}</string>
</dict>
</plist>
EOF
# Create simulator framework with combined architectures
echo "Creating iOS Simulator framework..."
SIM_FRAMEWORK_DIR="${INTERDIR}/frameworks/simulator/opus.framework"
mkdir -p "${SIM_FRAMEWORK_DIR}/Headers"
mkdir -p "${SIM_FRAMEWORK_DIR}/Modules"
# Combine simulator architectures
lipo -create \
"${INTERDIR}/iPhoneSimulator${SDKVERSION}-arm64.sdk/lib/libopus.a" \
"${INTERDIR}/iPhoneSimulator${SDKVERSION}-x86_64.sdk/lib/libopus.a" \
-output "${SIM_FRAMEWORK_DIR}/opus"
# Copy headers and module map
cp -R ${INTERDIR}/iPhoneSimulator${SDKVERSION}-arm64.sdk/include/opus/* "${SIM_FRAMEWORK_DIR}/Headers/"
cp "${DEVICE_FRAMEWORK_DIR}/Modules/module.modulemap" "${SIM_FRAMEWORK_DIR}/Modules/"
cp "${DEVICE_FRAMEWORK_DIR}/Info.plist" "${SIM_FRAMEWORK_DIR}/"
echo "Device framework architectures:"
lipo -info "${DEVICE_FRAMEWORK_DIR}/opus"
echo "Simulator framework architectures:"
lipo -info "${SIM_FRAMEWORK_DIR}/opus"
########################################
echo "Creating XCFramework..."
########################################
# Remove old XCFramework if exists
rm -rf "${OUTPUTDIR}/opus.xcframework"
# Create XCFramework from frameworks
xcodebuild -create-xcframework \
-framework "${DEVICE_FRAMEWORK_DIR}" \
-framework "${SIM_FRAMEWORK_DIR}" \
-output "${OUTPUTDIR}/opus.xcframework"
echo "XCFramework created at: ${OUTPUTDIR}/opus.xcframework"
# Also update headers in dependencies/include
cp -R ${INTERDIR}/iPhoneOS${SDKVERSION}-arm64.sdk/include/* ${OUTPUTDIR}/include/
########################################
echo "Verifying XCFramework..."
########################################
echo "XCFramework contents:"
ls -la "${OUTPUTDIR}/opus.xcframework/"
echo ""
echo "Device library info:"
lipo -info "${OUTPUTDIR}/opus.xcframework/ios-arm64/libopus.a" 2>/dev/null || echo "(check ios-arm64 directory)"
echo ""
echo "Simulator library info:"
lipo -info "${OUTPUTDIR}/opus.xcframework/ios-arm64_x86_64-simulator/libopus.a" 2>/dev/null || echo "(check simulator directory)"
####################
echo ""
echo "Building done."
echo "Cleaning up..."
rm -rf ${BUILDDIR}
echo "Done."
echo ""
echo "========================================"
echo "Build Summary:"
echo "========================================"
echo "XCFramework: ${OUTPUTDIR}/opus.xcframework"
echo "Headers: ${OUTPUTDIR}/include/opus/"
echo ""
echo "Supported architectures:"
echo " - iOS Device: arm64"
echo " - iOS Simulator: arm64 (Apple Silicon) + x86_64 (Intel)"
echo ""
echo "Use this XCFramework with CocoaPods or SPM."
echo "========================================"