summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorDan Peebles <thetypesaretoobig@gmail.com>2015-02-08 13:36:13 -0500
committerDan Peebles <thetypesaretoobig@gmail.com>2015-02-08 21:15:22 -0500
commit7bea6aafae10731b53e2f8b9a66d6488a3a9f54a (patch)
treeedbf71a01d9ade05059235ec4c16829317554c55 /pkgs/build-support
parentc165f24208d770713934c0cd943255d54a73d35c (diff)
downloadnixpkgs-7bea6aafae10731b53e2f8b9a66d6488a3a9f54a.tar
nixpkgs-7bea6aafae10731b53e2f8b9a66d6488a3a9f54a.tar.gz
nixpkgs-7bea6aafae10731b53e2f8b9a66d6488a3a9f54a.tar.bz2
nixpkgs-7bea6aafae10731b53e2f8b9a66d6488a3a9f54a.tar.lz
nixpkgs-7bea6aafae10731b53e2f8b9a66d6488a3a9f54a.tar.xz
nixpkgs-7bea6aafae10731b53e2f8b9a66d6488a3a9f54a.tar.zst
nixpkgs-7bea6aafae10731b53e2f8b9a66d6488a3a9f54a.zip
Some cc-wrapper changes to better support darwin and clang:
- Add a conditional flag for the c++ std lib
- Build binaries that get linked by our own dyld (someday)
- Automatically add framework directories in the setup hook
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/cc-wrapper/cc-wrapper.sh7
-rw-r--r--pkgs/build-support/cc-wrapper/default.nix25
-rw-r--r--pkgs/build-support/cc-wrapper/setup-hook.sh4
3 files changed, 29 insertions, 7 deletions
diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh
index 9284a62c643..548b1910645 100644
--- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh
+++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh
@@ -79,6 +79,13 @@ if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
     params=("${rest[@]}")
 fi
 
+if [[ "@prog@" = *++ ]]; then
+    if  echo "$@" | grep -qvw -- -nostdlib; then
+        NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE $NIX_CXXSTDLIB_COMPILE"
+        NIX_CFLAGS_LINK="$NIX_CFLAGS_LINK $NIX_CXXSTDLIB_LINK"
+    fi
+fi
+
 # Add the flags for the C compiler proper.
 extraAfter=($NIX_CFLAGS_COMPILE)
 extraBefore=()
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index 5d05b5eff86..ac33a0b083c 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -8,6 +8,7 @@
 { name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? ""
 , cc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? stdenv.shell
 , zlib ? null, extraPackages ? []
+, dyld ? null # TODO: should this be a setup-hook on dyld?
 , setupHook ? ./setup-hook.sh
 }:
 
@@ -55,7 +56,7 @@ stdenv.mkDerivation {
       }
     ''
 
-    + optionalString (!nativeLibc) ''
+    + optionalString (!nativeLibc) (if (!stdenv.isDarwin) then ''
       dynamicLinker="$libc/lib/$dynamicLinker"
       echo $dynamicLinker > $out/nix-support/dynamic-linker
 
@@ -63,6 +64,17 @@ stdenv.mkDerivation {
         echo $libc/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
       fi
 
+      # 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).
+      echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before
+    '' else ''
+      echo $dynamicLinker > $out/nix-support/dynamic-linker
+
+      echo "export LD_DYLD_PATH=\"$dynamicLinker\"" >> $out/nix-support/setup-hook
+    '')
+
+    + optionalString (!nativeLibc) ''
       # 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.  (This is only an issue when using an `impure'
@@ -78,11 +90,6 @@ stdenv.mkDerivation {
 
       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).
-      echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before
-
       echo $libc > $out/nix-support/orig-libc
     ''
 
@@ -213,7 +220,10 @@ stdenv.mkDerivation {
     ''
 
     + ''
-      substituteAll ${setupHook} $out/nix-support/setup-hook
+      substituteAll ${setupHook} $out/nix-support/setup-hook.tmp
+      cat $out/nix-support/setup-hook.tmp >> $out/nix-support/setup-hook
+      rm $out/nix-support/setup-hook.tmp
+
       substituteAll ${./add-flags} $out/nix-support/add-flags.sh
       cp -p ${./utils.sh} $out/nix-support/utils.sh
     '';
@@ -227,6 +237,7 @@ stdenv.mkDerivation {
        if stdenv.isArm then "ld-linux*.so.3" else
        if stdenv.system == "powerpc-linux" then "ld.so.1" else
        if stdenv.system == "mips64el-linux" then "ld.so.1" else
+       if stdenv.system == "x86_64-darwin" then "${dyld}/lib/dyld" else
        abort "Don't know the name of the dynamic linker for this platform.")
     else "";
 
diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh
index e23d7f4cf12..648afda6ebb 100644
--- a/pkgs/build-support/cc-wrapper/setup-hook.sh
+++ b/pkgs/build-support/cc-wrapper/setup-hook.sh
@@ -12,6 +12,10 @@ addCVars () {
     if [ -d $1/lib ]; then
         export NIX_LDFLAGS+=" -L$1/lib"
     fi
+
+    if test -d $1/Library/Frameworks; then
+        export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -F$1/Library/Frameworks"
+    fi
 }
 
 envHooks+=(addCVars)