Commit 83934917 authored by gsell's avatar gsell
Browse files

postinstall_macOS: complete review

- specific code for GCC from Macports removed
- lot of other stuff
parent c0dacedf
...@@ -17,122 +17,124 @@ fi ...@@ -17,122 +17,124 @@ fi
# macOS specific post-install # macOS specific post-install
# #
postinstall_macOS() { postinstall_macOS() {
install_gcc() {
# gcc cc g++ c++ gfortran as ar nm ranlib
rm -f "${OTB_PREFIX}/bin/gcc"
rm -f "${OTB_PREFIX}/bin/cc"
rm -f "${OTB_PREFIX}/bin/g++"
rm -f "${OTB_PREFIX}/bin/c++"
rm -f "${OTB_PREFIX}/bin/gfortran"
rm -f "${OTB_PREFIX}/bin/as"
rm -f "${OTB_PREFIX}/bin/ar"
rm -f "${OTB_PREFIX}/bin/nm"
rm -f "${OTB_PREFIX}/bin/ranlib"
cp "/opt/local/bin/gcc-mp-8" "${OTB_PREFIX}/bin/gcc" ########################################################
ln "${OTB_PREFIX}/bin/gcc" "${OTB_PREFIX}/bin/cc" #
make_relocatable() {
patch_exe() {
local -r f="$1"
local -r d="$2"
cp "/opt/local/bin/g++-mp-8" "${OTB_PREFIX}/bin/g++" local str=$(printf "../%0.s" $(seq 1 $d))
ln "${OTB_PREFIX}/bin/g++" "${OTB_PREFIX}/bin/c++" local path_prefix="@executable_path/${str}lib"
cp "/opt/local/bin/gfortran-mp-8" "${OTB_PREFIX}/bin/gfortran" # replace absolute paths of needed libraries
libs=( $(otool -L "$f" | awk " /${OTB_PREFIX//\//\\/}\/lib/ {print \$1}") )
cp "/opt/local/bin/as" "${OTB_PREFIX}/bin/" [[ -z "${libs}" ]] && return
cp "/opt/local/bin/ar" "${OTB_PREFIX}/bin/" echo "post-process executable: $f"
cp "/opt/local/bin/ranlib" "${OTB_PREFIX}/bin/" for l in ${libs[*]}; do
cp "/opt/local/libexec/llvm-8.0/bin/llvm-nm" "${OTB_PREFIX}/bin/nm" local new="${path_prefix}/${l##*/}"
chmod 0755 "${OTB_PREFIX}"/bin/* echo " changing '$l' -> '${new}'"
install_name_tool -change "$l" "${new}" "$f"
cp /opt/local/lib/libgcc/*.dylib "${OTB_PREFIX}/lib/" done
cp /opt/local/lib/libffi.6.dylib "${OTB_PREFIX}/lib/" }
cp /opt/local/lib/libedit.0.dylib "${OTB_PREFIX}/lib/" patch_lib() {
cp /opt/local/lib/libncurses.6.dylib "${OTB_PREFIX}/lib/" local -r f="$1"
cp /opt/local/libexec/llvm-8.0/lib/libLLVM.dylib "${OTB_PREFIX}/lib/" local -r d="$2"
cp /opt/local/lib/gcc8/libgfortran.spec "${OTB_PREFIX}/lib/gcc8/"
# create required sym-links # check library id
{ local lib_id=$(otool -D "$f" | grep -v "${f}:")
cd ${OTB_PREFIX}/lib local new_id=''
ln -sf libstdc++.6.dylib libstdc++.dylib [[ ${lib_id} =~ ^@rpath ]] || new_id="@rpath/${f##*/}"
ln -sf libgfortran.5.dylib libgfortran.dylib
ln -sf libquadmath.0.dylib libquadmath.dylib # get needed libs to be changed
ln -sf libffi.6.dylib libffi.dylib local str=$(printf "../%0.s" $(seq 1 $d))
ln -sf libedit.0.dylib libedit.dylib local path_prefix="@loader_path/${str}lib"
ln -sf libncurses.6.dylib libncurses.dylib libs=( $(otool -L "$f" | awk "/ ${OTB_PREFIX//\//\\/}\/lib/ {print \$1}") )
if [[ -z "${new_id}" ]] && [[ -z "${libs}" ]]; then
return
fi
echo "post-process library: $f"
if [[ -n "${new_id}" ]]; then
echo " setting id to '${new_id}'"
install_name_tool -id "${new_id}" "$f"
fi
for l in ${libs[*]}; do
local new="${path_prefix}/${l##*/}"
echo " changing '$l' -> '${new}'"
install_name_tool -change "$l" "${new}" "$f"
done
} }
mkdir -p "${OTB_PREFIX}/include/gcc8/" patch_bundle() {
rsync --verbose --archive "/opt/local/include/gcc8/" "${OTB_PREFIX}/include/gcc8/" local -r f="$1"
local -r d="$2"
mkdir -p "${OTB_PREFIX}/lib/gcc8/gcc/"
rsync --verbose --archive "/opt/local/lib/gcc8/gcc/" "${OTB_PREFIX}/lib/gcc8/gcc/"
mkdir -p "${OTB_PREFIX}/libexec/gcc/x86_64-apple-darwin19/8.4.0/"
rsync --verbose --archive "/opt/local/libexec/gcc/x86_64-apple-darwin19/8.4.0/" "${OTB_PREFIX}/libexec/gcc/x86_64-apple-darwin19/8.4.0/"
}
install_libs_from_Macports() {
local -A to_be_installed
executables_1=( $(file -h "${OTB_PREFIX}"/bin/* | \
awk '/Mach-O 64-bit executable/ {print substr($1, 0, length($1)-1)}') )
executables_4=( $(file -h "${OTB_PREFIX}"/libexec/gcc/*/*/* | \
awk '/Mach-O 64-bit executable/ {print substr($1, 0, length($1)-1)}') )
libraries=( $(find "${OTB_PREFIX}" -type f -name "*.dylib" -o -name "*.so") )
for f in "${executables_1[@]}" "${executables_4[@]}" "${libraries[@]}"; do # get needed libs to be changed
while read l; do local str=$(printf "../%0.s" $(seq 1 $d))
to_be_installed["$l"]=1 local path_prefix="@loader_path/${str}lib"
done < <(otool -L "$f" | awk '/opt\/local/ {print $1}') libs=( $(otool -L "$f" | awk "/ ${OTB_PREFIX//\//\\/}\/lib/ {print \$1}") )
done
for f in "${!to_be_installed[@]}"; do if [[ -z "${libs}" ]]; then
if [[ ! -e ${OTB_PREFIX}/lib/${f##*/} ]]; then return
cp "$f" "${OTB_PREFIX}/lib/"
fi fi
done echo "post-process library: $f"
}
make_binaries_relocatable() {
executables_1=( $(file -h "${OTB_PREFIX}"/bin/* | \
awk '/Mach-O 64-bit executable/ {print substr($1, 0, length($1)-1)}') )
executables_4=( $(file -h "${OTB_PREFIX}"/libexec/gcc/*/*/* | \
awk '/Mach-O 64-bit executable/ {print substr($1, 0, length($1)-1)}') )
libraries=( $(find "${OTB_PREFIX}" -type f -name "*.dylib" -o -name "*.so") )
for f in "${executables_1[@]}"; do
# CMake has been compiled with Clang!
[[ "$f" =~ cmake ]] && continue
echo "post-process: $f"
# set rpath if not already set
install_name_tool -add_rpath @executable_path/../lib "$f"
libs=( $(otool -L "$f" | awk " /opt\/local\/lib|${OTB_PREFIX//\//\\/}\/lib/ {print \$1}") )
for l in ${libs[*]}; do for l in ${libs[*]}; do
install_name_tool -change "$l" "@rpath/${l##*/}" "$f" local new="${path_prefix}/${l##*/}"
echo " changing '$l' -> '${new}'"
install_name_tool -change "$l" "${new}" "$f"
done done
done }
for f in "${executables_4[@]}"; do #
echo "post-process: $f" # check and patch all executables, libraries and bundles
# set rpath if not already set # in ${OTB_PREFIX}/{bin,lib}
install_name_tool -add_rpath @executable_path/../../../../lib "$f" #
libs=( $(otool -L "$f" | awk " /opt\/local\/lib|${OTB_PREFIX//\//\\/}\/lib/ {print \$1}") ) local -A executables
for l in ${libs[*]}; do local -A libraries
install_name_tool -change "$l" "@rpath/${l##*/}" "$f" local -- fname
done local -i depth
done echo "Check and patch executables, libraries and bundles..."
while read depth fname; do
case "$(file -b ${fname})" in
Mach-O\ 64-bit\ executable\ * )
patch_exe "${fname}" "${depth}"
;;
Mach-O\ 64-bit\ dynamically\ linked\ shared\ library\ * )
patch_lib "${fname}" "${depth}"
;;
Mach-O\ 64-bit\ bundle\ * )
patch_bundle "${fname}" "${depth}"
;;
esac
done < <(gfind "${OTB_PREFIX}/bin" "${OTB_PREFIX}/lib" -type f -printf "%d %p\n" )
}
for f in "${libraries[@]}"; do ########################################################
echo "post-process: $f" #
otool -l "$f" | grep -q LC_RPATH || \ # strip binaries
install_name_tool -id "@rpath/${f##*/}" "$f" #
libs=( $(otool -L "$f" | awk " /opt\/local\/lib|${OTB_PREFIX//\//\\/}\/lib/ {print \$1}") ) strip_unneeded() {
for l in ${libs[*]}; do while read depth fname; do
install_name_tool -change "$l" "@rpath/${l##*/}" "$f" case "$(file -b ${fname})" in
done Mach-O\ 64-bit\ executable\ * )
done strip -u -r "$fname"
;;
Mach-O\ 64-bit\ dynamically\ linked\ shared\ library\ * )
strip -x "$fname"
;;
Mach-O\ 64-bit\ bundle\ * )
:
;;
esac
done < <(gfind "${OTB_PREFIX}/bin" "${OTB_PREFIX}/lib" -type f -printf "%d %p\n" )
} }
install_gcc
install_libs_from_Macports ########################################################
make_binaries_relocatable #
make_relocatable
strip_unneeded
} }
postinstall_macOS postinstall_macOS
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment