Chris@335: #!/bin/bash Chris@335: Chris@667: set -e Chris@667: Chris@335: app="$1" Chris@335: if [ -z "$app" ]; then Chris@335: echo "Usage: $0 " Chris@335: echo "Provide appname without the .app extension, please" Chris@335: exit 2 Chris@335: fi Chris@335: Chris@667: set -u Chris@667: Chris@667: frameworks="QtCore QtNetwork QtGui QtWidgets QtPrintSupport QtDBus" Chris@667: Chris@335: echo Chris@667: echo "I expect you to have already copied these frameworks from the Qt installation to" Chris@667: echo "$app.app/Contents/Frameworks -- expect errors to follow if they're missing:" Chris@667: echo "$frameworks" Chris@335: echo Chris@335: Chris@335: echo "Fixing up loader paths in binaries..." Chris@335: Chris@667: for fwk in $frameworks; do Chris@667: install_name_tool -id $fwk "$app.app/Contents/Frameworks/$fwk" Chris@667: done Chris@335: Chris@667: find "$app.app" -name \*.dylib -print | while read x; do Chris@667: install_name_tool -id "`basename \"$x\"`" "$x" Chris@667: done Chris@667: Chris@667: for fwk in $frameworks; do Chris@670: find "$app.app" -type f -print | while read x; do Chris@670: Chris@670: current=$(otool -L "$x" | Chris@670: grep "$fwk" | grep amework | grep -v ':$' | Chris@670: awk '{ print $1; }') Chris@670: Chris@670: [ -z "$current" ] && continue Chris@670: Chris@670: echo "$x has $current" Chris@670: Chris@670: case "$x" in Chris@670: *PyQt4*) Chris@670: # These are "special" Qt4 libraries used by Chris@670: # the PyQt module. They need to refer to their Chris@670: # own local neighbours. Ugh, but let's handle Chris@670: # those manually here. Chris@670: relative="$fwk.so" Chris@670: ;; Chris@670: *) Chris@670: # The normal Qt5 case Chris@670: relative=$(echo "$x" | Chris@670: sed -e "s,$app.app/Contents/,," \ Chris@670: -e 's,[^/]*/,../,g' \ Chris@670: -e 's,/[^/]*$,/Frameworks/'"$fwk"',' ) Chris@670: ;; Chris@670: esac Chris@670: Chris@670: echo "replacing with relative path $relative" Chris@670: install_name_tool -change \ Chris@670: "$current" "@loader_path/$relative" "$x" Chris@670: done Chris@335: done Chris@335: Chris@667: find "$app.app" -type f -print | while read x; do Chris@667: qtdep=$(otool -L "$x" | grep Qt | grep amework | grep -v ':$' | grep -v '@loader_path' | awk '{ print $1; }') Chris@667: if [ -n "$qtdep" ]; then Chris@667: echo Chris@667: echo "ERROR: File $x depends on Qt framework(s) not apparently present in the bundle:" Chris@667: echo $qtdep Chris@667: exit 1 Chris@667: fi Chris@667: done Chris@667: Chris@335: echo "Done: be sure to run the app and see that it works!" Chris@335: Chris@335: