2016-06-02 07:56:56 -05:00
#!/bin/sh
bundle = " $1 "
if ! test -d " $bundle " ; then
2019-03-21 09:02:19 -05:00
echo " ${ bundle } is no bundle! " >& 2
2016-06-02 07:56:56 -05:00
exit 1
fi
2019-03-21 09:02:19 -05:00
if test -z ${ QTDIR } ; then
2016-06-02 07:56:56 -05:00
echo "QTDIR environment variable not set"
exit 1
else
2019-03-21 09:02:19 -05:00
echo " QTDIR= ${ QTDIR } "
2016-06-02 07:56:56 -05:00
fi
2019-03-21 09:02:19 -05:00
test -d " ${ bundle } /Contents/Resources " || mkdir -p " ${ bundle } /Contents/Resources " || exit 1
2016-06-02 07:56:56 -05:00
# Create qt.conf so that app knows where the Plugins are present
2019-03-21 09:02:19 -05:00
cat >> " ${ bundle } /Contents/Resources/qt.conf " << EOF
2016-06-02 07:56:56 -05:00
[ Paths]
Plugins = PlugIns
EOF
2019-03-21 09:02:19 -05:00
test -d " ${ bundle } /Contents/Frameworks " || mkdir -p " ${ bundle } /Contents/Frameworks " || exit 1
test -d " ${ bundle } /Contents/PlugIns/platforms " || mkdir -p " ${ bundle } /Contents/PlugIns/platforms " || exit 1
2020-04-22 08:06:04 -05:00
test -d " ${ bundle } /Contents/PlugIns/imageformats " || mkdir -p " ${ bundle } /Contents/PlugIns/imageformats " || exit 1
2019-03-21 09:02:19 -05:00
cp -f ${ QTDIR } /plugins/platforms/libqcocoa.dylib " ${ bundle } /Contents/PlugIns/platforms " || { echo libqcocoa.dylib not found in ${ QTDIR } /plugins/platforms; exit 1; }
2020-04-22 08:06:04 -05:00
cp -f ${ QTDIR } /plugins/imageformats/libqsvg.dylib " ${ bundle } /Contents/PlugIns/imageformats " || { echo libqsvg.dylib not found in ${ QTDIR } /plugins/imageformats; exit 1; }
2019-03-21 09:02:19 -05:00
cp -f ${ PGDIR } /lib/libpq.5.dylib " ${ bundle } /Contents/Frameworks " || { echo libpq.5.dylib not found in ${ PGDIR } ; exit 1; }
2016-06-02 07:56:56 -05:00
function CompleteSingleApp( ) {
local bundle = $1 tag = $( basename " $1 " ) todo todo_old fw_relpath lib lib_bn nested_app na_relpath
2019-03-21 09:02:19 -05:00
echo " Completing app: ${ bundle } "
pushd " ${ bundle } " > /dev/null
2016-06-02 07:56:56 -05:00
#We skip nested apps here - those are treated specially
2018-06-14 11:03:16 -05:00
todo = $( file ` find ./ -perm +0111 ! -type d ! -path "*.app/*" ! -name "*.app" ` | grep -E "Mach-O 64-bit" | awk -F ':| ' '{ORS=" "; print $1}' )
2016-06-02 07:56:56 -05:00
2019-03-21 09:02:19 -05:00
echo " App: ${ tag } : Found executables: ${ todo } "
while test " ${ todo } " != "" ; do
todo_old = ${ todo } ;
2016-06-02 07:56:56 -05:00
todo = "" ;
2019-03-21 09:02:19 -05:00
for todo_obj in ${ todo_old } ; do
echo " App: ${ tag } : Post-processing: ${ todo_obj } "
2016-06-02 07:56:56 -05:00
#Figure out the relative path from todo_obj to Contents/Frameworks
2019-03-21 09:02:19 -05:00
fw_relpath = $( echo " ${ todo_obj } " | \
2016-06-02 07:56:56 -05:00
sed -n 's|^\(\.//*\)\(\([^/][^/]*/\)*\)[^/][^/]*$|\2|gp' | \
sed -n 's|[^/][^/]*/|../|gp' \
) "Contents/Frameworks"
2019-03-21 09:02:19 -05:00
fw_relpath_old = ${ fw_relpath }
2016-06-02 07:56:56 -05:00
fw_loc = "Contents/Frameworks"
#Find all libraries $todo_obj depends on, but skip system libraries
for lib in $(
2019-03-21 09:02:19 -05:00
otool -L ${ todo_obj } | \
2016-06-02 07:56:56 -05:00
grep "Qt\|dylib\|Frameworks\|PlugIns" | grep -v ":" | sed 's/(.*//' | egrep -v '(/usr/lib)|(/System)|@executable_path@' \
2019-03-21 09:02:19 -05:00
) $( otool -L ${ todo_obj } | grep "Python" | grep -v ":" | sed 's/(.*//' \
2016-06-02 07:56:56 -05:00
) ; do
2019-03-21 09:02:19 -05:00
if echo ${ lib } | grep "PlugIns\|libqcocoa" > /dev/null; then
2016-06-02 07:56:56 -05:00
lib_loc = "Contents/PlugIns/platforms"
2020-04-22 08:06:04 -05:00
elif echo ${ lib } | grep "PlugIns\|libqsvg" > /dev/null; then
lib_loc = "Contents/PlugIns/imageformats"
2019-03-21 09:02:19 -05:00
elif echo ${ lib } | grep "Qt" > /dev/null; then
qtfw_path = " $( dirname ${ lib } | sed 's|.*\(Qt.*framework\)|\1|' ) "
lib_loc = " Contents/Frameworks/ ${ qtfw_path } "
if [ " $( basename ${ todo_obj } ) " = " ${ lib } " ] ; then
lib_loc = " $( dirname ${ todo_obj } ) "
qtfw_path = $( echo ${ lib_loc } | sed 's/Contents\/Frameworks\///' )
2016-06-02 07:56:56 -05:00
fi
2019-03-21 09:02:19 -05:00
elif echo ${ lib } | grep "Python" > /dev/null; then
pyfw_path = " $( dirname ${ lib } | sed 's|.*\(Python.*framework\)|\1|' ) "
lib_loc = " Contents/Frameworks/ ${ pyfw_path } "
if [ " $( basename ${ todo_obj } ) " = " ${ lib } " ] ; then
lib_loc = " $( dirname ${ todo_obj } ) "
pyfw_path = $( echo ${ lib_loc } | sed 's/Contents\/Frameworks\///' )
2016-06-02 07:56:56 -05:00
fi
else
lib_loc = "Contents/Frameworks"
fi
2019-03-21 09:02:19 -05:00
lib_bn = " $( basename " ${ lib } " ) " ;
if ! test -f " ${ lib_loc } / ${ lib_bn } " ; then
2016-06-02 07:56:56 -05:00
target_file = ""
target_path = ""
2019-03-21 09:02:19 -05:00
echo " App: ${ tag } : Adding symlink: ${ lib_bn } (because of: ${ todo_obj } ) "
2016-06-02 07:56:56 -05:00
# Copy the QT and Python framework
2019-03-21 09:02:19 -05:00
if echo ${ lib } | grep Qt > /dev/null ; then
test -d ${ lib_loc } || mkdir -p ${ lib_loc }
echo Copying -R ${ QTDIR } /lib/${ qtfw_path } /${ lib_bn } to ${ lib_loc } /
cp ${ QTDIR } /lib/${ qtfw_path } /${ lib_bn } ${ lib_loc } /
elif echo ${ lib } | grep Python > /dev/null ; then
test -d ${ lib_loc } || mkdir -p ${ lib_loc }
cp -R " ${ lib } " " ${ lib_loc } / ${ lib_bn } "
2016-06-02 07:56:56 -05:00
else
2019-03-21 09:02:19 -05:00
cp -R " ${ lib } " " ${ lib_loc } / ${ lib_bn } "
2016-06-02 07:56:56 -05:00
fi
2019-03-21 09:02:19 -05:00
if ! test -L " ${ lib_loc } / ${ lib_bn } " ; then
chmod 755 " ${ lib_loc } / ${ lib_bn } "
2016-06-02 07:56:56 -05:00
else
2019-03-21 09:02:19 -05:00
target_file = $( readlink " ${ lib } " )
target_path = $( dirname " ${ lib } " ) /${ target_file }
echo " App: ${ tag } : Adding symlink target: ${ target_path } "
cp " ${ target_path } " " ${ lib_loc } / ${ target_file } "
chmod 755 " ${ lib_loc } / ${ target_file } "
2016-06-02 07:56:56 -05:00
fi
2019-03-21 09:02:19 -05:00
echo " Rewriting ID in ${ lib_loc } / ${ lib_bn } to ${ lib_bn } "
echo install_name_tool -id " ${ lib_bn } " " ${ lib_loc } / ${ lib_bn } "
2016-06-02 07:56:56 -05:00
install_name_tool \
2019-03-21 09:02:19 -05:00
-id " ${ lib_bn } " \
" ${ lib_loc } / ${ lib_bn } " || exit 1
todo = " ${ todo } ./ ${ lib_loc } / ${ lib_bn } "
2016-06-02 07:56:56 -05:00
fi
2019-03-21 09:02:19 -05:00
if echo ${ lib } | grep Qt > /dev/null ; then
fw_relpath = " ${ fw_relpath } / ${ qtfw_path } "
2016-06-02 07:56:56 -05:00
fi
2019-03-21 09:02:19 -05:00
if echo ${ lib } | grep Python > /dev/null ; then
fw_relpath = " ${ fw_relpath } / ${ pyfw_path } "
2016-06-02 07:56:56 -05:00
fi
2019-03-21 09:02:19 -05:00
chmod +w ${ todo_obj }
echo " Rewriting library ${ lib } to @loader_path/ ${ fw_relpath } / ${ lib_bn } in ${ todo_obj } "
echo install_name_tool -change " ${ lib } " " @loader_path/ ${ fw_relpath } / ${ lib_bn } " " ${ todo_obj } "
2016-06-02 07:56:56 -05:00
install_name_tool -change \
2019-03-21 09:02:19 -05:00
" ${ lib } " \
" @loader_path/ ${ fw_relpath } / ${ lib_bn } " \
" ${ todo_obj } " || exit 1
2016-06-02 07:56:56 -05:00
install_name_tool -change \
2019-03-21 09:02:19 -05:00
" ${ target_path } " \
" @loader_path/ ${ fw_relpath } / ${ target_file } " \
" ${ todo_obj } " || exit 1
fw_relpath = " ${ fw_relpath_old } "
2016-06-02 07:56:56 -05:00
done
done
done
# Fix the rpaths for psycopg module
2019-03-21 09:02:19 -05:00
find " ${ bundle } /Contents/Resources/venv/ " -name _psycopg.so -print0 | xargs -0 install_name_tool -change libpq.5.dylib @loader_path/../../../../../../Frameworks/libpq.5.dylib
find " ${ bundle } /Contents/Resources/venv/ " -name _psycopg.so -print0 | xargs -0 install_name_tool -change libssl.1.0.0.dylib @loader_path/../../../../../../Frameworks/libssl.1.0.0.dylib
find " ${ bundle } /Contents/Resources/venv/ " -name _psycopg.so -print0 | xargs -0 install_name_tool -change libcrypto.1.0.0.dylib @loader_path/../../../../../../Frameworks/libcrypto.1.0.0.dylib
2016-06-02 07:56:56 -05:00
2019-03-21 09:02:19 -05:00
echo " App completed: ${ bundle } "
2016-06-02 07:56:56 -05:00
popd > /dev/null
}
2019-03-21 09:02:19 -05:00
CompleteSingleApp " ${ bundle } "