@@ -168,6 +168,51 @@ cat "$INSTALLROOT/.original-unrelocated" | xargs -n1 -I{} echo "sed -e \"s|/[^ ]
168
168
if [[ ! -s " $INSTALLROOT /.original-unrelocated" && -f " $INSTALLROOT /etc/modulefiles/$PKGNAME " ]]; then
169
169
echo " mv -f \$ PP/etc/modulefiles/$PKGNAME \$ PP/etc/modulefiles/${PKGNAME} .forced-relocation && sed -e \" s|[@][@]PKGREVISION[@]\$ PH[@][@]|$PKGREVISION |g\" \$ PP/etc/modulefiles/${PKGNAME} .forced-relocation > \$ PP/etc/modulefiles/$PKGNAME " >> " $INSTALLROOT /relocate-me.sh"
170
170
fi
171
+
172
+ # Find libraries and executables needing relocation on macOS
173
+ if [[ ${ARCHITECTURE: 0: 3} == " osx" ]]; then
174
+
175
+ /usr/bin/find ${RELOCATE_PATHS:- bin lib lib64} -type f | \
176
+ while read BIN; do
177
+ MACHOTYPE=$( set +o pipefail; otool -h " $PWD /$BIN " 2> /dev/null | grep filetype -A1 | tail -n1 | awk ' {print $5}' )
178
+
179
+ # See mach-o/loader.h from XNU sources: 2 == executable, 6 == dylib
180
+ if [[ $MACHOTYPE == 6 ]]; then
181
+ # Only dylibs: relocate LC_ID_DYLIB
182
+ if otool -D " $PWD /$BIN " 2> /dev/null | tail -n1 | grep -q $PKGHASH ; then
183
+ cat << EOF >> "$INSTALLROOT /relocate-me.sh"
184
+ install_name_tool -id \$ (otool -D "\$ PP/$BIN " | tail -n1 | sed -e "s|/[^ ]*INSTALLROOT/\$ PH/\$ OP|\$ WORK_DIR/\$ PP|g") "\$ PP/$BIN "
185
+ EOF
186
+ fi
187
+ fi
188
+
189
+ if [[ $MACHOTYPE == 2 || $MACHOTYPE == 6 ]]; then
190
+ # Both libs and binaries: relocate LC_RPATH
191
+ if otool -l " $PWD /$BIN " 2> /dev/null | grep -A2 LC_RPATH | grep path | grep -q $PKGHASH ; then
192
+ cat << EOF >> "$INSTALLROOT /relocate-me.sh"
193
+ OLD_RPATHS=\$ (otool -l \$ PP/$BIN | grep -A2 LC_RPATH | grep path | grep \$ PH | sed -e 's|^.*path ||' -e 's| .*$||')
194
+ for OLD_RPATH in \$ OLD_RPATHS; do
195
+ NEW_RPATH=\$ {OLD_RPATH/#*INSTALLROOT\/\$ PH\/\$ OP/\$ WORK_DIR/\$ PP}
196
+ install_name_tool -rpath "\$ OLD_RPATH" "\$ NEW_RPATH" "\$ PP/$BIN "
197
+ done
198
+ EOF
199
+ fi
200
+
201
+ # Both libs and binaries: relocate LC_LOAD_DYLIB
202
+ if otool -l " $PWD /$BIN " 2> /dev/null | grep -A2 LC_LOAD_DYLIB | grep name | grep -q $PKGHASH ; then
203
+ cat << EOF >> "$INSTALLROOT /relocate-me.sh"
204
+ OLD_LOAD_DYLIBS=\$ (otool -l \$ PP/$BIN | grep -A2 LC_LOAD_DYLIB | grep name | grep \$ PH | sed -e 's|^.*name ||' -e 's| .*$||')
205
+ for OLD_LOAD_DYLIB in \$ OLD_LOAD_DYLIBS; do
206
+ NEW_LOAD_DYLIB=\$ {OLD_LOAD_DYLIB/#*INSTALLROOT\/\$ PH\/\$ OP/\$ WORK_DIR/\$ PP}
207
+ install_name_tool -change "\$ OLD_LOAD_DYLIB" "\$ NEW_LOAD_DYLIB" "\$ PP/$BIN "
208
+ done
209
+ EOF
210
+ fi
211
+ fi
212
+ done || true
213
+
214
+ fi
215
+
171
216
cat " $INSTALLROOT /relocate-me.sh"
172
217
cat " $INSTALLROOT /.original-unrelocated" | xargs -n1 -I{} cp ' {}' ' {}' .unrelocated
173
218
cd " $WORK_DIR /INSTALLROOT/$PKGHASH "
0 commit comments