1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
# This script copies the .dylib files DarkRadiant is depending on to the bundle's MacOS folder.
# Secondly, it's fixing up the dylib references in all the binaries recursively, replacing
# the hardcoded /opt/local/* paths with @executable_path, making use of otool and install_name_tool
echo Building Package in $TARGET_BUILD_DIR
cd $TARGET_BUILD_DIR
cd DarkRadiant.app/Contents/MacOS
# Copy wxwidgets dependencies
WXLIBPOSTFIX=*wx*3.0.0.dylib
APP=DarkRadiantMain
WXLIBDIR=/opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/lib/
BINDIR=./
LIBDEFDIR=/opt/local/Library/Frameworks/wxWidgets.framework/Versions/wxWidgets/3.0/lib/
echo "Copying dynamic libraries to " $BINDIR " ..."
cp $WXLIBDIR/*wx*3.0.0.dylib $BINDIR
echo "Changing directory to " $BINDIR " ..."
export TMP=$PWD
cd $BINDIR
function fetchLibraries()
{
# The lib we're inspecting
local file=$1
local targetDir=$2
# Fetch all the other libs referenced in /opt/local/lib
# e.g. /opt/local/lib/libftgl.2.dylib
local fileRegex=(\(/opt/local/lib/\(.*.dylib\)\))
echo "Inspecting binary " $file
for dependency in `otool -L $file`
do
if [[ $dependency =~ $fileRegex ]];
then
#echo ${BASH_REMATCH[0]} ${BASH_REMATCH[1]} ${BASH_REMATCH[2]}
local dependencyPath=${BASH_REMATCH[1]}
local filename=${BASH_REMATCH[2]}
local fetchedFile=$targetDir$filename
echo "==> " $file " depends on " $filename
if [ ! -f $fetchedFile ]
then
echo Fetching ${BASH_REMATCH[0]} to $targetDir...
cp $dependencyPath $targetDir
echo "Fixing ID of file " $fetchedFile
echo install_name_tool -id @executable_path/$filename $fetchedFile
install_name_tool -id @executable_path/$filename $fetchedFile
else
echo $fetchedFile already exists
fi
echo "Fixing link in referencing file " $file
echo install_name_tool -change ${BASH_REMATCH[1]} @executable_path/$filename $file
install_name_tool -change ${BASH_REMATCH[1]} @executable_path/$filename $file
echo "Entering recursion for lib " $fetchedFile
fetchLibraries $fetchedFile $targetDir
fi
done
}
# patch all wx dynlibs and the main executable
for file in `ls $WXLIBPOSTFIX`
do
# patch all library internal cross references
echo "Patching " $file "..."
for fileother in `ls $WXLIBPOSTFIX `
do
# library
echo " Patching " $fileother " with " $file "..."
install_name_tool -change $LIBDEFDIR/$file @executable_path/$file $fileother
done
# patch current library itself
install_name_tool -id @executable_path/$file $file
# patch executable
install_name_tool -change $LIBDEFDIR$file @executable_path/$file $APP
# Resolve the 3.0.0.2.0 version issue
fileRegex=(\(libwx_[A-Za-z_]+-\)\(\([0-9]\.[0-9]\.[0-9]\)\.[0-9]\.[0-9]\)\.dylib)
for dependency in `otool -L $file`
do
if [[ $dependency =~ $fileRegex ]];
then
echo Replacing ${BASH_REMATCH[0]} with ${BASH_REMATCH[1]}3.0.0.dylib...
install_name_tool -change $LIBDEFDIR${BASH_REMATCH[0]} @executable_path/${BASH_REMATCH[1]}3.0.0.dylib $file
fi
done
# Fetch referenced libraries
fetchLibraries $file $BINDIR
done
echo Patching Main Executable $APP
#pwd
#otool -L $APP
# Replace the 3.0 version references with 3.0.0 ones
fileRegex=(\(libwx_[A-Za-z_]+-\)\([0-9]\.[0-9]\)\.dylib)
for dependency in `otool -L $APP`
do
if [[ $dependency =~ $fileRegex ]];
then
echo Replacing ${BASH_REMATCH[0]} with ${BASH_REMATCH[1]}3.0.0.dylib...
install_name_tool -change $LIBDEFDIR${BASH_REMATCH[0]} @executable_path/${BASH_REMATCH[1]}3.0.0.dylib $APP
fi
done
# Fetch dependencies from /opt/local
fetchLibraries $APP $BINDIR
# Patch all plugins
for plugin in `ls *.so`
do
echo Patching $plugin...
# wx library dependency
fileRegex=(\(libwx_[A-Za-z_]+-\)\([0-9]\.[0-9]\)\.dylib)
for dependency in `otool -L $plugin`
do
if [[ $dependency =~ $fileRegex ]];
then
echo Replacing ${BASH_REMATCH[0]} with ${BASH_REMATCH[1]}3.0.0.dylib...
install_name_tool -change $LIBDEFDIR${BASH_REMATCH[0]} @executable_path/${BASH_REMATCH[1]}3.0.0.dylib $plugin
fi
done
# Fetch all the other libs referenced in /opt/local/lib
fetchLibraries $plugin $BINDIR
done
cd $TMP
|