forked from Javernaut/ffmpeg-android-maker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffmpeg-android-maker.sh
More file actions
executable file
·151 lines (127 loc) · 5.11 KB
/
ffmpeg-android-maker.sh
File metadata and controls
executable file
·151 lines (127 loc) · 5.11 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
#!/usr/bin/env bash
# Defining essential directories
# The root of the project
export BASE_DIR="$( cd "$( dirname "$0" )" && pwd )"
# Directory that contains source code for FFmpeg and its dependencies
# Each library has its own subdirectory
# Multiple versions of the same library can be stored inside librarie's directory
export SOURCES_DIR=${BASE_DIR}/sources
# Directory to place some statistics about the build.
# Currently - the info about Text Relocations
export STATS_DIR=${BASE_DIR}/stats
# Directory that contains helper scripts and
# scripts to download and build FFmpeg and each dependency separated by subdirectories
export SCRIPTS_DIR=${BASE_DIR}/scripts
# The directory to use by Android project
# All FFmpeg's libraries and headers are copied there
export OUTPUT_DIR=${BASE_DIR}/output
# Check the host machine for proper setup and fail fast otherwise
${SCRIPTS_DIR}/check-host-machine.sh || exit 1
# Directory to use as a place to build/install FFmpeg and its dependencies
BUILD_DIR=${BASE_DIR}/build
# Separate directory to build FFmpeg to
export BUILD_DIR_FFMPEG=$BUILD_DIR/ffmpeg
# All external libraries are installed to a single root
# to make easier referencing them when FFmpeg is being built.
export BUILD_DIR_EXTERNAL=$BUILD_DIR/external
# Function that copies *.so files and headers of the current ANDROID_ABI
# to the proper place inside OUTPUT_DIR
function prepareOutput() {
OUTPUT_LIB=${OUTPUT_DIR}/lib/${ANDROID_ABI}
mkdir -p ${OUTPUT_LIB}
LIB_DIR=${BUILD_DIR_FFMPEG}/${ANDROID_ABI}/lib
FOUND_LIBS=false
if compgen -G "${LIB_DIR}/*.so" > /dev/null; then
cp ${LIB_DIR}/*.so ${OUTPUT_LIB}
FOUND_LIBS=true
fi
if compgen -G "${LIB_DIR}/*.a" > /dev/null; then
cp ${LIB_DIR}/*.a ${OUTPUT_LIB}
FOUND_LIBS=true
fi
EXTERNAL_LIB_DIR=${BUILD_DIR_EXTERNAL}/${ANDROID_ABI}/lib
if [ -d "${EXTERNAL_LIB_DIR}" ]; then
if compgen -G "${EXTERNAL_LIB_DIR}/*.so" > /dev/null; then
cp ${EXTERNAL_LIB_DIR}/*.so ${OUTPUT_LIB}
fi
if compgen -G "${EXTERNAL_LIB_DIR}/*.a" > /dev/null; then
cp ${EXTERNAL_LIB_DIR}/*.a ${OUTPUT_LIB}
fi
# Some libs (e.g. liboapv) install static archives in subdirectories.
find "${EXTERNAL_LIB_DIR}" -mindepth 2 -type f -name '*.a' -exec cp {} ${OUTPUT_LIB} \;
fi
if [ "$FOUND_LIBS" = false ]; then
echo "No FFmpeg libraries found in ${LIB_DIR}"
exit 1
fi
OUTPUT_HEADERS=${OUTPUT_DIR}/include/${ANDROID_ABI}
mkdir -p ${OUTPUT_HEADERS}
cp -r ${BUILD_DIR_FFMPEG}/${ANDROID_ABI}/include/* ${OUTPUT_HEADERS}
}
# Saving stats about text relocation presence.
# If the result file doesn't have 'TEXTREL' at all, then we are good.
# Otherwise the whole script is interrupted
function checkTextRelocations() {
TEXT_REL_STATS_FILE=${STATS_DIR}/text-relocations.txt
LIB_DIR=${BUILD_DIR_FFMPEG}/${ANDROID_ABI}/lib
if compgen -G "${LIB_DIR}/*.so" > /dev/null; then
${FAM_READELF} --dynamic ${LIB_DIR}/*.so | grep 'TEXTREL\|File' >> ${TEXT_REL_STATS_FILE}
if grep -q TEXTREL ${TEXT_REL_STATS_FILE}; then
echo "There are text relocations in output files:"
cat ${TEXT_REL_STATS_FILE}
exit 1
fi
fi
}
# Actual work of the script
# Clearing previously created binaries
rm -rf ${BUILD_DIR}
rm -rf ${STATS_DIR}
rm -rf ${OUTPUT_DIR}
mkdir -p ${STATS_DIR}
mkdir -p ${OUTPUT_DIR}
# Exporting more necessary variabls
source ${SCRIPTS_DIR}/export-host-variables.sh
source ${SCRIPTS_DIR}/parse-arguments.sh
# Treating FFmpeg as just a module to build after its dependencies
COMPONENTS_TO_BUILD=${EXTERNAL_LIBRARIES[@]}
COMPONENTS_TO_BUILD+=( "ffmpeg" )
# Get the source code of component to build
for COMPONENT in ${COMPONENTS_TO_BUILD[@]}
do
echo "Getting source code of the component: ${COMPONENT}"
SOURCE_DIR_FOR_COMPONENT=${SOURCES_DIR}/${COMPONENT}
mkdir -p ${SOURCE_DIR_FOR_COMPONENT}
cd ${SOURCE_DIR_FOR_COMPONENT}
# Executing the component-specific script for downloading the source code
source ${SCRIPTS_DIR}/${COMPONENT}/download.sh
# The download.sh script has to export SOURCES_DIR_$COMPONENT variable
# with actual path of the source code. This is done for possiblity to switch
# between different verions of a component.
# If it isn't set, consider SOURCE_DIR_FOR_COMPONENT as the proper value
COMPONENT_SOURCES_DIR_VARIABLE=SOURCES_DIR_${COMPONENT}
if [[ -z "${!COMPONENT_SOURCES_DIR_VARIABLE}" ]]; then
export SOURCES_DIR_${COMPONENT}=${SOURCE_DIR_FOR_COMPONENT}
fi
# Returning to the rood directory. Just in case.
cd ${BASE_DIR}
done
# Main build loop
for ABI in ${FFMPEG_ABIS_TO_BUILD[@]}
do
# Exporting variables for the current ABI
source ${SCRIPTS_DIR}/export-build-variables.sh ${ABI}
for COMPONENT in ${COMPONENTS_TO_BUILD[@]}
do
echo "Building the component: ${COMPONENT}"
COMPONENT_SOURCES_DIR_VARIABLE=SOURCES_DIR_${COMPONENT}
# Going to the actual source code directory of the current component
cd ${!COMPONENT_SOURCES_DIR_VARIABLE}
# and executing the component-specific build script
source ${SCRIPTS_DIR}/${COMPONENT}/build.sh || exit 1
# Returning to the root directory. Just in case.
cd ${BASE_DIR}
done
checkTextRelocations || exit 1
prepareOutput
done