summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2004-03-08 16:02:46 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2004-03-08 16:02:46 +0000
commitce50734cf067496ae50d1a6fd139fc03de283cbc (patch)
tree8603be7a557177d8646093c4edf7bdb097577b11 /pkgs/build-support
parent1b8e9faf08d2bb5fe83464d8380dabc52982f935 (diff)
downloadnixlib-ce50734cf067496ae50d1a6fd139fc03de283cbc.tar
nixlib-ce50734cf067496ae50d1a6fd139fc03de283cbc.tar.gz
nixlib-ce50734cf067496ae50d1a6fd139fc03de283cbc.tar.bz2
nixlib-ce50734cf067496ae50d1a6fd139fc03de283cbc.tar.lz
nixlib-ce50734cf067496ae50d1a6fd139fc03de283cbc.tar.xz
nixlib-ce50734cf067496ae50d1a6fd139fc03de283cbc.tar.zst
nixlib-ce50734cf067496ae50d1a6fd139fc03de283cbc.zip
* Started reorganising stdenv:
  - gcc/ld-wrappers have been factored out into a separate
    derivation.  This allows a working gcc to be installed in the user
    environment.  (Previously the Nix gcc didn't work because it
    needed a whole bunch of flags to point to glibc.)
    
  - Better modularity: packages can specify hooks into the setup
    scripts.  For instance, setup no longer knows about the
    PKG_CONFIG_PATH variable; pkgconfig can set it up instead.

  - gcc not longer depends on binutils.  This simplifies the bootstrap
    process.

