-
Notifications
You must be signed in to change notification settings - Fork 14
/
prepare.sh
executable file
·159 lines (130 loc) · 5.14 KB
/
prepare.sh
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
#!/bin/sh
# MIT License
# Copyright (c) 2021 Ybrid®, a Hybrid Dynamic Live Audio Technology
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# Generates fat libopus.a for iOS and for macOS.
#
# Preconditions:
# - clang installed
# - git clone of https://github.com/xiph/opus in directory ../opus
# - checked iosSDKVersion and osxSDKVersion
iosSDKVersion="14.4"
osxSDKVersion="11.1"
opusDownload="https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz"
here=$(pwd)
rm -f opus-*.gz
wget $opusDownload
libopusDir=`basename $opusDownload | sed "s/\.tar.gz$//"`
rm -rf $libopusDir
tar -xvzf `basename $opusDownload`
echo "opus sources ready in $libopusDir"
echo "\n==========================="
opuspath="$here/$libopusDir"
opusArtifact=.libs/libopus.a
opusHeaders="$opuspath/include"
tmp=./prepare
fatLibsDest=opus-swift/libs
generateLibopus()
{
host=$1
arch=$2
sdk=$3
sdkname=`basename $sdk | sed "s/[0-9\.]*\.sdk$//"` # stripping path, version and '.sdk'
product="libopus_${host}_${arch}_$sdkname.a"
echo "\n----------------------------"
echo "generating $tmp/$product ...\n"
logfile="$here/$tmp/generate_${host}_${arch}_$sdkname.log"
cd $opuspath
make clean > $logfile
if [[ $sdkname =~ "iPhone" ]]; then
minversion="-miphoneos-version-min=9.0"
else # contains "Mac"
minversion="-mmacosx-version-min=10.10"
fi
./configure CC=clang --enable-float-approx --disable-shared --enable-static --with-pic \
--disable-extra-programs --disable-doc --host=$host \
CFLAGS=" -arch $arch -Ofast -flto -g -fPIE $minversion -isysroot $sdk" \
LDFLAGS=" -flto -fPIE $minversion" >> $logfile
make >> $logfile
cd $here
cp "$opuspath/$opusArtifact" "$tmp/$product"
echo "generated $product, see $logfile\n"
lipo -i "$tmp/$product"
}
xcodePlatforms="/Applications/Xcode.app/Contents/Developer/Platforms"
sdkSimulator="$xcodePlatforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator$iosSDKVersion.sdk"
sdkPhone="/$xcodePlatforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$iosSDKVersion.sdk"
sdkMac="/$xcodePlatforms/MacOSX.platform/Developer/SDKs/MacOSX$osxSDKVersion.sdk"
cd $opuspath
make distclean
cd $here
rm -rf $tmp
mkdir -p $tmp
fatProductIos="libopus_ios.a"
echo "\n==========================="
echo "generate $fatProductIos ..."
generateLibopus "x86_64-apple-darwin" "x86_64" $sdkSimulator
generateLibopus "x86_64-apple-darwin" "i386" $sdkSimulator
generateLibopus "arm-apple-darwin" "armv7" $sdkPhone
generateLibopus "arm-apple-darwin" "arm64" $sdkPhone
cd $tmp
products=`ls | grep libopus | grep iPhone`
echo "generating $fatProductIos from ${products} ..."
lipo -create ${products} -output $fatProductIos
cd $here
cp -v $tmp/$fatProductIos $fatLibsDest
lipo -info $fatLibsDest/$fatProductIos
echo "$fatLibsDest/$fatProductIos generated."
echo "\n==========================="
fatProductMac="libopus_osx.a"
echo "\n==========================="
echo "generate $fatProductMac ..."
generateLibopus "x86_64-apple-darwin20.2.0" "x86_64" $sdkMac
generateLibopus "aarch64-apple-darwin20.0.0" "arm64" $sdkMac
cd $tmp
products=`ls | grep libopus | grep Mac`
echo "generating $fatProductMac from ${products} ..."
lipo -create ${products} -output $fatProductMac
cd $here
cp -v $tmp/$fatProductMac $fatLibsDest
lipo -info $fatLibsDest/$fatProductMac
echo "$fatLibsDest/$fatProductMac ready."
echo "\n==========================="
fatProductCatalyst="libopus_catalyst.a"
echo "\n==========================="
echo "generate $fatProductCatalyst ..."
generateLibopus "x86_64-apple-darwin20.2.0" "x86_64h" $sdkMac
cd $tmp
products=`ls | grep libopus | grep x86_64h`
echo "generating $fatProductCatalyst from ${products} ..."
lipo -create ${products} -output $fatProductCatalyst
cd $here
cp -v $tmp/$fatProductCatalyst $fatLibsDest
lipo -info $fatLibsDest/$fatProductCatalyst
echo "$fatLibsDest/$fatProductCatalyst ready."
echo "\n==========================="
echo "generating libraries done."
echo "\n==========================="
cd $here
echo "copy headers into opus-swift.xcodeproj"
for f in $opusHeaders/*.h; do
file=`basename $f`
cp -v $f ./opus-swift/include
done
echo "opus-swift.xcodeproj is ready"
echo "done."