1+ #! /usr/bin/env bash
2+ #
3+ # Copyright (C) 2021 Matt Reach<[email protected] >4+
5+ # Licensed under the Apache License, Version 2.0 (the "License");
6+ # you may not use this file except in compliance with the License.
7+ # You may obtain a copy of the License at
8+ #
9+ # http://www.apache.org/licenses/LICENSE-2.0
10+ #
11+ # Unless required by applicable law or agreed to in writing, software
12+ # distributed under the License is distributed on an "AS IS" BASIS,
13+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ # See the License for the specific language governing permissions and
15+ # limitations under the License.
16+ #
17+
18+ # This script is based on projects below
19+ # https://github.com/bilibili/ijkplayer
20+
21+ set -e
22+
23+ error_handler () {
24+ echo " An error occurred!"
25+ tail -n20 ${MR_BUILD_SOURCE} /ffbuild/config.log
26+ }
27+
28+ trap ' error_handler' ERR
29+
30+ THIS_DIR=$( DIRNAME=$( dirname " $0 " ) ; cd " $DIRNAME " ; pwd)
31+ cd " $THIS_DIR "
32+
33+ export COMMON_FF_CFG_FLAGS=
34+ # use ijk ffmpeg config options
35+ source $MR_SHELL_CONFIGS_DIR /ijk-ffmpeg-config/module.sh
36+
37+ FFMPEG_CFG_FLAGS=
38+ FFMPEG_CFG_FLAGS=" $FFMPEG_CFG_FLAGS $COMMON_FF_CFG_FLAGS "
39+
40+ # Advanced options (experts only):
41+ FFMPEG_CFG_FLAGS=" $FFMPEG_CFG_FLAGS --enable-cross-compile"
42+ # --disable-symver may indicate a bug
43+ # FFMPEG_CFG_FLAGS="$FFMPEG_CFG_FLAGS --disable-symver"
44+
45+ # Developer options (useful when working on FFmpeg itself):
46+ FFMPEG_CFG_FLAGS=" $FFMPEG_CFG_FLAGS --disable-stripping"
47+
48+ # #
49+ FFMPEG_CFG_FLAGS=" $FFMPEG_CFG_FLAGS --arch=$MR_FF_ARCH "
50+ FFMPEG_CFG_FLAGS=" $FFMPEG_CFG_FLAGS --target-os=$MR_TAGET_OS "
51+ FFMPEG_CFG_FLAGS=" $FFMPEG_CFG_FLAGS --enable-static"
52+ FFMPEG_CFG_FLAGS=" $FFMPEG_CFG_FLAGS --disable-shared"
53+ # FFMPEG_CFG_FLAGS="$FFMPEG_CFG_FLAGS --pkg-config-flags=--static"
54+ FFMPEG_EXTRA_CFLAGS=
55+
56+ # i386, x86_64
57+ FFMPEG_CFG_FLAGS_SIMULATOR=
58+ FFMPEG_CFG_FLAGS_SIMULATOR=" $FFMPEG_CFG_FLAGS_SIMULATOR --disable-asm"
59+ FFMPEG_CFG_FLAGS_SIMULATOR=" $FFMPEG_CFG_FLAGS_SIMULATOR --disable-mmx"
60+ FFMPEG_CFG_FLAGS_SIMULATOR=" $FFMPEG_CFG_FLAGS_SIMULATOR --assert-level=2"
61+
62+ # armv7, armv7s, arm64
63+ FFMPEG_CFG_FLAGS_ARM=
64+ FFMPEG_CFG_FLAGS_ARM=" $FFMPEG_CFG_FLAGS_ARM --enable-pic"
65+ FFMPEG_CFG_FLAGS_ARM=" $FFMPEG_CFG_FLAGS_ARM --enable-neon"
66+ case " $MR_DEBUG " in
67+ debug)
68+ FFMPEG_CFG_FLAGS_ARM=" $FFMPEG_CFG_FLAGS_ARM --disable-optimizations"
69+ FFMPEG_CFG_FLAGS_ARM=" $FFMPEG_CFG_FLAGS_ARM --enable-debug"
70+ FFMPEG_CFG_FLAGS_ARM=" $FFMPEG_CFG_FLAGS_ARM --disable-small"
71+ ;;
72+ * )
73+ FFMPEG_CFG_FLAGS_ARM=" $FFMPEG_CFG_FLAGS_ARM --enable-optimizations"
74+ FFMPEG_CFG_FLAGS_ARM=" $FFMPEG_CFG_FLAGS_ARM --enable-debug"
75+ FFMPEG_CFG_FLAGS_ARM=" $FFMPEG_CFG_FLAGS_ARM --enable-small"
76+ ;;
77+ esac
78+
79+ FFMPEG_CFG_FLAGS=" $FFMPEG_CFG_FLAGS --prefix=$MR_BUILD_PREFIX "
80+
81+ FFMPEG_CFLAGS=" $MR_DEFAULT_CFLAGS "
82+ FFMPEG_LDFLAGS=" $FFMPEG_CFLAGS "
83+ FFMPEG_DEP_LIBS=
84+
85+ # libavformat/tls_openssl.c:56:16: error: use of undeclared identifier 'CRYPTO_LOCK'; did you mean 'CRYPTO_free'?
86+ # if (mode & CRYPTO_LOCK)
87+ # ^~~~~~~~~~~
88+ # CRYPTO_free
89+
90+ pkg-config --libs openssl --silence-errors > /dev/null && enable_openssl=1
91+
92+ if [[ $enable_openssl ]]; then
93+ echo " [✅] --enable-openssl : $( pkg-config --modversion openssl) "
94+ FFMPEG_CFG_FLAGS=" $FFMPEG_CFG_FLAGS --enable-openssl"
95+ else
96+ echo " [❌] --disable-openssl"
97+ fi
98+
99+ # --------------------
100+ echo " --------------------"
101+ echo " [*] configure"
102+ echo " ----------------------"
103+
104+ if [ ! -d $MR_BUILD_SOURCE ]; then
105+ echo " "
106+ echo " !! ERROR"
107+ echo " !! Can not find FFmpeg directory for $FF_BUILD_NAME "
108+ echo " !! Run 'sh init-ios.sh' first"
109+ echo " "
110+ exit 1
111+ fi
112+
113+ cd $MR_BUILD_SOURCE
114+ if [ -f " ./config.h" ]; then
115+ echo ' reuse configure'
116+ else
117+ echo
118+ echo " CC: $MR_TRIPLE_CC "
119+ echo " CFLAGS: $FFMPEG_CFLAGS "
120+ echo " LDFLAG:$FFMPEG_LDFLAGS "
121+ echo " DEP_LIBS: $FFMPEG_DEP_LIBS "
122+ echo " FF_CFG_FLAGS: $FFMPEG_CFG_FLAGS "
123+ echo
124+
125+ ./configure \
126+ $FFMPEG_CFG_FLAGS \
127+ --cc=${MR_TRIPLE_CC} \
128+ --as=${MR_TRIPLE_CC} \
129+ --ld=${MR_TRIPLE_CC} \
130+ --ar=${MR_AR} \
131+ --nm=${MR_NM} \
132+ --strip=${MR_STRIP} \
133+ --ranlib=${MR_RANLIB} \
134+ --extra-cflags=" $FFMPEG_CFLAGS " \
135+ --extra-cxxflags=" $FFMPEG_CFLAGS " \
136+ --extra-ldflags=" $FFMPEG_LDFLAGS $FFMPEG_DEP_LIBS "
137+ fi
138+
139+ # --------------------
140+ echo " --------------------"
141+ echo " [*] compile ffmpeg"
142+ echo " --------------------"
143+
144+ make -j$MR_HOST_NPROC > /dev/null
145+ cp config.* $MR_BUILD_PREFIX
146+ make install > /dev/null
147+ mkdir -p $MR_BUILD_PREFIX /include/libffmpeg
148+ cp -f config.h $MR_BUILD_PREFIX /include/libffmpeg/config.h
0 commit comments