Fixing once again the ld-wrapper.sh script. I put it in a gcc-wrapper apart, to be removed

on the next stdenv-updates.
This would fix the build for many cmake packages, although that requires updating the stdenv
in those for its gcc to use this 2nd wrapper.

I updated paraview and avidemux. I can't recall now more packages with problems, but I was
quite sure there were.

If anyone sees a cmake-built package with the result binaries lacking some rpaths, then try
this wrapper.


svn path=/nixpkgs/trunk/; revision=20669
This commit is contained in:
Lluís Batlle i Rossell 2010-03-16 20:49:26 +00:00
parent d1217f68a4
commit dd4ad6741e
3 changed files with 235 additions and 2 deletions

View File

@ -0,0 +1,72 @@
# The Nix `gcc' stdenv.mkDerivation is not directly usable, since it doesn't
# know where the C library and standard header files are. Therefore
# the compiler produced by that package cannot be installed directly
# in a user environment and used from the command line. This
# stdenv.mkDerivation provides a wrapper that sets up the right environment
# variables so that the compiler and the linker just "work".
{ name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? ""
, gcc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? ""
, zlib ? null
}:
assert nativeTools -> nativePrefix != "";
assert !nativeTools -> gcc != null && binutils != null && coreutils != null;
assert !nativeLibc -> libc != null;
# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper
assert (gcc != null && gcc ? langVhdl && gcc.langVhdl) -> zlib != null;
let
gccVersion = (builtins.parseDrvName gcc.name).version;
gccName = (builtins.parseDrvName gcc.name).name;
in
stdenv.mkDerivation {
name =
(if name != "" then name else gccName + "-wrapper") +
(if gcc != null && gccVersion != "" then "-" + gccVersion else "");
builder = ./builder.sh;
setupHook = ./setup-hook.sh;
gccWrapper = ./gcc-wrapper.sh;
gnatWrapper = ./gnat-wrapper.sh;
gnatlinkWrapper = ./gnatlink-wrapper.sh;
ldWrapper = ./ld-wrapper2.sh;
utils = ./utils.sh;
addFlags = ./add-flags;
inherit nativeTools nativeLibc nativePrefix gcc;
libc = if nativeLibc then null else libc;
binutils = if nativeTools then null else binutils;
# The wrapper scripts use 'cat', so we may need coreutils
coreutils = if nativeTools then null else coreutils;
langC = if nativeTools then true else gcc.langC;
langCC = if nativeTools then true else gcc.langCC;
langFortran = if nativeTools then false else gcc ? langFortran;
langAda = if nativeTools then false else gcc ? langAda && gcc.langAda;
langVhdl = if nativeTools then false else gcc ? langVhdl && gcc.langVhdl;
zlib = if (gcc != null && gcc ? langVhdl) then zlib else null;
shell = if shell == "" then stdenv.shell else shell;
meta =
let gcc_ = if gcc != null then gcc else {}; in
(if gcc_ ? meta then removeAttrs gcc.meta ["priority"] else {}) //
{ description =
stdenv.lib.attrByPath ["meta" "description"] "System C compiler" gcc_
+ " (wrapper script)";
};
# The dynamic linker has different names on different Linux platforms.
dynamicLinker =
if !nativeLibc then
(if stdenv.system == "i686-linux" then "ld-linux.so.2" else
if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
if stdenv.system == "armv5tel-linux" then "ld-linux.so.3" else
if stdenv.system == "powerpc-linux" then "ld.so.1" else
abort "don't know the name of the dynamic linker for this platform")
else "";
}

View File

