@@ -44,15 +44,22 @@ if command -v nproc >/dev/null 2>&1; then JOBS="$(nproc)"; else JOBS="$(sysctl -
4444# --- per-target toolchain configuration ---------------------------------------------------
4545CROSS_FLAGS=() # extra ffmpeg ./configure flags
4646OPUS_HOST_FLAGS=() # extra libopus ./configure flags
47+ OPUS_CFLAGS=" " # extra CFLAGS for the opus build ("" = use opus defaults)
48+ FF_EXTRA_CFLAGS=" " # appended to ffmpeg --extra-cflags
4749BIN_NAME=" ffmpeg"
4850case " $TARGET " in
4951 win32-x64)
5052 CROSS_PREFIX=" x86_64-w64-mingw32-"
5153 CROSS_FLAGS=(--arch=x86_64 --target-os=mingw32 " --cross-prefix=${CROSS_PREFIX} " --pkg-config=pkg-config)
52- # --disable-hardening: opus enables -fstack-protector-strong by default, which on mingw
53- # references __stack_chk_* from libssp that opus.pc doesn't advertise. FFmpeg's static
54- # link test for opus would then fail to link and report "opus not found using pkg-config".
5554 OPUS_HOST_FLAGS=(--host=x86_64-w64-mingw32 --disable-hardening)
55+ # Debian/Ubuntu patch their mingw-w64 gcc to default -fstack-protector-strong and
56+ # _FORTIFY_SOURCE=2. Those inject __stack_chk_*/__memcpy_chk references (normally
57+ # satisfied by libssp) into libopus.a and the ffmpeg objects, breaking the static link
58+ # — FFmpeg's opus link test then fails with the misleading "opus not found using
59+ # pkg-config". Turn both off for the cross build (opus's --disable-hardening alone does
60+ # not counter the compiler default). Harmless on toolchains that don't default them on.
61+ OPUS_CFLAGS=" -O2 -fno-stack-protector -D_FORTIFY_SOURCE=0"
62+ FF_EXTRA_CFLAGS=" -fno-stack-protector -D_FORTIFY_SOURCE=0"
5663 BIN_NAME=" ffmpeg.exe"
5764 ;;
5865 darwin-arm64|darwin-x64|linux-x64|linux-arm64)
@@ -67,9 +74,11 @@ cd "$WORK"
6774echo " ::group::build libopus $OPUS_VERSION "
6875curl -fsSL -o opus.tar.gz " https://downloads.xiph.org/releases/opus/opus-${OPUS_VERSION} .tar.gz"
6976tar xf opus.tar.gz && cd " opus-${OPUS_VERSION} "
77+ if [ -n " $OPUS_CFLAGS " ]; then export CFLAGS=" $OPUS_CFLAGS " ; fi
7078./configure --prefix=" $PREFIX " --disable-shared --enable-static --disable-doc \
7179 --disable-extra-programs ${OPUS_HOST_FLAGS[@]+" ${OPUS_HOST_FLAGS[@]} " }
7280make -j" $JOBS " && make install
81+ unset CFLAGS # don't leak opus CFLAGS into the ffmpeg build (it uses --extra-cflags)
7382cd " $WORK "
7483echo " ::endgroup::"
7584
@@ -82,7 +91,7 @@ trap 'status=$?; if [ "$status" -ne 0 ]; then echo "::group::ffbuild/config.log
8291./configure \
8392 --prefix=" $PREFIX " \
8493 --pkg-config-flags=" --static" \
85- --extra-cflags=" -I$PREFIX /include" \
94+ --extra-cflags=" -I$PREFIX /include $FF_EXTRA_CFLAGS " \
8695 --extra-ldflags=" -L$PREFIX /lib" \
8796 --enable-static --disable-shared \
8897 --disable-gpl --disable-nonfree \
0 commit comments