diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2006-10-24 18:26:23 +0000 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2006-10-24 18:26:23 +0000 |
commit | b342dcb13bae24e81c55327d4c5276c7ed73f8c8 (patch) | |
tree | 351527ea3f0cb7e5197ac4a00b79d882f89c3350 /pkgs/build-support | |
parent | 5f4f8766cfd3a46433855716011ba015711eddd6 (diff) | |
download | nixlib-b342dcb13bae24e81c55327d4c5276c7ed73f8c8.tar nixlib-b342dcb13bae24e81c55327d4c5276c7ed73f8c8.tar.gz nixlib-b342dcb13bae24e81c55327d4c5276c7ed73f8c8.tar.bz2 nixlib-b342dcb13bae24e81c55327d4c5276c7ed73f8c8.tar.lz nixlib-b342dcb13bae24e81c55327d4c5276c7ed73f8c8.tar.xz nixlib-b342dcb13bae24e81c55327d4c5276c7ed73f8c8.tar.zst nixlib-b342dcb13bae24e81c55327d4c5276c7ed73f8c8.zip |
* gcc-wrapper: separately store the flags necessary to find GCC and
Glibc. This is useful when building GCC. * gcc-wrapper: the dynamic linker has a different name on x86_64 and powerpc. * gcc-wrapper: "glibc" -> "libc", because someday we might support different C libraries. * gcc: don't do a multilib build (e.g., 32-bit support on x86_64), don't need it. * gcc: merge in support for static builds. * gcc: various simplifications in the compiler/linker flags, hope they work. svn path=/nixpkgs/trunk/; revision=6823
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/gcc-wrapper/add-flags | 29 | ||||
-rw-r--r-- | pkgs/build-support/gcc-wrapper/builder.sh | 47 | ||||
-rw-r--r-- | pkgs/build-support/gcc-wrapper/default.nix | 19 | ||||
-rw-r--r-- | pkgs/build-support/gcc-wrapper/gcc-wrapper.sh | 6 | ||||
-rw-r--r-- | pkgs/build-support/gcc-wrapper/ld-wrapper.sh | 6 | ||||
-rw-r--r-- | pkgs/build-support/gcc-wrapper/setup-hook.sh | 4 |
6 files changed, 69 insertions, 42 deletions
diff --git a/pkgs/build-support/gcc-wrapper/add-flags b/pkgs/build-support/gcc-wrapper/add-flags index ac1e58ebb812..63a483460015 100644 --- a/pkgs/build-support/gcc-wrapper/add-flags +++ b/pkgs/build-support/gcc-wrapper/add-flags @@ -1,5 +1,24 @@ -export NIX_CFLAGS_COMPILE="@cflagsCompile@ $NIX_CFLAGS_COMPILE" -export NIX_CFLAGS_LINK="@cflagsLink@ $NIX_CFLAGS_LINK" -export NIX_LDFLAGS="@ldflags@ $NIX_LDFLAGS" -export NIX_LDFLAGS_BEFORE="@ldflagsBefore@ $NIX_LDFLAGS_BEFORE" -export NIX_GLIBC_FLAGS_SET=1 +# `-B@out@/bin' forces gcc to use ld-wrapper.sh when calling ld. +export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE" + +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-ldflags; then + export NIX_LDFLAGS="$(cat @out@/nix-support/gcc-ldflags) $NIX_LDFLAGS" +fi + +if test -e @out@/nix-support/gcc-ldflags; then + export NIX_LDFLAGS="$(cat @out@/nix-support/gcc-ldflags) $NIX_LDFLAGS" +fi + +if test -e @out@/nix-support/libc-ldflags-before; then + export NIX_LDFLAGS_BEFORE="$(cat @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE" +fi + +export NIX_GCC_WRAPPER_FLAGS_SET=1 diff --git a/pkgs/build-support/gcc-wrapper/builder.sh b/pkgs/build-support/gcc-wrapper/builder.sh index b9a811dd7471..c0b124fec0c6 100644 --- a/pkgs/build-support/gcc-wrapper/builder.sh +++ b/pkgs/build-support/gcc-wrapper/builder.sh @@ -2,20 +2,27 @@ source $stdenv/setup source $substitute -# Force gcc to use ld-wrapper.sh when calling ld. -cflagsCompile="-B$out/bin/" +mkdir $out +mkdir $out/bin +mkdir $out/nix-support -if test -z "$nativeGlibc"; then - # The "-B$glibc/lib/" flag is a quick hack to force gcc to link + +if test -z "$nativeLibc"; then + dynamicLinker="$libc/lib/$dynamicLinker" + echo $dynamicLinker > $out/nix-support/dynamic-linker + + # The "-B$libc/lib/" flag is a quick hack to force gcc to link # against the crt1.o from our own glibc, rather than the one in - # /usr/lib. The real solution is of course to prevent those paths - # from being used by gcc in the first place. + # /usr/lib. (This is only an issue when using an `impure' + # compiler/linker, i.e., one that searches /usr/lib and so on.) + echo "-B$libc/lib/ -isystem $libc/include" > $out/nix-support/libc-cflags + + echo "-L$libc/lib" > $out/nix-support/libc-ldflags + # The dynamic linker is passed in `ldflagsBefore' to allow # explicit overrides of the dynamic linker by callers to gcc/ld # (the *last* value counts, so ours should come first). - cflagsCompile="$cflagsCompile -B$glibc/lib/ -isystem $glibc/include" - ldflags="$ldflags -L$glibc/lib" - ldflagsBefore="-dynamic-linker $glibc/lib/ld-linux.so.2" + echo "-dynamic-linker $dynamicLinker" > $out/nix-support/libc-ldflags-before fi if test -n "$nativeTools"; then @@ -23,19 +30,15 @@ if test -n "$nativeTools"; then ldPath="$nativePrefix/bin" else if test -e "$gcc/lib64"; then - ldflags="$ldflags -L$gcc/lib64" + gccLDFlags="$gccLDFlags -L$gcc/lib64" fi - ldflags="$ldflags -L$gcc/lib" + gccLDFlags="$gccLDFlags -L$gcc/lib" + echo "$gccLDFlags" > $out/nix-support/gcc-ldflags gccPath="$gcc/bin" ldPath="$binutils/bin" fi -mkdir $out -mkdir $out/bin -mkdir $out/nix-support - - doSubstitute() { local src=$1 local dst=$2 @@ -45,11 +48,7 @@ doSubstitute() { --subst-var "gcc" \ --subst-var "gccProg" \ --subst-var "binutils" \ - --subst-var "glibc" \ - --subst-var "cflagsCompile" \ - --subst-var "cflagsLink" \ - --subst-var "ldflags" \ - --subst-var "ldflagsBefore" \ + --subst-var "libc" \ --subst-var-by "ld" "$ldPath/ld" } @@ -88,10 +87,10 @@ chmod +x "$out/bin/ld" # Emit a setup hook. Also store the path to the original GCC and # Glibc. test -n "$gcc" && echo $gcc > $out/nix-support/orig-gcc -test -n "$glibc" && echo $glibc > $out/nix-support/orig-glibc +test -n "$libc" && echo $libc > $out/nix-support/orig-libc -doSubstitute "$addFlags" "$out/nix-support/add-flags" +doSubstitute "$addFlags" "$out/nix-support/add-flags.sh" doSubstitute "$setupHook" "$out/nix-support/setup-hook" -cp -p $utils $out/nix-support/utils +cp -p $utils $out/nix-support/utils.sh diff --git a/pkgs/build-support/gcc-wrapper/default.nix b/pkgs/build-support/gcc-wrapper/default.nix index c48ee635f37c..2edd0049dc17 100644 --- a/pkgs/build-support/gcc-wrapper/default.nix +++ b/pkgs/build-support/gcc-wrapper/default.nix @@ -5,13 +5,13 @@ # stdenv.mkDerivation provides a wrapper that sets up the right environment # variables so that the compiler and the linker just "work". -{ name ? "", stdenv, nativeTools, nativeGlibc, nativePrefix ? "" -, gcc ? null, glibc ? null, binutils ? null, shell ? "" +{ name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? "" +, gcc ? null, libc ? null, binutils ? null, shell ? "" }: assert nativeTools -> nativePrefix != ""; assert !nativeTools -> gcc != null && binutils != null; -assert !nativeGlibc -> glibc != null; +assert !nativeLibc -> libc != null; stdenv.mkDerivation { builder = ./builder.sh; @@ -21,7 +21,7 @@ stdenv.mkDerivation { ldWrapper = ./ld-wrapper.sh; utils = ./utils.sh; addFlags = ./add-flags; - inherit nativeTools nativeGlibc nativePrefix gcc glibc binutils; + inherit nativeTools nativeLibc nativePrefix gcc libc binutils; name = if name == "" then gcc.name else name; langC = if nativeTools then true else gcc.langC; langCC = if nativeTools then true else gcc.langCC; @@ -30,4 +30,13 @@ stdenv.mkDerivation { meta = if gcc != null && (gcc ? meta) then gcc.meta else { description = "System C compiler wrapper"; }; -} \ No newline at end of file + + # 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 == "powerpc-linux" then "ld.so.1" else + abort "don't know the name of the dynamic linker for this platform") + else ""; +} diff --git a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh index 51916ccdd4a1..fda6b65c5251 100644 --- a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh +++ b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh @@ -4,11 +4,11 @@ if test -n "$NIX_GCC_WRAPPER_START_HOOK"; then source "$NIX_GCC_WRAPPER_START_HOOK" fi -if test -z "$NIX_GLIBC_FLAGS_SET"; then - source @out@/nix-support/add-flags +if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then + source @out@/nix-support/add-flags.sh fi -source @out@/nix-support/utils +source @out@/nix-support/utils.sh # Figure out if linker flags should be passed. GCC prints annoying diff --git a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh index cc1b125804a4..94241e42ce9b 100644 --- a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh @@ -4,11 +4,11 @@ if test -n "$NIX_LD_WRAPPER_START_HOOK"; then source "$NIX_LD_WRAPPER_START_HOOK" fi -if test -z "$NIX_GLIBC_FLAGS_SET"; then - source @out@/nix-support/add-flags +if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then + source @out@/nix-support/add-flags.sh fi -source @out@/nix-support/utils +source @out@/nix-support/utils.sh # Optionally filter out paths not refering to the store. diff --git a/pkgs/build-support/gcc-wrapper/setup-hook.sh b/pkgs/build-support/gcc-wrapper/setup-hook.sh index 1739d8dcae53..60aad0fe4dc6 100644 --- a/pkgs/build-support/gcc-wrapper/setup-hook.sh +++ b/pkgs/build-support/gcc-wrapper/setup-hook.sh @@ -24,6 +24,6 @@ if test -n "@binutils@"; then PATH=$PATH:@binutils@/bin fi -if test -n "@glibc@"; then - PATH=$PATH:@glibc@/bin +if test -n "@libc@"; then + PATH=$PATH:@libc@/bin fi |