@ -0,0 +1,153 @@
#! @shell@ -e
if test -n "$NIX_LD_WRAPPER_START_HOOK"; then
source "$NIX_LD_WRAPPER_START_HOOK"
fi
if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then
source @out@/nix-support/add-flags.sh
fi
source @out@/nix-support/utils.sh
# Optionally filter out paths not refering to the store.
params=("$@")
if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE" \
-a \( -z "$NIX_IGNORE_LD_THROUGH_GCC" -o -z "$NIX_LDFLAGS_SET" \); then
rest=()
n=0
while test $n -lt ${#params[*]}; do
p=${params[n]}
p2=${params[$((n+1))]}
if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
skip $p
elif test "$p" = "-L" && badPath "$p2"; then
n=$((n + 1)); skip $p2
elif test "$p" = "-rpath" && badPath "$p2"; then
n=$((n + 1)); skip $p2
elif test "$p" = "-dynamic-linker" && badPath "$p2"; then
n=$((n + 1)); skip $p2
elif test "${p:0:1}" = "/" && badPath "$p"; then
# We cannot skip this; barf.
echo "impure path \`$p' used in link" >&2
exit 1
else
rest=("${rest[@]}" "$p")
fi
n=$((n + 1))
done
params=("${rest[@]}")
fi
extra=()
extraBefore=()
if test -z "$NIX_LDFLAGS_SET"; then
extra=(${extra[@]} $NIX_LDFLAGS)
extraBefore=(${extraBefore[@]} $NIX_LDFLAGS_BEFORE)
fi
# Add all used dynamic libraries to the rpath.
if test "$NIX_DONT_SET_RPATH" != "1"; then
libPath=""
addToLibPath() {
local path="$1"
if test "${path:0:1}" != "/"; then return 0; fi
case "$path" in
*..*|*./*|*/.*|*//*)
local path2
if path2=$(readlink -f "$path"); then
path="$path2"
fi
;;
esac
case $libPath in
*\ $path\ *) return 0 ;;
esac
libPath="$libPath $path "
}
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
# copied to $out/lib. If not, we're screwed.
if test "${1:0:${#NIX_STORE}}" != "$NIX_STORE"; then return 0; fi
case $rpath in
*\ $1\ *) return 0 ;;
esac
rpath="$rpath $1 "
}
rpath=""
# First, find all -L... switches.
allParams=("${params[@]}" ${extra[@]})
n=0
while test $n -lt ${#allParams[*]}; do
p=${allParams[n]}
p2=${allParams[$((n+1))]}
if test "${p:0:3}" = "-L/"; then
addToLibPath ${p:2}
elif test "$p" = "-L"; then
addToLibPath ${p2}
n=$((n + 1))
elif [[ "$p" =~ ^[^-].*\.so($|\.) ]]; then
# This is a direct reference to a shared library, so add
# its directory to the rpath.
path="$(dirname "$p")";
addToRPath "${path}"
fi
n=$((n + 1))
done
# 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.
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
n=$((n + 1))
done
done
# Finally, add `-rpath' switches.
for i in $rpath; do
extra=(${extra[@]} -rpath $i)
done
fi
# Optionally print debug info.
if test "$NIX_DEBUG" = "1"; then
echo "original flags to @ld@:" >&2
for i in "${params[@]}"; do
echo " $i" >&2
done
echo "extra flags to @ld@:" >&2
for i in ${extra[@]}; do
echo " $i" >&2
done
fi
if test -n "$NIX_LD_WRAPPER_EXEC_HOOK"; then
source "$NIX_LD_WRAPPER_EXEC_HOOK"
fi
exec @ld@ ${extraBefore[@]} "${params[@]}" ${extra[@]}

View File

@ -2466,6 +2466,12 @@ let
};
wrapGCC = wrapGCCWith (import ../build-support/gcc-wrapper) glibc;
# To be removed on stdenv-updates
# By now this has at least the fix of setting the proper rpath when a file "libbla.so"
# is passed directly to the linker.
# This is of interest to programs built by cmake, because this is a common practice
# in cmake builds.
wrapGCC2 = wrapGCCWith (import ../build-support/gcc-wrapper/default2.nix) glibc;
wrapGCCCross =
{gcc, libc, binutils, cross, shell ? "", name ? "gcc-cross-wrapper"}:
@ -6769,10 +6775,11 @@ let
};
avidemux = import ../applications/video/avidemux {
inherit fetchurl stdenv cmake pkgconfig libxml2 qt4 gettext SDL libxslt x264
inherit fetchurl cmake pkgconfig libxml2 qt4 gettext SDL libxslt x264
alsaLib lame faac faad2 libvorbis;
inherit (gtkLibs) gtk;
inherit (xlibs) libXv pixman libpthreadstubs libXau libXdmcp;
stdenv = overrideGCC stdenv (wrapGCC2 gcc.gcc);
};
awesome = import ../applications/window-managers/awesome {
@ -7900,7 +7907,8 @@ let
};
paraview = import ../applications/graphics/paraview {
inherit fetchurl stdenv cmake qt4;
inherit fetchurl cmake qt4;
stdenv = overrideGCC stdenv (wrapGCC2 gcc.gcc);
};
partitionManager = import ../tools/misc/partition-manager {