#!/bin/sh

libdir=${prefix}/lib

for dylib in ${destroot}${libdir}/*.dylib ; do
    [[ -L $dylib ]] && continue

    dylib_name=${dylib##*/}

    install_name_tool -id ${libdir}/${dylib_name} $dylib

    for lib in $(otool -L ${dylib} | grep -v : | grep ${worksrcpath} | awk '{print $1}') ; do
        lib_name=${lib##*/}
        [[ $dylib_name == $lib_name ]] && continue

        install_name_tool -change ${lib} ${libdir}/${lib_name} $dylib
    done
done
