From 48f63c2f2e3752df2a0b73cad9b9bba9eda8ac60 Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Fri, 9 Jan 2015 11:22:12 -0800 Subject: rename gcc-wrapper to cc-wrapper. also makes cc-wrapper compatible with clang in the darwin fork. --- pkgs/build-support/cc-wrapper/setup-hook.sh | 38 +++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 pkgs/build-support/cc-wrapper/setup-hook.sh (limited to 'pkgs/build-support/cc-wrapper/setup-hook.sh') diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh new file mode 100644 index 000000000000..218899e9d8fc --- /dev/null +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -0,0 +1,38 @@ +export NIX_CC=@out@ + +addCVars () { + if [ -d $1/include ]; then + export NIX_CFLAGS_COMPILE+=" -isystem $1/include" + fi + + if [ -d $1/lib64 -a ! -L $1/lib64 ]; then + export NIX_LDFLAGS+=" -L$1/lib64" + fi + + if [ -d $1/lib ]; then + export NIX_LDFLAGS+=" -L$1/lib" + fi +} + +envHooks+=(addCVars) + +# Note: these come *after* $out in the PATH (see setup.sh). + +if [ -n "@cc@" ]; then + addToSearchPath PATH @cc@/bin +fi + +if [ -n "@binutils@" ]; then + addToSearchPath PATH @binutils@/bin +fi + +if [ -n "@libc@" ]; then + addToSearchPath PATH @libc@/bin +fi + +if [ -n "@coreutils@" ]; then + addToSearchPath PATH @coreutils@/bin +fi + +export CC=cc +export CXX=c++ -- cgit 1.4.1 From 7dc57a389e3d3eb5b5e8de3b02dfe469496fad1a Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Fri, 16 Jan 2015 10:50:53 -0500 Subject: cc-wrapper: Set CC/CXX more specifically if possible --- pkgs/build-support/cc-wrapper/default.nix | 6 ++++++ pkgs/build-support/cc-wrapper/setup-hook.sh | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'pkgs/build-support/cc-wrapper/setup-hook.sh') diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix index abbba31641b3..3f8c3de6a2f3 100644 --- a/pkgs/build-support/cc-wrapper/default.nix +++ b/pkgs/build-support/cc-wrapper/default.nix @@ -160,12 +160,18 @@ stdenv.mkDerivation { wrap ld.bfd ${./ld-wrapper.sh} $binutils/bin/ld.bfd fi + export real_cc=cc + export real_cxx=c++ if [ -e $ccPath/gcc ]; then wrap gcc ${./cc-wrapper.sh} $ccPath/gcc ln -s gcc $out/bin/cc + export real_cc=gcc + export real_cxx=g++ elif [ -e $ccPath/clang ]; then wrap clang ${./cc-wrapper.sh} $ccPath/clang ln -s clang $out/bin/cc + export real_cc=clang + export real_cxx=clang++ fi if [ -e $ccPath/g++ ]; then diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index 218899e9d8fc..cd98f57ee937 100644 --- a/pkgs/build-support/cc-wrapper/setup-hook.sh +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -34,5 +34,5 @@ if [ -n "@coreutils@" ]; then addToSearchPath PATH @coreutils@/bin fi -export CC=cc -export CXX=c++ +export CC=@real_cc@ +export CXX=@real_cxx@ -- cgit 1.4.1 From 9bccb95a82de93d0419495acaf0ae0af581d4642 Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Sun, 25 Jan 2015 23:29:06 -0500 Subject: cc-wrapper: Fix for cross-compiling Fixes #5949 Suggested by @ambrop72 --- pkgs/build-support/cc-wrapper/setup-hook.sh | 9 +++++++-- pkgs/build-support/gcc-cross-wrapper/setup-hook.sh | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'pkgs/build-support/cc-wrapper/setup-hook.sh') diff --git a/pkgs/build-support/cc-wrapper/setup-hook.sh b/pkgs/build-support/cc-wrapper/setup-hook.sh index cd98f57ee937..e23d7f4cf12b 100644 --- a/pkgs/build-support/cc-wrapper/setup-hook.sh +++ b/pkgs/build-support/cc-wrapper/setup-hook.sh @@ -34,5 +34,10 @@ if [ -n "@coreutils@" ]; then addToSearchPath PATH @coreutils@/bin fi -export CC=@real_cc@ -export CXX=@real_cxx@ +if [ -z "$crossConfig" ]; then + export CC=@real_cc@ + export CXX=@real_cxx@ +else + export BUILD_CC=@real_cc@ + export BUILD_CXX=@real_cxx@ +fi diff --git a/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh b/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh index ce5f6e56136e..599954bd127d 100644 --- a/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh +++ b/pkgs/build-support/gcc-cross-wrapper/setup-hook.sh @@ -85,3 +85,6 @@ if test "$NIX_NO_SELF_RPATH" != "1"; then export NIX_CROSS_LDFLAGS="-rpath $out/lib64 -rpath-link $out/lib $NIX_CROSS_LDFLAGS" fi fi + +export CC=${crossConfig}-gcc +export CXX=${crossConfig}-g++ -- cgit 1.4.1 From 7bea6aafae10731b53e2f8b9a66d6488a3a9f54a Mon Sep 17 00:00:00 2001 From: Dan Peebles Date: Sun, 8 Feb 2015 13:36:13 -0500 Subject: 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 --- pkgs/build-support/cc-wrapper/cc-wrapper.sh | 7 +++++++ pkgs/build-support/cc-wrapper/default.nix | 25 ++++++++++++++++++------- pkgs/build-support/cc-wrapper/setup-hook.sh | 4 ++++ 3 files changed, 29 insertions(+), 7 deletions(-) (limited to 'pkgs/build-support/cc-wrapper/setup-hook.sh') diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index 9284a62c643f..548b19106457 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 5d05b5eff869..ac33a0b083c2 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 e23d7f4cf12b..648afda6ebb9 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) -- cgit 1.4.1