diff --git a/pkgs/build-support/gcc-wrapper/add-flags b/pkgs/build-support/gcc-wrapper/add-flags index ace0a789628c..02755e445414 100644 --- a/pkgs/build-support/gcc-wrapper/add-flags +++ b/pkgs/build-support/gcc-wrapper/add-flags @@ -5,16 +5,16 @@ if test -e @out@/nix-support/libc-cflags; then export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE" fi -if test -e @out@/nix-support/libc-ldflags; then - export NIX_LDFLAGS="$(cat @out@/nix-support/libc-ldflags) $NIX_LDFLAGS" -fi - if test -e @out@/nix-support/gcc-cflags; then export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/gcc-cflags) $NIX_CFLAGS_COMPILE" fi +if test -e @out@/nix-support/libc-ldflags; then + export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/libc-ldflags)" +fi + if test -e @out@/nix-support/gcc-ldflags; then - export NIX_LDFLAGS="$(cat @out@/nix-support/gcc-ldflags) $NIX_LDFLAGS" + export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/gcc-ldflags)" fi if test -e @out@/nix-support/libc-ldflags-before; then diff --git a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh index 94241e42ce9b..962adf43861a 100644 --- a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh @@ -85,9 +85,11 @@ if test "$NIX_DONT_SET_RPATH" != "1"; then n=$((n + 1)) done - # Second, for each -l... switch, find the directory containing the - # library and add it to the rpath. + # Second, for each directory in the library search path (-L...), + # see if it contains a dynamic library used by a -l... flag. If + # so, add the directory to the rpath. rpath="" + addToRPath() { # If the path is not in the store, don't add it to the rpath. # This typically happens for libraries in /tmp that are later @@ -98,26 +100,25 @@ if test "$NIX_DONT_SET_RPATH" != "1"; then esac rpath="$rpath $1 " } - findLib() { - for i in $libPath; do - if test -f $i/lib$1.so; then + + for i in $libPath; do + n=0 + while test $n -lt ${#allParams[*]}; do + p=${allParams[n]} + p2=${allParams[$((n+1))]} + if test "${p:0:2}" = "-l" -a -f "$i/lib${p:2}.so"; then addToRPath $i + break + elif test "$p" = "-l" -a -f "$i/lib${p2}"; then + # I haven't seen `-l foo', but you never know... + addToRPath $i + break fi - done - } - n=0 - while test $n -lt ${#allParams[*]}; do - p=${allParams[n]} - p2=${allParams[$((n+1))]} - if test "${p:0:2}" = "-l"; then - findLib ${p:2} - elif test "$p" = "-l"; then - # I haven't seen `-l foo', but you never know... - findLib ${p2} n=$((n + 1)) - fi - n=$((n + 1)) + done + done + # Finally, add `-rpath' switches. for i in $rpath; do