|
| 1 | +# For more information, please see: http://software.sci.utah.edu |
| 2 | +# |
| 3 | +# The MIT License |
| 4 | +# |
| 5 | +# Copyright (c) 2015 Scientific Computing and Imaging Institute, |
| 6 | +# University of Utah. |
| 7 | +# |
| 8 | +# |
| 9 | +# Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | +# copy of this software and associated documentation files (the "Software"), |
| 11 | +# to deal in the Software without restriction, including without limitation |
| 12 | +# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | +# and/or sell copies of the Software, and to permit persons to whom the |
| 14 | +# Software is furnished to do so, subject to the following conditions: |
| 15 | +# |
| 16 | +# The above copyright notice and this permission notice shall be included |
| 17 | +# in all copies or substantial portions of the Software. |
| 18 | +# |
| 19 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 24 | +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 25 | +# DEALINGS IN THE SOFTWARE. |
| 26 | +# |
| 27 | +# macdeploy.sh: change runtime paths in app bundle libraries and executables |
| 28 | +#!/bin/bash |
| 29 | + |
| 30 | +print() { |
| 31 | + if [[ $# -lt 2 ]]; then |
| 32 | + echo "$0 verbose (0 off or 1 on) string" |
| 33 | + exit -1 |
| 34 | + fi |
| 35 | + local verbose=$1 |
| 36 | + local string=$2 |
| 37 | + if [[ $verbose -eq 1 ]]; then |
| 38 | + echo "$string" |
| 39 | + fi |
| 40 | +} |
| 41 | + |
| 42 | +if [[ $# -lt 4 ]]; then |
| 43 | + echo "$0 path_to_app_bundle original_lib_dir appname verbose (0 off or 1 on)" |
| 44 | + exit -1 |
| 45 | +fi |
| 46 | + |
| 47 | +app_bundle=$1 |
| 48 | +original_lib_dir=$2 |
| 49 | +appname=$3 |
| 50 | +verbose=$4 |
| 51 | + |
| 52 | +if [[ $verbose -ne 0 && $verbose -ne 1 ]]; then |
| 53 | + echo "Arg 5 (verbose) not set to 0 or 1. Defaulting to verbose output off." |
| 54 | + verbose=0 |
| 55 | +fi |
| 56 | + |
| 57 | +print $verbose "SCIRun library directory: ${original_lib_dir}" |
| 58 | + |
| 59 | +cwd=`pwd` |
| 60 | +cd $app_bundle/Contents/Frameworks |
| 61 | + |
| 62 | +# TODO: when CMP0042 new is supported, switch to @rpath |
| 63 | +scirun_libs=`ls -1 *.dylib` |
| 64 | +for l in ${scirun_libs}; do |
| 65 | + if [[ $verbose -eq 1 ]]; then |
| 66 | + echo "processing $l" |
| 67 | + fi |
| 68 | + COMMAND=`otool -L $l | sed -n "s:"$original_lib_dir":& :p" | awk -v lib=$l '{print "install_name_tool -change "$1$2" "$2" " lib }'` |
| 69 | + print $verbose "${COMMAND}" |
| 70 | + sh -c "${COMMAND}" |
| 71 | + |
| 72 | + COMMAND=`otool -L $l | sed -n "s:[^/][^/]*lib[A-z0-9_.]*.dylib:&:p" | awk -v lib=$l '{print "install_name_tool -change "$1" @executable_path/../Frameworks/"$1" " lib }'` |
| 73 | + print $verbose "${COMMAND}" |
| 74 | + sh -c "${COMMAND}" |
| 75 | + |
| 76 | + print $verbose "install_name_tool -id @executable_path/../Frameworks/${l} ${l}" |
| 77 | + install_name_tool -id "@executable_path/../Frameworks/${l}" ${l} |
| 78 | +done |
| 79 | + |
| 80 | +cd $cwd |
| 81 | +cd $app_bundle/Contents/MacOS |
| 82 | + |
| 83 | +COMMAND=`otool -L $appname | sed -n "s:$original_lib_dir:& :p" | awk -v lib=$appname '{print "install_name_tool -change "$1$2" "$2" " lib }'` |
| 84 | +print $verbose "${COMMAND}" |
| 85 | +sh -c "${COMMAND}" |
| 86 | + |
| 87 | +COMMAND=`otool -L $appname | sed -n "s:[^/][^/]*lib[A-z0-9_.]*.dylib:&:p" | awk -v lib=$appname '{print "install_name_tool -change "$1" @executable_path/../Frameworks/"$1" " lib }'` |
| 88 | +print $verbose "${COMMAND}" |
| 89 | +sh -c "${COMMAND}" |
| 90 | + |
| 91 | +cd $cwd |
0 commit comments