-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_ffmpeg_iOS.sh
executable file
·235 lines (184 loc) · 4.3 KB
/
build_ffmpeg_iOS.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
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
#!/bin/bash
VERSION=1.0
CWD=$(pwd)
PACKAGES="$CWD/packages"
WORKSPACE="$CWD/workspace"
THIN="$CWD/thin"
FAT="$CWD/fat"
SCRATCH="$CWD/scratch"
SOURCE=""
DEPLOYMENT_TARGET_MIN="8.0"
# LDFLAGS="-L${WORKSPACE}/lib -lm" # 指定链接的lib文件
# CFLAGS="-I${WORKSPACE}/include" # 指定链接的头文件
# PKG_CONFIG_PATH="${WORKSPACE}/lib/pkgconfig"
CONFIGURE_FLAGS="--enable-cross-compile --disable-stripping --disable-optimizations --disable-armv5te --disable-armv6 --disable-armv6t2 --disable-programs \
--disable-doc --enable-pic --disable-lzma --enable-debug"
# ARCHS="arm64 armv7 x86_64 i386"
# ARCHS="x86_64"
# ARCHS="arm64"
ARCHS="arm64 x86_64"
# Speed up the process
# Env var NUMJOBS overrides automatic detection
if [[ -n $NUMJOBS ]]; then
MJOBS=$NUMJOBS
elif [[ -f /proc/cpuinfo ]]; then
MJOBS=$(grep -c processor /proc/cpuinfo)
elif [[ "$OSTYPE" == "darwin"* ]]; then
MJOBS=$(sysctl -n machdep.cpu.thread_count)
else
MJOBS=4
fi
make_dir () {
if [ ! -d $1 ]; then
if ! mkdir $1; then
printf "\n Failed to create dir %s" "$1";
exit 1
fi
fi
}
remove_dir () {
if [ -d $1 ]; then
rm -r "$1"
fi
}
execute () {
echo "$ $*"
OUTPUT=$($@ 2>&1)
if [ $? -ne 0 ]; then
echo "$OUTPUT"
echo ""
echo "Failed to Execute &*" >&2
exit 1
fi
}
download () {
if [ ! -f "$PACKAGES/$2" ]; then
echo "Downloading $1"
curl -L --show-error -o "$PACKAGES/$2" "$1" --progress
EXITCODE=$?
if [ $EXITCODE -ne 0 ]; then
echo ""
echo "Failed to download $1. Exitcode $EXITCODE. Retrying in 10 seconds";
sleep 10
curl -L --show-error -o "$PACKAGES/$2" "$1" --progress
fi
EXITCODE=$?
if [ $EXITCODE -ne 0 ]; then
echo ""
echo "Failed to download $1. Exitcode $EXITCODE";
exit 1
fi
echo "... Done"
if ! tar -xvf "$PACKAGES/$2" -C "$PACKAGES" 2>/dev/null >/dev/null; then
echo "Failed to extract $2";
exit 1
fi
fi
for objName in $(ls $PACKAGES)
do
# SOURCE is absolute path
[ -d $PACKAGES/$objName ] && SOURCE=$PACKAGES/$objName
done
echo "SOURCE is $SOURCE"
}
build () {
echo "building $1"
echo "==========="
if [ -f "$PACKAGES/$1.done" ]; then
echo "$1 alread built."
return 1
fi
}
command_exists() {
if ! [[ -x $(command -v "$1") ]]; then
return 1
fi
return 0
}
if ! command_exists "make"; then
echo "make not install"
exit 1
else
echo "make is install"
fi
if ! command_exists "g++"; then
echo "g++ not install"
exit 1
else
echo "g++ is install"
fi
if ! command_exists "curl"; then
echo "curl not install"
exit 1
else
echo "curl is install"
fi
# echo "make install"
echo "packages $PACKAGES"
echo "MJOBS $MJOBS"
if build "yasm"; then
echo "down yasm"
fi
echo "Using $MJOBS make jobs simultaneously."
make_dir $PACKAGES
make_dir $WORKSPACE
make_dir $THIN
make_dir $FAT
export PATH=${WORKSPACE}/bin:$PATH
echo "PATH $PATH"
echo "OSTYPE $OSTYPE"
TYPE="darwin"*
echo "TYPE $TYPE"
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "mac os"
fi
build "ffmpeg"
download "http://ffmpeg.org/releases/ffmpeg-4.0.tar.bz2" "ffmpeg-snapshot.tar.bz2"
for ARCH in $ARCHS
do
echo "build $ARCH..."
mkdir -p "$SCRATCH/$ARCH"
cd "$SCRATCH/$ARCH"
CFLAGS="-arch $ARCH"
if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]
then
PLATFORM="iPhoneSimulator"
CFLAGS="$CFLAGS -mios-simulator-version-min=$DEPLOYMENT_TARGET_MIN"
CONFIGURE_FLAGS="$CONFIGURE_FLAGS --disable-asm"
else
PLATFORM="iPhoneOS"
CFLAGS="$CFLAGS -mios-version-min=$DEPLOYMENT_TARGET_MIN -fembed-bitcode"
CONFIGURE_FLAGS="$CONFIGURE_FLAGS --enable-asm"
fi
XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`
CC="xcrun -sdk $XCRUN_SDK clang"
AS="$CC"
CXXFLAGS="$CFLAGS"
LDFLAGS="$CFLAGS"
$SOURCE/configure \
--target-os=darwin \
--arch=$ARCH \
--cc="$CC" \
--as="$AS" \
$CONFIGURE_FLAGS \
--extra-cflags="$CFLAGS" \
--extra-ldflags="$LDFLAGS" \
--prefix="${THIN}/$ARCH"
# install 将编译生成的lib和.h文件安装到"$THIN/$ARCH"目录下
execute make -j $MJOBS install || exit 1
done
echo "compile and install Doned"
echo "building fat binaries..."
mkdir -p $FAT/lib
set - $ARCHS
CWD=`pwd`
cd $THIN/$1/lib
for LIB in *.a
do
cd $CWD
echo lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB 1>&2
lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB || exit 1
done
cd $CWD
cp -rf $THIN/$1/include $FAT
echo Done