embed-MacOSX-dependencies.sh 4.48 KB
Newer Older
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/bin/sh
#
# This script finds all of the dependecies from Fink and included them into
# the Pd.app.  <hans@at.or.at>
#
# run it in the root directory where the externals are stored, i.e. "extra"

    
if [ $# -ne 1 ]; then
	echo "Usage: $0 Pd.app-Contents"
	echo "  i.e. $0 /Applications/Pd.app/Contents/"
	exit
fi

LIB_DIR=lib
PD_APP_CONTENTS=$1
PD_APP_LIB=$PD_APP_CONTENTS/$LIB_DIR

#echo "PD_APP_CONTENTS: $PD_APP_CONTENTS"
#echo "PD_APP_LIB: $PD_APP_LIB"

echo " "

for pd_darwin in `find $PD_APP_CONTENTS -name '*.pd_darwin'`; do
25
	LIBS=`otool -L $pd_darwin | sed -n 's|.*/usr/local/opt/\(.*\.dylib\).*|\1|p'`
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
26 27 28 29 30
	if [ "x$LIBS" != "x" ]; then
		echo "`echo $pd_darwin | sed 's|.*/\(.*\.pd_darwin$\)|\1|'` is using:"
		for lib in $LIBS; do
			echo "    $lib"
			install -d $PD_APP_LIB
31
			install -p /usr/local/opt/$lib $PD_APP_LIB/$(basename $lib)
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
32
			new_lib=`echo $lib | sed 's|.*/\(.*\.dylib\)|\1|'`
33 34
			# @executable_path starts from Contents/Resources/app.nw/bin/pd
			install_name_tool -id @executable_path/../../../$LIB_DIR/$new_lib $PD_APP_LIB/$new_lib
35
			install_name_tool -change /usr/local/opt/$lib @executable_path/../../../$LIB_DIR/$new_lib $pd_darwin
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
36 37 38 39 40 41 42
		done
		echo " "
	fi
done

# check for .so plugins used by libquicktime and others
for so in $PD_APP_LIB/*/*.so; do
43
	LIBS=`otool -L $so | sed -n 's|.*/usr/local/opt/\(.*\.dylib\).*|\1|p'`
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
44 45 46 47 48 49 50 51
	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
52
				install -vp /usr/local/opt/$lib $PD_APP_LIB
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
53 54
			fi
			# @executable_path starts from Contents/Resources/bin/pd
55
			install_name_tool -change /usr/local/opt/$lib @executable_path/../../../$LIB_DIR/$new_lib $so
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
56 57 58 59 60 61
		done
		echo " "
	fi
done

for dylib in $PD_APP_LIB/*.dylib; do
62
	LIBS=`otool -L $dylib | sed -n 's|.*/usr/local/opt/\(.*\.dylib\).*|\1|p'`
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
63 64 65 66 67 68 69 70
	if [ "x$LIBS" != "x" ]; then
		echo "`echo $dylib | sed 's|.*/\(.*\.dylib\)|\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
71
				install -vp /usr/local/opt/$lib $PD_APP_LIB
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
72 73
			fi
			# @executable_path starts from Contents/Resources/bin/pd
74
			install_name_tool -id @executable_path/../../../$LIB_DIR/$new_lib $PD_APP_LIB/$new_lib
75
			install_name_tool -change /usr/local/opt/$lib @executable_path/../../../$LIB_DIR/$new_lib $dylib
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
76 77 78 79 80
		done
		echo " "
	fi
done

81
# run it again to catch dylibs that depend on dylibs located in /usr/local/
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
82
for dylib in $PD_APP_LIB/*.dylib; do
83
	LIBS=`otool -L $dylib | sed -n 's|.*/usr/local/\(.*\.dylib\).*|\1|p'`
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
84 85 86 87 88 89 90 91
	if [ "x$LIBS" != "x" ]; then
		echo "`echo $dylib | sed 's|.*/\(.*\.dylib\)|\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
92
				install -vp /usr/local/$lib $PD_APP_LIB
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
93
			fi
94 95
			# @executable_path starts from Contents/Resources/app.nw/bin/pd
			install_name_tool -id @executable_path/../../../$LIB_DIR/$new_lib $PD_APP_LIB/$new_lib
96
			install_name_tool -change /usr/local/$lib @executable_path/../../../$LIB_DIR/$new_lib $dylib
Ivica Ico Bukvic's avatar
Ivica Ico Bukvic committed
97 98 99 100 101
		done
		echo " "
	fi
done

102
# finally, run it one more time to catch dylibs that depend on dylibs from
103
# /usr/local/
104
for dylib in $PD_APP_LIB/*.dylib; do
105
        LIBS=`otool -L $dylib | sed -n 's|.*/usr/local/\(.*\.dylib\).*|\1|p'`
106 107 108 109 110 111 112 113
        if [ "x$LIBS" != "x" ]; then
                echo "`echo $dylib | sed 's|.*/\(.*\.dylib\)|\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
114
                                install -vp /usr/local/$lib $PD_APP_LIB
115 116 117
                        fi
                        # @executable_path starts from Contents/Resources/app.nw/bin/pd
                        install_name_tool -id @executable_path/../../../$LIB_DIR/$new_lib $PD_APP_LIB/$new_lib
118
                        install_name_tool -change /usr/local/$lib @executable_path/../../../$LIB_DIR/$new_lib $dylib
119 120 121 122
                done
                echo " "
        fi
done