This repository was archived by the owner on Dec 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·257 lines (227 loc) · 6.52 KB
/
build.sh
File metadata and controls
executable file
·257 lines (227 loc) · 6.52 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
#!/bin/bash
###############################################################################
#
# This script will build FFMPEG for android.
#
# Prerequisits:
# - FFMPEG source checked out / copied to src subfolder.
#
# Build steps:
# - Patch the FFMPEG configure script to fix missing support for shared
# library versioning on android.
# - Configure FFMPEG
# - Build FFMPEG
#
###############################################################################
SCRIPT=$(readlink -f $0)
BASE=$(dirname $SCRIPT)
###############################################################################
#
# Argument parsing.
# Allow some components to be overwritten by command line arguments.
#
###############################################################################
if [ -z $HOST_ARCH]; then
HOST_ARCH=$(uname -m)
fi
if [ -z $PLATFORM ]; then
PLATFORM=9
fi
if [ -z $MAKE_OPTS ]; then
MAKE_OPTS="-j4"
fi
function usage
{
echo "$0 [-a <ndk>] [-h <host arch>] [-m <make opts>] [-p <android platform>]"
echo -e "\tdefaults:"
echo -e "\tHOST_ARCH=$HOST_ARCH"
echo -e "\tPLATFORM=$PLATFORM"
echo -e "\tMAKE_OPTS=$MAKE_OPTS"
echo -e "\tANDROID_NDK must be set manually."
echo ""
echo -e "\tAll arguments can also be set as environment variables."
exit -3
}
while getopts "a:h:m:p:" opt; do
case $opt in
a)
ANDROID_NDK=$OPTARG
;;
h)
HOST_ARCH=$OPTARG
;;
m)
MAKE_OPTS=$OPTARG
;;
p)
PLATFORM=$OPTARG
;;
\?)
echo "Invalid option $OPTARG" >&2
usage
;;
esac
done
if [ -z $HOST_ARCH ]; then
HOST_ARCH=$(uname -m)
fi
if [ -z $PLATFORM ]; then
PLATFORM=9
fi
if [ -z $MAKE_OPTS ]; then
MAKE_OPTS="-j4"
fi
if [ -z $ANDROID_NDK ]; then
echo "ANDROID_NDK not set. Set it to the directory of your NDK installation."
exit -1
fi
if [ ! -d $BASE/src ]; then
echo "Please copy or check out FFMPEG source to folder src!"
exit -2
fi
echo "Building with:"
echo "HOST_ARCH=$HOST_ARCH"
echo "PLATFORM=$PLATFORM"
echo "MAKE_OPTS=$MAKE_OPTS"
echo "ANDROID_NDK=$ANDROID_NDK"
cd $BASE/src
# Save original configuration file
# or restore original before applying patches.
if [ ! -f configure.bak ]; then
echo "Saving original configure file to configure.bak"
cp configure configure.bak
else
echo "Restoring original configure file from configure.bak"
cp configure.bak configure
fi
patch -p1 < $BASE/patches/config.patch
if [ ! -f library.mak.bak ]; then
echo "Saving original library.mak file to library.mak.bak"
cp library.mak library.mak.bak
else
echo "Restoring original library.mak file from library.mak.bak"
cp library.mak.bak library.mak
fi
patch -p1 < $BASE/patches/library.mak.patch
# Remove old build and installation files.
if [ -d $BASE/install ]; then
rm -rf $BASE/install
fi
if [ -d $BASE/build ]; then
rm -rf $BASE/build
fi
###############################################################################
#
# build_one ... builds FFMPEG with provided arguments.
#
# Calling convention:
#
# build_one <PREFIX> <CROSS_PREFIX> <ARCH> <SYSROOT> <CFLAGS> <LDFLAGS> <EXTRA>
#
# PREFIX ... Installation directory
# CROSS_PREFIX ... Full path with toolchain prefix
# ARCH ... Architecture to build for (arm, x86, mips)
# SYSROOT ... Android platform to build for, full path.
# CFLAGS ... Additional CFLAGS for building.
# LDFLAGS ... Additional LDFLAGS for linking
# EXTRA ... Any additional configuration flags, e.g. --cpu=XXX
#
###############################################################################
function build_one
{
mkdir -p $1
cd $1
$BASE/src/configure \
--prefix=$2 \
--enable-shared \
--enable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-doc \
--enable-symver \
--enable-decoder=h264 \
--enable-parser=h264 \
--enable-decoder=h263 \
--enable-runtime-cpudetect \
--cross-prefix=$3 \
--target-os=linux \
--enable-pic \
--arch=$4 \
--enable-cross-compile \
--sysroot=$5 \
--extra-cflags="-Os $6" \
--extra-ldflags="$7" \
$8
make clean
make $MAKE_OPTS
make install
}
NDK=$ANDROID_NDK
###############################################################################
#
# ARM build configuration
#
###############################################################################
PREFIX=$BASE/install/armeabi
BUILD_ROOT=$BASE/build/armeabi
SYSROOT=$NDK/platforms/android-$PLATFORM/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-$HOST_ARCH
CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
ARCH=arm
E_CFLAGS=
E_LDFLAGS=
EXTRA=
build_one "$BUILD_ROOT" "$PREFIX" "$CROSS_PREFIX" "$ARCH" "$SYSROOT" \
"$E_CFLAGS" "$E_LDFLAGS" "$EXTRA"
###############################################################################
#
# ARM-v7a build configuration
#
###############################################################################
PREFIX=$BASE/install/armeabi-v7a
BUILD_ROOT=$BASE/build/armeabi-v7a
SYSROOT=$NDK/platforms/android-$PLATFORM/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-$HOST_ARCH
CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
ARCH=arm
E_CFLAGS="-march=armv7-a -mfloat-abi=softfp"
E_LDFLAGS=
EXTRA=
build_one "$BUILD_ROOT" "$PREFIX" "$CROSS_PREFIX" "$ARCH" "$SYSROOT" \
"$E_CFLAGS" "$E_LDFLAGS" "$EXTRA"
###############################################################################
#
# x86 build configuration
#
###############################################################################
PREFIX=$BASE/install/x86
BUILD_ROOT=$BASE/build/x86
SYSROOT=$NDK/platforms/android-$PLATFORM/arch-x86/
TOOLCHAIN=$NDK/toolchains/x86-4.8/prebuilt/linux-$HOST_ARCH
CROSS_PREFIX=$TOOLCHAIN/bin/i686-linux-android-
ARCH=x86
E_CFLAGS=
E_LDFLAGS=
EXTRA="--disable-asm"
build_one "$BUILD_ROOT" "$PREFIX" "$CROSS_PREFIX" "$ARCH" "$SYSROOT" \
"$E_CFLAGS" "$E_LDFLAGS" "$EXTRA"
###############################################################################
#
# MIPS build configuration
#
###############################################################################
PREFIX=$BASE/install/mips
BUILD_ROOT=$BASE/build/mips
SYSROOT=$NDK/platforms/android-$PLATFORM/arch-mips/
TOOLCHAIN=$NDK/toolchains/mipsel-linux-android-4.8/prebuilt/linux-$HOST_ARCH
CROSS_PREFIX=$TOOLCHAIN/bin/mipsel-linux-android-
ARCH=mips32
E_CFLAGS=
E_LDFLAGS=
EXTRA=""
build_one "$BUILD_ROOT" "$PREFIX" "$CROSS_PREFIX" "$ARCH" "$SYSROOT" \
"$E_CFLAGS" "$E_LDFLAGS" "$EXTRA"