From 9ef88402d791fea697b79f2cf50f362e4e594d63 Mon Sep 17 00:00:00 2001
From: Albert Graef <aggraef@gmail.com>
Date: Wed, 24 Aug 2022 11:20:33 +0200
Subject: [PATCH] Check for a custom libquicktime-ffmpeg package.

---
 .../darwin_app/embed-MacOSX-dependencies.sh   | 34 +++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/packages/darwin_app/embed-MacOSX-dependencies.sh b/packages/darwin_app/embed-MacOSX-dependencies.sh
index 7109c9734..1d4e53e3b 100755
--- a/packages/darwin_app/embed-MacOSX-dependencies.sh
+++ b/packages/darwin_app/embed-MacOSX-dependencies.sh
@@ -51,9 +51,22 @@ for pd_darwin in `find $PD_APP_CONTENTS -name '*.pd_darwin'`; do
 	fi
 done
 
-# check for .so plugins used by libquicktime and others
+# check for libquicktime plugins, copy them over
 rm -rf $PD_APP_PLUGINS/libquicktime
-test -d ${optlocal}/libquicktime/lib/libquicktime && cp -r ${optlocal}/libquicktime/lib/libquicktime $PD_APP_PLUGINS || true
+libqt_ffmpeg_plugins=${optlocal}/libquicktime-ffmpeg/lib/libquicktime
+libqt_plugins=${optlocal}/libquicktime/lib/libquicktime
+# prefer libquicktime-ffmpeg, in case we have both installed
+if test -d ${libqt_ffmpeg_plugins}; then
+    cp -r ${libqt_ffmpeg_plugins} $PD_APP_PLUGINS
+elif test -d ${libqt_plugins}; then
+    cp -r ${libqt_plugins} $PD_APP_PLUGINS
+elif [ "$optlocal" != "/opt/local" ]; then
+    echo "No libquicktime found, did you install it?" >&2
+fi
+# change permissions so that install_name can write to the plugin files
+chmod -fR u+xw $PD_APP_PLUGINS/libquicktime
+
+# check for .so plugins used by libquicktime and others
 for so in $PD_APP_PLUGINS/*/*.so; do
 	LIBS=`otool -L $so | sed -n 's|.*'"${optlocal}"'/\(.*\.dylib\).*|\1|p'`
 	if [ "x$LIBS" != "x" ]; then
@@ -71,6 +84,23 @@ for so in $PD_APP_PLUGINS/*/*.so; do
 		done
 		echo " "
 	fi
+	# Homebrew also has some libraries in its cellar (keg-only package?).
+	LIBS=`otool -L $so | sed -n 's|.*'"/usr/local/Cellar"'/\(.*\.dylib\).*|\1|p'`
+	if [ "x$LIBS" != "x" ]; then
+		echo "`echo $so | sed 's|.*/\(lib.*/.*\.so\)|\1|'` is using:"
+		for lib in $LIBS; do
+			echo "    $lib"
+			new_lib=`echo $lib | sed 's|.*/\(.*\.dylib\)|\1|'`
+			if [ -e  $PD_APP_LIB/$new_lib ]; then
+				echo "$PD_APP_LIB/$new_lib already exists, skipping copy."
+			else
+				install -vp /usr/local/Cellar/$lib $PD_APP_LIB
+			fi
+			# @executable_path starts from Contents/Resources/app.nw/bin
+			install_name_tool -change /usr/local/Cellar/$lib @executable_path/../../../$LIB_DIR/$new_lib $so
+		done
+		echo " "
+	fi
 done
 
 for dylib in $PD_APP_LIB/*.dylib; do
-- 
GitLab