···6464# Add all used dynamic libraries to the rpath.
6565if [ "$NIX_DONT_SET_RPATH" != 1 ]; then
66666767- libPath=""
6767+ declare -A libDirsSeen
6868+ declare -a libDirs
6969+6870 addToLibPath() {
6971 local path="$1"
7072 if [ "${path:0:1}" != / ]; then return 0; fi
···7678 fi
7779 ;;
7880 esac
7979- case $libPath in
8080- *\ $path\ *) return 0 ;;
8181- esac
8282- libPath+=" $path "
8181+ if [[ -z ${libDirsSeen[$path]} ]]; then
8282+ libDirs+=("$path")
8383+ libDirsSeen[$path]=1
8484+ fi
8385 }
8686+8787+ declare -A rpathsSeen
8888+ declare -a rpaths
84898590 addToRPath() {
8691 # If the path is not in the store, don't add it to the rpath.
8792 # This typically happens for libraries in /tmp that are later
8893 # copied to $out/lib. If not, we're screwed.
8994 if [ "${1:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then return 0; fi
9090- case $rpath in
9191- *\ $1\ *) return 0 ;;
9292- esac
9393- rpath+=" $1 "
9494- }
9595-9696- libs=""
9797- addToLibs() {
9898- libs+=" $1"
9595+ if [[ -z ${rpathsSeen[$1]} ]]; then
9696+ rpaths+=("$1")
9797+ rpathsSeen[$1]=1
9898+ fi
9999 }
100100101101- rpath=""
101101+ declare -a libs
102102103103 # First, find all -L... switches.
104104 allParams=("${params[@]}" ${extra[@]})
···112112 addToLibPath ${p2}
113113 n=$((n + 1))
114114 elif [ "$p" = -l ]; then
115115- addToLibs ${p2}
115115+ libs+=(${p2})
116116 n=$((n + 1))
117117 elif [ "${p:0:2}" = -l ]; then
118118- addToLibs ${p:2}
118118+ libs+=(${p:2})
119119 elif [ "$p" = -dynamic-linker ]; then
120120 # Ignore the dynamic linker argument, or it
121121 # will get into the next 'elif'. We don't want
···135135 # so, add the directory to the rpath.
136136 # It's important to add the rpath in the order of -L..., so
137137 # the link time chosen objects will be those of runtime linking.
138138-139139- for i in $libPath; do
140140- for j in $libs; do
138138+ for i in ${libDirs[@]}; do
139139+ for j in ${libs[@]}; do
141140 if [ -f "$i/lib$j.so" ]; then
142141 addToRPath $i
143142 break
···145144 done
146145 done
147146148148-149147 # Finally, add `-rpath' switches.
150150- for i in $rpath; do
151151- extra+=(-rpath $i)
148148+ for i in ${rpaths[@]}; do
149149+ extra+=(-rpath "$i")
152150 done
153151fi
154152