···64# Add all used dynamic libraries to the rpath.
65if [ "$NIX_DONT_SET_RPATH" != 1 ]; then
6667- libPath=""
0068 addToLibPath() {
69 local path="$1"
70 if [ "${path:0:1}" != / ]; then return 0; fi
···76 fi
77 ;;
78 esac
79- case $libPath in
80- *\ $path\ *) return 0 ;;
81- esac
82- libPath+=" $path "
83 }
0008485 addToRPath() {
86 # If the path is not in the store, don't add it to the rpath.
87 # This typically happens for libraries in /tmp that are later
88 # copied to $out/lib. If not, we're screwed.
89 if [ "${1:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then return 0; fi
90- case $rpath in
91- *\ $1\ *) return 0 ;;
92- esac
93- rpath+=" $1 "
94- }
95-96- libs=""
97- addToLibs() {
98- libs+=" $1"
99 }
100101- rpath=""
102103 # First, find all -L... switches.
104 allParams=("${params[@]}" ${extra[@]})
···112 addToLibPath ${p2}
113 n=$((n + 1))
114 elif [ "$p" = -l ]; then
115- addToLibs ${p2}
116 n=$((n + 1))
117 elif [ "${p:0:2}" = -l ]; then
118- addToLibs ${p:2}
119 elif [ "$p" = -dynamic-linker ]; then
120 # Ignore the dynamic linker argument, or it
121 # will get into the next 'elif'. We don't want
···135 # so, add the directory to the rpath.
136 # It's important to add the rpath in the order of -L..., so
137 # the link time chosen objects will be those of runtime linking.
138-139- for i in $libPath; do
140- for j in $libs; do
141 if [ -f "$i/lib$j.so" ]; then
142 addToRPath $i
143 break
···145 done
146 done
147148-149 # Finally, add `-rpath' switches.
150- for i in $rpath; do
151- extra+=(-rpath $i)
152 done
153fi
154
···64# Add all used dynamic libraries to the rpath.
65if [ "$NIX_DONT_SET_RPATH" != 1 ]; then
6667+ declare -A libDirsSeen
68+ declare -a libDirs
69+70 addToLibPath() {
71 local path="$1"
72 if [ "${path:0:1}" != / ]; then return 0; fi
···78 fi
79 ;;
80 esac
81+ if [[ -z ${libDirsSeen[$path]} ]]; then
82+ libDirs+=("$path")
83+ libDirsSeen[$path]=1
84+ fi
85 }
86+87+ declare -A rpathsSeen
88+ declare -a rpaths
8990 addToRPath() {
91 # If the path is not in the store, don't add it to the rpath.
92 # This typically happens for libraries in /tmp that are later
93 # copied to $out/lib. If not, we're screwed.
94 if [ "${1:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then return 0; fi
95+ if [[ -z ${rpathsSeen[$1]} ]]; then
96+ rpaths+=("$1")
97+ rpathsSeen[$1]=1
98+ fi
0000099 }
100101+ declare -a libs
102103 # First, find all -L... switches.
104 allParams=("${params[@]}" ${extra[@]})
···112 addToLibPath ${p2}
113 n=$((n + 1))
114 elif [ "$p" = -l ]; then
115+ libs+=(${p2})
116 n=$((n + 1))
117 elif [ "${p:0:2}" = -l ]; then
118+ libs+=(${p:2})
119 elif [ "$p" = -dynamic-linker ]; then
120 # Ignore the dynamic linker argument, or it
121 # will get into the next 'elif'. We don't want
···135 # so, add the directory to the rpath.
136 # It's important to add the rpath in the order of -L..., so
137 # the link time chosen objects will be those of runtime linking.
138+ for i in ${libDirs[@]}; do
139+ for j in ${libs[@]}; do
0140 if [ -f "$i/lib$j.so" ]; then
141 addToRPath $i
142 break
···144 done
145 done
1460147 # Finally, add `-rpath' switches.
148+ for i in ${rpaths[@]}; do
149+ extra+=(-rpath "$i")
150 done
151fi
152