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@699: if [ -x "$x" ]; then Chris@699: current=$(otool -L "$x" | Chris@699: grep "$fwk" | grep amework | grep -v ':$' | Chris@699: awk '{ print $1; }') Chris@670: Chris@699: [ -z "$current" ] && continue Chris@670: Chris@699: echo "$x has $current" Chris@670: Chris@699: case "$x" in Chris@699: # *PyQt*) Chris@699: # These are "special" Qt libraries used by Chris@699: # the PyQt module. They need to refer to their Chris@699: # own local neighbours. Ugh, but let's handle Chris@699: # those manually here. Chris@699: # relative="$fwk.so" Chris@699: # ;; Chris@699: *) Chris@699: # The normal Qt case Chris@699: relative=$(echo "$x" | Chris@699: sed -e "s,$app.app/Contents/,," \ Chris@699: -e 's,[^/]*/,../,g' \ Chris@699: -e 's,/[^/]*$,/Frameworks/'"$fwk"',' ) Chris@699: ;; Chris@699: esac Chris@670: Chris@699: echo "replacing with relative path $relative" Chris@699: install_name_tool -change \ Chris@699: "$current" "@loader_path/$relative" "$x" Chris@699: fi Chris@670: done Chris@335: done Chris@335: Chris@667: find "$app.app" -type f -print | while read x; do Chris@699: if [ -x "$x" ]; then Chris@699: qtdep=$(otool -L "$x" | grep Qt | grep amework | grep -v ':$' | grep -v '@loader_path' | awk '{ print $1; }') Chris@699: if [ -n "$qtdep" ]; then Chris@699: echo Chris@699: echo "ERROR: File $x depends on Qt framework(s) not apparently present in the bundle:" Chris@699: echo $qtdep Chris@699: exit 1 Chris@699: fi 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: