@@ -205,22 +205,43 @@ for icu_lib in "${icu_libs[@]}"; do
205205 sign_binary " $INSTALL_DIR /lib/$icu_lib "
206206done
207207
208- # Update library paths within each .dylib in the lib directory
209- for dylib in $INSTALL_DIR /lib/* .dylib; do
210- install_name_tool -id " @loader_path/../lib/$( basename " $dylib " ) " " $dylib "
211- otool -L " $dylib " | awk ' {print $1}' | grep -E ' /opt/homebrew|/usr/local|@executable_path|' " $INSTALL_DIR " | while read dep; do
212- # Ensure the library is copied to the lib folder if it’s not already there
213- cp -Lf " $dep " " $INSTALL_DIR /lib/" 2> /dev/null || true
214- install_name_tool -change " $dep " " @loader_path/../lib/$( basename " $dep " ) " " $dylib "
215-
216- # Create version-agnostic symlinks
208+ # Function to recursively copy dependencies and update paths
209+ process_dependencies () {
210+ local file_path=" $1 "
211+
212+ # Update the ID of the library to use @loader_path
213+ install_name_tool -id " @loader_path/../lib/$( basename " $file_path " ) " " $file_path "
214+
215+ # Get the dependencies using otool
216+ otool -L " $file_path " | awk ' {print $1}' | grep -E ' /opt/homebrew|/usr/local|@executable_path|' " $INSTALL_DIR " | while read dep; do
217+ # If the dependency is not already in the lib directory, copy it
218+ if [ ! -f " $INSTALL_DIR /lib/$( basename " $dep " ) " ]; then
219+ cp -Lf " $dep " " $INSTALL_DIR /lib/" 2> /dev/null || true
220+
221+ # Recursively process the newly copied dependency
222+ if [ -f " $INSTALL_DIR /lib/$( basename " $dep " ) " ]; then
223+ process_dependencies " $INSTALL_DIR /lib/$( basename " $dep " ) "
224+ fi
225+ fi
226+
227+ # Update the path to use @loader_path
228+ install_name_tool -change " $dep " " @loader_path/../lib/$( basename " $dep " ) " " $file_path "
229+
230+ # Create version-agnostic symlinks if necessary
217231 base_name=$( basename " $dep " )
218232 symlink_name=$( echo " $base_name " | sed -E ' s/([._][0-9]+)+\.dylib$/.dylib/' ) # e.g., libcrypto.3.dylib -> libcrypto.dylib
219233
220234 if [ " $symlink_name " != " $base_name " ]; then
221235 ln -sf " $base_name " " $INSTALL_DIR /lib/$symlink_name "
222236 fi
223237 done
238+ }
239+
240+ # Process all .so and .dylib files in the lib directory
241+ for lib_file in $INSTALL_DIR /lib/* .{so,dylib}; do
242+ if [ -f " $lib_file " ]; then
243+ process_dependencies " $lib_file "
244+ fi
224245done
225246
226247# Loop through all .dylib and .so files in the lib folder to sign them
235256# **Step 2: Create a Zip Archive for Notarization**
236257cd $INSTALL_DIR
237258rm -rf lib/pgxs/src/test/
259+ rm -rf lib/Python
238260cp -Rf $( git rev-parse --show-toplevel) /share/postgresql/extension/* share/extension
239261zip -r $TRG_DIR /postgres-macos.zip \
240262 share \
0 commit comments