# The name of the executable
app=$1
# Create a directory to hold the app and dependencies
mkdir -p "MyApp.app/Contents/MacOS"
mkdir -p "MyApp.app/Contents/libs"
# Copy the app into the MacOS directory
cp $app "MyApp.app/Contents/MacOS/"
# Get the dependencies
dependencies=$(otool -L $app | awk 'NR>1{print $1}')
# Copy the dependencies into the libs directory and rename them
for dep in $dependencies; do
dep_name=$(basename $dep)
cp $dep "MyApp.app/Contents/libs/$dep_name"
install_name_tool -change $dep "@executable_path/../libs/$dep_name" "MyApp.app/Contents/MacOS/$app"
done
# Create a script to set the DYLD_LIBRARY_PATH environment variable
cat > "MyApp.app/Contents/MacOS/MyApp" << EOF
#!/bin/sh
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:\$(cd \$(dirname \$0) && pwd)/../libs
$PWD/$app
EOF
# Make the script executable
chmod 0755 "MyApp.app/Contents/MacOS/MyApp"