svn path=/nixpkgs/trunk/; revision=816
Diffstat (limited to 'pkgs/build-support')
-rwxr-xr-xpkgs/build-support/gcc-wrapper/builder.sh62
-rw-r--r--pkgs/build-support/gcc-wrapper/default.nix23
-rw-r--r--pkgs/build-support/gcc-wrapper/gcc-wrapper.sh74
-rw-r--r--pkgs/build-support/gcc-wrapper/ld-wrapper.sh28
-rw-r--r--pkgs/build-support/gcc-wrapper/setup-hook.sh15
5 files changed, 202 insertions, 0 deletions
diff --git a/pkgs/build-support/gcc-wrapper/builder.sh b/pkgs/build-support/gcc-wrapper/builder.sh
new file mode 100755
index 000000000000..d3b1f433559c
--- /dev/null
+++ b/pkgs/build-support/gcc-wrapper/builder.sh
@@ -0,0 +1,62 @@
+#! /bin/sh -e
+
+. $stdenv/setup
+
+if test -z "$isNative"; then
+    cflagsCompile="-B$out/bin -B$glibc/lib -isystem $glibc/include"
+    ldflags="-L$glibc/lib -L$gcc/lib " \
+        "-dynamic-linker $glibc/lib/ld-linux.so.2" \
+        "-rpath $glibc/lib -rpath $gcc/lib"
+else
+    cflagsCompile="-B$out/bin"
+fi
+
+mkdir $out
+mkdir $out/bin
+
+
+mkGccWrapper () {
+    local dst=$1
+    local src=$2
+
+    if ! test -f "$src"; then
+        echo "$src does not exist (skipping)"
+        return
+    fi
+
+    sed \
+        -e "s^@cflagsCompile@^$cflagsCompile^g" \
+        -e "s^@cflagsLink@^$cflagsLink^g" \
+        -e "s^@ldflags@^$ldflags^g" \
+        -e "s^@gcc@^$src^g" \
+        < $gccWrapper > $dst
+    chmod +x $dst
+
+}
+
+mkGccWrapper $out/bin/gcc $gcc/bin/gcc
+ln -s gcc $out/bin/cc
+
+mkGccWrapper $out/bin/g++ $gcc/bin/g++
+ln -s g++ $out/bin/c++
+
+mkGccWrapper $out/bin/g77 $gcc/bin/g77
+ln -s g77 $out/bin/f77
+
+
+sed \
+    -e "s^@ldflags@^$ldflags^g" \
+    -e "s^@ld@^$gcc/bin/ld^g" \
+    < $ldWrapper > $out/bin/ld
+chmod +x $out/bin/ld
+
+
+mkdir $out/nix-support
+test -z "$isNative" && echo $gcc > $out/nix-support/orig-gcc
+test -z "$isNative" && echo $glibc > $out/nix-support/orig-glibc
+
+sed \
+    -e "s^@isNative@^$isNative^g" \
+    -e "s^@gcc@^$gcc^g" \
+    -e "s^@glibc@^$glibc^g" \
+    < $setupHook > $out/nix-support/setup-hook
diff --git a/pkgs/build-support/gcc-wrapper/default.nix b/pkgs/build-support/gcc-wrapper/default.nix
new file mode 100644
index 000000000000..da1896611645
--- /dev/null
+++ b/pkgs/build-support/gcc-wrapper/default.nix
@@ -0,0 +1,23 @@
+# The Nix `gcc' derivation 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
+# derivation provides a wrapper that sets up the right environment
+# variables so that the compiler and the linker just "work".
+
+{name, stdenv, isNative, gcc ? null, glibc ? null, binutils ? null}:
+
+assert isNative -> gcc != "";
+assert !isNative -> gcc != null && glibc != null && binutils != null;
+
+derivation {
+  system = stdenv.system;
+  builder = ./builder.sh;
+  setupHook = ./setup-hook.sh;
+  gccWrapper = ./gcc-wrapper.sh;
+  ldWrapper = ./ld-wrapper.sh;
+  inherit name stdenv isNative gcc glibc binutils;
+  langC = if isNative then true else gcc.langC;
+  langCC = if isNative then true else gcc.langCC;
+  langF77 = if isNative then false else gcc.langF77;
+}
diff --git a/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
new file mode 100644
index 000000000000..59f38086f325
--- /dev/null
+++ b/pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
@@ -0,0 +1,74 @@
+#! /bin/sh
+
+if test -n "$NIX_GCC_WRAPPER_START_HOOK"; then
+    . "$NIX_GCC_WRAPPER_START_HOOK"
+fi
+
+if test -z "$NIX_GLIBC_FLAGS_SET"; then
+    NIX_CFLAGS_COMPILE="@cflagsCompile@ $NIX_CFLAGS_COMPILE"
+    NIX_CFLAGS_LINK="@cflagsLink@ $NIX_CFLAGS_LINK"
+    NIX_LDFLAGS="@ldflags@ $NIX_LDFLAGS"
+fi
+
+# Figure out if linker flags should be passed.  GCC prints annoying
+# warnings when they are not needed.
+dontLink=0
+if test "$*" = "-v"; then
+    dontLink=1
+else    
+    for i in "$@"; do
+        if test "$i" = "-c"; then
+            dontLink=1
+        elif test "$i" = "-S"; then
+            dontLink=1
+        elif test "$i" = "-E"; then
+            dontLink=1
+        elif test "$i" = "-E"; then
+            dontLink=1
+        elif test "$i" = "-M"; then
+            dontLink=1
+        elif test "$i" = "-MM"; then
+            dontLink=1
+        fi
+    done
+fi
+
+# Add the flags for the C compiler proper.
+extra=($NIX_CFLAGS_COMPILE)
+
+if test "$dontLink" != "1"; then
+
+    # Add the flags that should only be passed to the compiler when
+    # linking.
+    extra=(${extra[@]} $NIX_CFLAGS_LINK)
+
+    # Add the flags that should be passed to the linker (and prevent
+    # `ld-wrapper' from adding NIX_LDFLAGS again).
+    for i in $NIX_LDFLAGS; do
+        extra=(${extra[@]} "-Wl,$i")
+    done
+    export NIX_LDFLAGS_SET=1
+
+    if test "$NIX_STRIP_DEBUG" = "1"; then
+        # Add executable-stripping flags.
+        extra=(${extra[@]} $NIX_CFLAGS_STRIP)
+    fi
+fi
+
+# Optionally print debug info.
+if test "$NIX_DEBUG" = "1"; then
+  echo "original flags to @gcc@:" >&2
+  for i in "$@"; do
+      echo "  $i" >&2
+  done
+  echo "extra flags to @gcc@:" >&2
+  for i in ${extra[@]}; do
+      echo "  $i" >&2
+  done
+fi
+
+if test -n "$NIX_GCC_WRAPPER_EXEC_HOOK"; then
+    . "$NIX_GCC_WRAPPER_EXEC_HOOK"
+fi
+
+exec @gcc@ "$@" ${extra[@]}
diff --git a/pkgs/build-support/gcc-wrapper/ld-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
new file mode 100644
index 000000000000..2201bbe19d23
--- /dev/null
+++ b/pkgs/build-support/gcc-wrapper/ld-wrapper.sh
@@ -0,0 +1,28 @@
+#! /bin/sh
+
+if test -n "$NIX_LD_WRAPPER_START_HOOK"; then
+    . "$NIX_LD_WRAPPER_START_HOOK"
+fi
+
+extra=()
+
+if test -z "$NIX_LDFLAGS_SET"; then
+    extra=(${extra[@]} $NIX_LDFLAGS)
+fi
+
+if test "$NIX_DEBUG" = "1"; then
+  echo "original flags to @ld@:" >&2
+  for i in "$@"; 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
+    . "$NIX_LD_WRAPPER_EXEC_HOOK"
+fi
+
+exec @ld@ "$@" ${extra[@]}
diff --git a/pkgs/build-support/gcc-wrapper/setup-hook.sh b/pkgs/build-support/gcc-wrapper/setup-hook.sh
new file mode 100644
index 000000000000..a4c52ba803d7
--- /dev/null
+++ b/pkgs/build-support/gcc-wrapper/setup-hook.sh
@@ -0,0 +1,15 @@
+addCVars () {
+    if test -d $1/include; then
+        export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I$1/include"
+    fi
+
+    if test -d $1/lib; then
+        export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib -rpath $1/lib"
+    fi
+}
+
+envHooks=(${envHooks[@]} addCVars)
+
+if test -z "@isNative@"; then
+    PATH=$PATH:@gcc@/bin:@glibc@/bin
+fi