From cee40e1e6996bb2b722cc02e0273a5847f128f9b Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
Date: Wed, 1 Sep 2021 12:42:41 -0400
Subject: [PATCH] debian: rules: Fix FFmpeg linking issues on Ubuntu.

* packaging/rules/debian/rules (LDFLAGS): Filter out the
-Bsymbolic-functions linker option added by default on Ubuntu.
[ubuntu_21.04]: Do not force the bundling of FFmpeg.

Change-Id: Ia83c305808072a4e5923530421924eb85f9b5b5e
---
 packaging/rules/debian/rules | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/packaging/rules/debian/rules b/packaging/rules/debian/rules
index de15c8c1..276f2f87 100755
--- a/packaging/rules/debian/rules
+++ b/packaging/rules/debian/rules
@@ -6,6 +6,15 @@ export DEB_BUILD_MAINT_OPTIONS = hardening=+all
 DPKG_EXPORT_BUILDFLAGS = 1
 include /usr/share/dpkg/buildflags.mk
 
+# Ubuntu defaults to use -Bsymbolic-functions, which breaks linking
+# shared objects with static FFmpeg archives (see:
+# https://bugs.launchpad.net/ubuntu/+source/ffmpeg/+bug/1942352).
+ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes),yes)
+ifneq (,$(LDFLAGS))
+  LDFLAGS := $(filter-out %-Bsymbolic-functions,$(LDFLAGS))
+endif
+endif
+
 # Number of CPUS
 NO_CPUS=$(shell nproc)
 ifeq ($(NO_CPUS),0)
@@ -30,10 +39,6 @@ CMAKE_OPTIONS=-DCHOST=${HOST_ARCH} \
   -DCMAKE_CXX_COMPILER=${HOST_ARCH}-g++ \
   -DCMAKE_FIND_ROOT_PATH=/usr/${HOST_ARCH} \
   -DPKG_CONFIG_EXECUTABLE=/usr/bin/${HOST_ARCH}-pkg-config
-else
-ifneq (ubuntu_21.04,$(findstring ubuntu_21.04, $(DISTRIBUTION)))
-BUNDLED_PKGS="--enable-ffmpeg" # For ubuntu 21.04 it seems there is massive issues with linking for swscale
-endif
 endif
 
 # Qt-related variables
-- 
GitLab