diff --git a/packaging/osx/OpenRA.app/Contents/MacOS/OpenRA b/packaging/osx/OpenRA.app/Contents/MacOS/OpenRA index 0fc1636097..82b998fb0b 100755 --- a/packaging/osx/OpenRA.app/Contents/MacOS/OpenRA +++ b/packaging/osx/OpenRA.app/Contents/MacOS/OpenRA @@ -1,16 +1,17 @@ #!/bin/bash # Where is the game we are trying to load? -GAME_DIR="/Users/paul/src/OpenRA/" +GAME_PATH="/Users/paul/src/OpenRA/" # Find where we are and what we want to run APP_PATH=`echo $0 | awk '{split($0,patharr,"/"); idx=1; while(patharr[idx+3] != "") { if (patharr[idx] != "/") {printf("%s/", patharr[idx]); idx++ }} }'` -EXE_DIR="$APP_PATH/Contents/MacOS/" +EXE_PATH="$APP_PATH/Contents/MacOS/" + +# Override paths within mono to avoid string-hacking the executable +export LD_LIBRARY_PATH="$EXE_PATH/lib" +export MONO_PATH="$EXE_PATH/lib" +#export MONO_LOG_LEVEL=debug -# Override paths so mono can find itself and the libraries it depends on -export MONO_PATH="$APP_PATH/Contents/Frameworks/Mono.framework/Versions/2.6.3/lib/" -export LD_LIBRARY_PATH="$MONO":"$MONO_PATH" -export MONO_LOG_LEVEL=debug # Run the game -cd $GAME_DIR -${EXE_DIR}mono OpenRA.Game.exe \ No newline at end of file +cd $GAME_PATH +${EXE_PATH}mono OpenRA.Game.exe \ No newline at end of file diff --git a/packaging/osx/package.sh b/packaging/osx/package.sh index 5357e00df3..d05ac8a027 100755 --- a/packaging/osx/package.sh +++ b/packaging/osx/package.sh @@ -1,41 +1,45 @@ #!/bin/sh # OpenRA Packaging script for osx -# Creates a .app bundle for OpenRA -# Patches and packages mono to work from within the app bundle +# Creates a self contained app bundle that contains +# all the dependencies required to run the game. +# This script assumes that it is being run on osx >= 10.5 +# and that all the required dependencies are installed +# and the dependant dlls exist in the system GAC. +# $GAME_PATH in OpenRA.app/Contents/MacOS/OpenRA +# specifies the game directory to load. This can point +# anywhere on the filesystem. -# A list of the binaries that may contain references to dependencies in the gac +# A list of the binaries that we want to be able to run DEPS_LOCAL="OpenRA.Game.exe OpenRA.Gl.dll OpenRA.FileFormats.dll" - -# A list of external dependencies, (aside from mono) -# Note: references to frameworks are currently hardcoded in the .config hacking step -DEPS_FRAMEWORKS="/Library/Frameworks/Cg.framework /Library/Frameworks/SDL.framework" - PACKAGING_DIR="osxbuild" SYSTEM_MONO="/Library/Frameworks/Mono.framework/Versions/2.6.3" -LOCAL_MONO="$PACKAGING_DIR/OpenRA.app/Contents/Frameworks/Mono.framework/Versions/2.6.3" - - -# Todo: make this go away when we kill the gac stuff # dylibs referred to by dlls in the gac; won't show up to otool GAC_DYLIBS="$SYSTEM_MONO/lib/libMonoPosixHelper.dylib $SYSTEM_MONO/lib/libgdiplus.dylib " - - -mkdir -p $PACKAGING_DIR/OpenRA.app/ -cp -r ./packaging/osx/OpenRA.app/* $PACKAGING_DIR/OpenRA.app/ +#################################################################################### +EXE_DIR="$PACKAGING_DIR/OpenRA.app/Contents/MacOS" +LIB_DIR="$EXE_DIR/lib" function patch_mono { - echo "Patching: "$1 + echo "Patching binary: "$1 LIBS=$( otool -L $1 | grep /Library/Frameworks/Mono.framework/ | awk {'print $1'} ) + # Todo: fix the -id? for i in $LIBS; do - install_name_tool -change $i @executable_path/../${i:9} $1 + install_name_tool -change $i @executable_path/lib/`basename $i` $1 done + + # If it still matches then we also need to change the id + LIBS2=$( otool -L $1 | grep /Library/Frameworks/Mono.framework/ | awk {'print $1'} ) + for i in $LIBS2; do + install_name_tool -id @executable_path/lib/`basename $i` $1 + done + for i in $LIBS; do - if [ ! -e $PACKAGING_DIR/OpenRA.app/Contents/${i:9} ]; then - mkdir -p $PACKAGING_DIR/OpenRA.app/Contents/`dirname ${i:9}` - cp $i $PACKAGING_DIR/OpenRA.app/Contents/`dirname ${i:9}` - patch_mono $PACKAGING_DIR/OpenRA.app/Contents/${i:9} + FILE=`basename $i` + if [ ! -e $LIB_DIR/$FILE ]; then + cp $i $LIB_DIR + patch_mono $LIB_DIR/$FILE fi done } @@ -48,53 +52,60 @@ export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/Library/Frameworks/Mono.framework/Versi export PATH=/sw/bin:/sw/sbin:$PATH # Copy and patch mono -echo "Copying and patching mono..." +echo "Creating app bundle..." -mkdir -p "$LOCAL_MONO/bin/" -cp "$SYSTEM_MONO/bin/mono" "$PACKAGING_DIR/OpenRA.app/Contents/MacOS/" -patch_mono "$PACKAGING_DIR/OpenRA.app/Contents/MacOS/mono" + +# Create the directory tree and copy in our existing files +mkdir -p $PACKAGING_DIR/OpenRA.app +cp -r ./packaging/osx/OpenRA.app/* $PACKAGING_DIR/OpenRA.app/ +mkdir -p $LIB_DIR + + +cp "$SYSTEM_MONO/bin/mono" $EXE_DIR +patch_mono "$EXE_DIR/mono" # Copy the gac dylibs into the app bundle for i in $GAC_DYLIBS; do - mkdir -p $PACKAGING_DIR/OpenRA.app/Contents/`dirname ${i:9}` - cp $i $PACKAGING_DIR/OpenRA.app/Contents/`dirname ${i:9}` - patch_mono $PACKAGING_DIR/OpenRA.app/Contents/${i:9} + cp $i $LIB_DIR + patch_mono $LIB_DIR/`basename $i` done # Find the dlls that are used by the game; copy them into the app bundle and patch/package any dependencies -echo "Determining dlls used by the game..." +echo "Searching for dlls..." -DLL_DIR="$LOCAL_MONO/lib" - -# This is a huge hack, but reliably gets us the dlls to include +# This is a huge hack, but it works DLLS=`mkbundle --deps --static -z -c -o OpenRA $DEPS_LOCAL | grep "embedding: "` for i in $DLLS; do if [ "$i" != "embedding:" ]; then - cp $i $DLL_DIR + cp $i $LIB_DIR if [ -e "$i.config" ]; then - CONFIG="$DLL_DIR/`basename $i`.config" - echo "Patching config `basename $CONFIG`" + CONFIG=$LIB_DIR/"`basename $i`.config" + + echo "Patching config: $CONFIG" # Remove any references to the hardcoded mono framework; the game will look in the right location anyway - #sed "s/\/Library\/Frameworks\/Mono.framework\/Versions\/2.6.3\/lib\///" "$i.config" > "${CONFIG}_1" - sed "s/\/Library\/Frameworks\/Mono.framework/..\/Mono.framework/" "$i.config" > "${CONFIG}" -# sed "s/\/Library\/Frameworks\/Cg.framework/..\/Cg.framework/" "${CONFIG}_1" > "${CONFIG}_2" -# sed "s/\/Library\/Frameworks\/SDL.framework/..\/SDL.framework/" "${CONFIG}_2" > $CONFIG -# rm "${CONFIG}_1" "${CONFIG}_2" + sed "s/\/Library\/Frameworks\/Mono.framework\/Versions\/2.6.3\///" "$i.config" > "${CONFIG}_1" + sed "s/\/Library\/Frameworks\/Cg.framework/lib/" "${CONFIG}_1" > "${CONFIG}_2" + sed "s/\/Library\/Frameworks\/SDL.framework/lib/" "${CONFIG}_2" > $CONFIG + rm "${CONFIG}_1" "${CONFIG}_2" fi fi done - -# Remove the files themselves that we accidentally copied over +# Remove the files that we want to run that we accidentally copied over for i in $DEPS_LOCAL; do - rm "$DLL_DIR/$i" + rm "$LIB_DIR/$i" done + # Copy external frameworks -#echo "Copying external frameworks..." -#for i in $DEPS_FRAMEWORKS; do -# cp -RL $i $PACKAGING_DIR/OpenRA.app/Contents/${i:9} -#done +echo "Copying Cg..." +cp /Library/Frameworks/Cg.framework/Cg $LIB_DIR +chmod 755 $LIB_DIR/Cg + +echo "Copying SDL..." +cp /Library/Frameworks/SDL.framework/SDL $LIB_DIR +xattr -d com.apple.quarantine $LIB_DIR/SDL +chmod 755 $LIB_DIR/SDL echo "All Done!"