···1-# `-B@out@/bin' forces clang to use ld-wrapper.sh when calling ld.
2-export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE"
3-4-if test -e @out@/nix-support/libc-cflags; then
5- export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE"
6-fi
7-8-if test -e @out@/nix-support/clang-cflags; then
9- export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/clang-cflags) $NIX_CFLAGS_COMPILE"
10-fi
11-12-if test -e @out@/nix-support/libc-ldflags; then
13- export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/libc-ldflags)"
14-fi
15-16-if test -e @out@/nix-support/clang-ldflags; then
17- export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/clang-ldflags)"
18-fi
19-20-if test -e @out@/nix-support/libc-ldflags-before; then
21- export NIX_LDFLAGS_BEFORE="$(cat @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE"
22-fi
23-24-export NIX_GCC_WRAPPER_FLAGS_SET=1
···000000000000000000000000
-137
pkgs/build-support/clang-wrapper/builder.sh
···1-source $stdenv/setup
2-3-4-mkdir -p $out/bin
5-mkdir -p $out/nix-support
6-7-8-if test -z "$nativeLibc"; then
9- dynamicLinker="$libc/lib/$dynamicLinker"
10- echo $dynamicLinker > $out/nix-support/dynamic-linker
11-12- if test -e $libc/lib/32/ld-linux.so.2; then
13- echo $libc/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
14- fi
15-16- # The "-B$libc/lib/" flag is a quick hack to force clang to link
17- # against the crt1.o from our own glibc, rather than the one in
18- # /usr/lib. (This is only an issue when using an `impure'
19- # compiler/linker, i.e., one that searches /usr/lib and so on.)
20- echo "-B$libc/lib/ -idirafter $libc/include" > $out/nix-support/libc-cflags
21-22- echo "-L$libc/lib" > $out/nix-support/libc-ldflags
23-24- # The dynamic linker is passed in `ldflagsBefore' to allow
25- # explicit overrides of the dynamic linker by callers to clang/ld
26- # (the *last* value counts, so ours should come first).
27- echo "-dynamic-linker $dynamicLinker" > $out/nix-support/libc-ldflags-before
28-fi
29-30-if test -n "$nativeTools"; then
31- clangPath="$nativePrefix/bin"
32- ldPath="$nativePrefix/bin"
33-else
34- basePath=`echo $gcc/lib/*/*/*`
35- # Need libgcc until the llvm compiler-rt library is complete
36- clangLDFlags="$clangLDFlags -L$basePath"
37- if test -e "$gcc/lib64"; then
38- clangLDFlags="$clangLDFlags -L$gcc/lib64"
39- else
40- clangLDFlags="$clangLDFlags -L$gcc/lib"
41- fi
42-43- clangLDFlags="$clangLDFlags -L$clang/lib"
44- echo "$clangLDFlags" > $out/nix-support/clang-ldflags
45-46- # Need files like crtbegin.o from gcc
47- # It's unclear if these will ever be provided by an LLVM project
48- clangCFlags="$clangCFlags -B$basePath"
49-50- clangCFlags="$clangCFlags -isystem$clang/lib/clang/$clangVersion/include"
51- echo "$clangCFlags" > $out/nix-support/clang-cflags
52-53- clangPath="$clang/bin"
54- ldPath="$binutils/bin"
55-fi
56-57-58-doSubstitute() {
59- local src=$1
60- local dst=$2
61- local uselibcxx=
62- local uselibcxxabi=
63- if test -n "$libcxx" && echo $dst | fgrep ++; then uselibcxx=$libcxx; fi
64- if test -n "$libcxxabi" && echo $dst | fgrep ++; then uselibcxxabi=$libcxxabi; fi
65- # Can't use substitute() here, because replace may not have been
66- # built yet (in the bootstrap).
67- sed \
68- -e "s^@out@^$out^g" \
69- -e "s^@shell@^$shell^g" \
70- -e "s^@libcxx@^$uselibcxx^g" \
71- -e "s^@libcxxabi@^$uselibcxxabi^g" \
72- -e "s^@clang@^$clang^g" \
73- -e "s^@clangProg@^$clangProg^g" \
74- -e "s^@binutils@^$binutils^g" \
75- -e "s^@coreutils@^$coreutils^g" \
76- -e "s^@libc@^$libc^g" \
77- -e "s^@ld@^$ldPath/ld^g" \
78- < "$src" > "$dst"
79-}
80-81-82-# Make wrapper scripts around clang and clang++. Also make symlinks
83-# cc and c++
84-mkClangWrapper() {
85- local dst=$1
86- local src=$2
87-88- if ! test -f "$src"; then
89- echo "$src does not exist (skipping)"
90- return 1
91- fi
92-93- clangProg="$src"
94- doSubstitute "$clangWrapper" "$dst"
95- chmod +x "$dst"
96-}
97-98-if mkClangWrapper $out/bin/clang $clangPath/clang
99-then
100- ln -sv clang $out/bin/cc
101-fi
102-103-if mkClangWrapper $out/bin/clang++ $clangPath/clang++
104-then
105- ln -sv clang++ $out/bin/c++
106-fi
107-108-109-# Create a symlink to as (the assembler). This is useful when a
110-# clang-wrapper is installed in a user environment, as it ensures that
111-# the right assembler is called.
112-ln -s $ldPath/as $out/bin/as
113-114-115-# Make a wrapper around the linker.
116-doSubstitute "$ldWrapper" "$out/bin/ld"
117-chmod +x "$out/bin/ld"
118-119-120-# Emit a setup hook. Also store the path to the original Clang and
121-# libc.
122-test -n "$clang" && echo $clang > $out/nix-support/orig-clang
123-test -n "$libc" && echo $libc > $out/nix-support/orig-libc
124-125-doSubstitute "$addFlags" "$out/nix-support/add-flags.sh"
126-127-doSubstitute "$setupHook" "$out/nix-support/setup-hook"
128-129-cp -p $utils $out/nix-support/utils.sh
130-131-132-# Propagate the wrapped clang so that if you install the wrapper, you get
133-# llvm tools, the manpages, etc. as well (including for binutils
134-# and Glibc).
135-if test -z "$nativeTools"; then
136- echo $clang $binutils $libc > $out/nix-support/propagated-user-env-packages
137-fi
···1-#! @shell@ -e
2-3-if test -n "$NIX_GCC_WRAPPER_START_HOOK"; then
4- source "$NIX_GCC_WRAPPER_START_HOOK"
5-fi
6-7-if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then
8- source @out@/nix-support/add-flags.sh
9-fi
10-11-source @out@/nix-support/utils.sh
12-13-14-# Figure out if linker flags should be passed. Clang prints annoying
15-# warnings when they are not needed. (does it really? Copied from gcc-wrapper)
16-dontLink=0
17-getVersion=0
18-nonFlagArgs=0
19-20-for i in "$@"; do
21- if test "$i" = "-c"; then
22- dontLink=1
23- elif test "$i" = "-S"; then
24- dontLink=1
25- elif test "$i" = "-E"; then
26- dontLink=1
27- elif test "$i" = "-E"; then
28- dontLink=1
29- elif test "$i" = "-M"; then
30- dontLink=1
31- elif test "$i" = "-MM"; then
32- dontLink=1
33- elif test "$i" = "-x"; then
34- # At least for the cases c-header or c++-header we should set dontLink.
35- # I expect no one use -x other than making precompiled headers.
36- dontLink=1
37- elif test "${i:0:1}" != "-"; then
38- nonFlagArgs=1
39- elif test "$i" = "-m32"; then
40- if test -e @out@/nix-support/dynamic-linker-m32; then
41- NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
42- fi
43- fi
44-done
45-46-# If we pass a flag like -Wl, then clang will call the linker unless it
47-# can figure out that it has to do something else (e.g., because of a
48-# "-c" flag). So if no non-flag arguments are given, don't pass any
49-# linker flags. This catches cases like "clang" (should just print
50-# "clang: no input files") and "clang -v" (should print the version).
51-if test "$nonFlagArgs" = "0"; then
52- dontLink=1
53-fi
54-55-# Optionally filter out paths not refering to the store.
56-params=("$@")
57-if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then
58- rest=()
59- n=0
60- while test $n -lt ${#params[*]}; do
61- p=${params[n]}
62- p2=${params[$((n+1))]}
63- if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
64- skip $p
65- elif test "$p" = "-L" && badPath "$p2"; then
66- n=$((n + 1)); skip $p2
67- elif test "${p:0:3}" = "-I/" && badPath "${p:2}"; then
68- skip $p
69- elif test "$p" = "-I" && badPath "$p2"; then
70- n=$((n + 1)); skip $p2
71- elif test "$p" = "-isystem" && badPath "$p2"; then
72- n=$((n + 1)); skip $p2
73- else
74- rest=("${rest[@]}" "$p")
75- fi
76- n=$((n + 1))
77- done
78- params=("${rest[@]}")
79- NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE --sysroot=/var/empty"
80-fi
81-82-if test -n "@libcxx@"; then
83- NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem@libcxx@/include/c++/v1 -stdlib=libc++"
84- NIX_CFLAGS_LINK="$NIX_CFLAGS_LINK -L@libcxx@/lib -stdlib=libc++ -L@libcxxabi@/lib -lc++abi"
85-fi
86-87-# Add the flags for the C compiler proper.
88-extraAfter=($NIX_CFLAGS_COMPILE)
89-extraBefore=()
90-91-if test "$dontLink" != "1"; then
92-93- # Add the flags that should only be passed to the compiler when
94- # linking.
95- extraAfter=(${extraAfter[@]} $NIX_CFLAGS_LINK)
96-97- # Add the flags that should be passed to the linker (and prevent
98- # `ld-wrapper' from adding NIX_LDFLAGS again).
99- for i in $NIX_LDFLAGS_BEFORE; do
100- extraBefore=(${extraBefore[@]} "-Wl,$i")
101- done
102- for i in $NIX_LDFLAGS; do
103- if test "${i:0:3}" = "-L/"; then
104- extraAfter=(${extraAfter[@]} "$i")
105- else
106- extraAfter=(${extraAfter[@]} "-Wl,$i")
107- fi
108- done
109- export NIX_LDFLAGS_SET=1
110-fi
111-112-# As a very special hack, if the arguments are just `-v', then don't
113-# add anything. This is to prevent `clang -v' (which normally prints
114-# out the version number and returns exit code 0) from printing out
115-# `No input files specified' and returning exit code 1.
116-if test "$*" = "-v"; then
117- extraAfter=()
118- extraBefore=()
119-fi
120-121-# Optionally print debug info.
122-if test "$NIX_DEBUG" = "1"; then
123- echo "original flags to @clangProg@:" >&2
124- for i in "${params[@]}"; do
125- echo " $i" >&2
126- done
127- echo "extraBefore flags to @clangProg@:" >&2
128- for i in ${extraBefore[@]}; do
129- echo " $i" >&2
130- done
131- echo "extraAfter flags to @clangProg@:" >&2
132- for i in ${extraAfter[@]}; do
133- echo " $i" >&2
134- done
135-fi
136-137-if test -n "$NIX_CLANG_WRAPPER_EXEC_HOOK"; then
138- source "$NIX_CLANG_WRAPPER_EXEC_HOOK"
139-fi
140-141-# Call the real `clang'. Filter out warnings from stderr about unused
142-# `-B' flags, since they confuse some programs. Deep bash magic to
143-# apply grep to stderr (by swapping stdin/stderr twice).
144-if test -z "$NIX_CLANG_NEEDS_GREP"; then
145- @clangProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
146-else
147- (@clangProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
148- | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
149- exit $?
150-fi
···1-# The Nix `clang' stdenv.mkDerivation is not directly usable, since it doesn't
2-# know where the C library and standard header files are. Therefore
3-# the compiler produced by that package cannot be installed directly
4-# in a user environment and used from the command line. This
5-# stdenv.mkDerivation provides a wrapper that sets up the right environment
6-# variables so that the compiler and the linker just "work".
7-8-{ name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? ""
9-, clang ? null, libc ? null, binutils ? null, coreutils ? null, shell ? ""
10-, zlib ? null, libcxx ? null
11-}:
12-13-assert nativeTools -> nativePrefix != "";
14-assert !nativeTools -> clang != null && binutils != null && coreutils != null;
15-assert !nativeLibc -> libc != null;
16-17-let
18-19- clangVersion = (builtins.parseDrvName clang.name).version;
20- clangName = (builtins.parseDrvName clang.name).name;
21-22-in
23-24-stdenv.mkDerivation {
25- name =
26- (if name != "" then name else clangName + "-wrapper") +
27- (if clang != null && clangVersion != "" then "-" + clangVersion else "");
28-29- builder = ./builder.sh;
30- setupHook = ./setup-hook.sh;
31- clangWrapper = ./clang-wrapper.sh;
32- ldWrapper = ../gcc-wrapper/ld-wrapper.sh;
33- utils = ../gcc-wrapper/utils.sh;
34- addFlags = ./add-flags;
35-36- inherit nativeTools nativeLibc nativePrefix clang clangVersion libcxx;
37-38- libcxxabi = libcxx.abi or null;
39-40- gcc = clang.gcc;
41- libc = if nativeLibc then null else libc;
42- binutils = if nativeTools then null else binutils;
43- # The wrapper scripts use 'cat', so we may need coreutils
44- coreutils = if nativeTools then null else coreutils;
45-46- langC = true;
47- langCC = true;
48- shell = if shell == "" then stdenv.shell else
49- if builtins.isAttrs shell then (shell + shell.shellPath)
50- else shell;
51-52- crossAttrs = {
53- shell = shell.crossDrv + shell.crossDrv.shellPath;
54- libc = libc.crossDrv;
55- coreutils = coreutils.crossDrv;
56- binutils = binutils.crossDrv;
57- clang = clang.crossDrv;
58- #
59- # This is not the best way to do this. I think the reference should be
60- # the style in the gcc-cross-wrapper, but to keep a stable stdenv now I
61- # do this sufficient if/else.
62- dynamicLinker =
63- (if stdenv.cross.arch == "arm" then "ld-linux.so.3" else
64- if stdenv.cross.arch == "mips" then "ld.so.1" else
65- if stdenv.lib.hasSuffix "pc-gnu" stdenv.cross.config then "ld.so.1" else
66- abort "don't know the name of the dynamic linker for this platform");
67- };
68-69- meta =
70- let clang_ = if clang != null then clang else {}; in
71- (if clang_ ? meta then removeAttrs clang.meta ["priority"] else {}) //
72- { description =
73- stdenv.lib.attrByPath ["meta" "description"] "System C compiler" clang_
74- + " (wrapper script)";
75- };
76-77- # The dynamic linker has different names on different Linux platforms.
78- dynamicLinker =
79- if !nativeLibc then
80- (if stdenv.system == "i686-linux" then "ld-linux.so.2" else
81- if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
82- if stdenv.isArm then "ld-linux.so.3" else
83- if stdenv.system == "powerpc-linux" then "ld.so.1" else
84- if stdenv.system == "mips64el-linux" then "ld.so.1" else
85- abort "don't know the name of the dynamic linker for this platform")
86- else "";
87-88- preferLocalBuild = true;
89-}
···1-export NIX_GCC=@out@
2-3-addCVars () {
4- if test -d $1/include; then
5- export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
6- fi
7-8- if test -d $1/lib64; then
9- export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib64"
10- fi
11-12- if test -d $1/lib; then
13- export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib"
14- fi
15-}
16-17-envHooks+=(addCVars)
18-19-# Note: these come *after* $out in the PATH (see setup.sh).
20-21-if test -n "@clang@"; then
22- addToSearchPath PATH @clang@/bin
23-fi
24-25-if test -n "@binutils@"; then
26- addToSearchPath PATH @binutils@/bin
27-fi
28-29-if test -n "@libc@"; then
30- addToSearchPath PATH @libc@/bin
31-fi
32-33-if test -n "@coreutils@"; then
34- addToSearchPath PATH @coreutils@/bin
35-fi
36-37-: ${CXX:=clang++}
38-export CXX
···114# We want gcc to call the wrapper linker, not that of binutils.
115export PATH="@ldPath@:$PATH"
116117-# Call the real `gcc'. Filter out warnings from stderr about unused
118-# `-B' flags, since they confuse some programs. Deep bash magic to
119-# apply grep to stderr (by swapping stdin/stderr twice).
120-if test -z "$NIX_GCC_NEEDS_GREP"; then
121- @gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
122-else
123- (@gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
124- | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
125- exit $?
126-fi
···114# We want gcc to call the wrapper linker, not that of binutils.
115export PATH="@ldPath@:$PATH"
116117+exec @gccProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
000000000
+8-8
pkgs/build-support/gcc-wrapper/add-flags
···1# `-B@out@/bin' forces gcc to use ld-wrapper.sh when calling ld.
2export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE"
34-if test -e @out@/nix-support/libc-cflags; then
5 export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE"
6fi
78-if test -e @out@/nix-support/gcc-cflags; then
9 export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/gcc-cflags) $NIX_CFLAGS_COMPILE"
10fi
1112-if test -e @out@/nix-support/gnat-cflags; then
13 export NIX_GNATFLAGS_COMPILE="$(cat @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE"
14fi
1516-if test -e @out@/nix-support/libc-ldflags; then
17- export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/libc-ldflags)"
18fi
1920-if test -e @out@/nix-support/gcc-ldflags; then
21- export NIX_LDFLAGS="$NIX_LDFLAGS $(cat @out@/nix-support/gcc-ldflags)"
22fi
2324-if test -e @out@/nix-support/libc-ldflags-before; then
25 export NIX_LDFLAGS_BEFORE="$(cat @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE"
26fi
27
···1# `-B@out@/bin' forces gcc to use ld-wrapper.sh when calling ld.
2export NIX_CFLAGS_COMPILE="-B@out@/bin/ $NIX_CFLAGS_COMPILE"
34+if [ -e @out@/nix-support/libc-cflags ]; then
5 export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/libc-cflags) $NIX_CFLAGS_COMPILE"
6fi
78+if [ -e @out@/nix-support/gcc-cflags ]; then
9 export NIX_CFLAGS_COMPILE="$(cat @out@/nix-support/gcc-cflags) $NIX_CFLAGS_COMPILE"
10fi
1112+if [ -e @out@/nix-support/gnat-cflags ]; then
13 export NIX_GNATFLAGS_COMPILE="$(cat @out@/nix-support/gnat-cflags) $NIX_GNATFLAGS_COMPILE"
14fi
1516+if [ -e @out@/nix-support/libc-ldflags ]; then
17+ export NIX_LDFLAGS+=" $(cat @out@/nix-support/libc-ldflags)"
18fi
1920+if [ -e @out@/nix-support/gcc-ldflags ]; then
21+ export NIX_LDFLAGS+=" $(cat @out@/nix-support/gcc-ldflags)"
22fi
2324+if [ -e @out@/nix-support/libc-ldflags-before ]; then
25 export NIX_LDFLAGS_BEFORE="$(cat @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE"
26fi
27
-214
pkgs/build-support/gcc-wrapper/builder.sh
···1-source $stdenv/setup
2-3-4-mkdir -p $out/bin
5-mkdir -p $out/nix-support
6-7-8-if test -z "$nativeLibc"; then
9- dynamicLinker="$libc/lib/$dynamicLinker"
10- echo $dynamicLinker > $out/nix-support/dynamic-linker
11-12- if test -e $libc/lib/32/ld-linux.so.2; then
13- echo $libc/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
14- fi
15-16- # The "-B$libc/lib/" flag is a quick hack to force gcc to link
17- # against the crt1.o from our own glibc, rather than the one in
18- # /usr/lib. (This is only an issue when using an `impure'
19- # compiler/linker, i.e., one that searches /usr/lib and so on.)
20- #
21- # Unfortunately, setting -B appears to override the default search
22- # path. Thus, the gcc-specific "../includes-fixed" directory is
23- # now longer searched and glibc's <limits.h> header fails to
24- # compile, because it uses "#include_next <limits.h>" to find the
25- # limits.h file in ../includes-fixed. To remedy the problem,
26- # another -idirafter is necessary to add that directory again.
27- echo "-B$libc/lib/ -idirafter $libc/include -idirafter $gcc/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
28-29- echo "-L$libc/lib" > $out/nix-support/libc-ldflags
30-31- # The dynamic linker is passed in `ldflagsBefore' to allow
32- # explicit overrides of the dynamic linker by callers to gcc/ld
33- # (the *last* value counts, so ours should come first).
34- echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before
35-fi
36-37-if test -n "$nativeTools"; then
38- gccPath="$nativePrefix/bin"
39- ldPath="$nativePrefix/bin"
40-else
41- if test -e "$gcc/lib64"; then
42- gccLDFlags="$gccLDFlags -L$gcc/lib64"
43- fi
44- gccLDFlags="$gccLDFlags -L$gcc/lib"
45- if [ -n "$langVhdl" ]; then
46- gccLDFlags="$gccLDFlags -L$zlib/lib"
47- fi
48- echo "$gccLDFlags" > $out/nix-support/gcc-ldflags
49-50- # GCC shows $gcc/lib in `gcc -print-search-dirs', but not
51- # $gcc/lib64 (even though it does actually search there...)..
52- # This confuses libtool. So add it to the compiler tool search
53- # path explicitly.
54- if test -e "$gcc/lib64"; then
55- gccCFlags="$gccCFlags -B$gcc/lib64"
56- fi
57-58- # Find the gcc libraries path (may work only without multilib)
59- if [ -n "$langAda" ]; then
60- basePath=`echo $gcc/lib/*/*/*`
61- gccCFlags="$gccCFlags -B$basePath -I$basePath/adainclude"
62-63- gnatCFlags="-aI$basePath/adainclude -aO$basePath/adalib"
64- echo "$gnatCFlags" > $out/nix-support/gnat-cflags
65- fi
66- echo "$gccCFlags" > $out/nix-support/gcc-cflags
67-68- gccPath="$gcc/bin"
69- # On Illumos/Solaris we might prefer native ld
70- if test -n "$nativePrefix"; then
71- ldPath="$nativePrefix/bin"
72- else
73- ldPath="$binutils/bin"
74- fi;
75-fi
76-77-78-doSubstitute() {
79- local src=$1
80- local dst=$2
81- local ld="$ldPath/ld"
82- if $ld -V 2>&1 |grep Solaris; then
83- # Use Solaris specific linker wrapper
84- ld="$out/bin/ld-solaris"
85- fi
86- # Can't use substitute() here, because replace may not have been
87- # built yet (in the bootstrap).
88- sed \
89- -e "s^@out@^$out^g" \
90- -e "s^@shell@^$shell^g" \
91- -e "s^@gcc@^$gcc^g" \
92- -e "s^@gccProg@^$gccProg^g" \
93- -e "s^@gnatProg@^$gnatProg^g" \
94- -e "s^@gnatlinkProg@^$gnatlinkProg^g" \
95- -e "s^@binutils@^$binutils^g" \
96- -e "s^@coreutils@^$coreutils^g" \
97- -e "s^@libc@^$libc^g" \
98- -e "s^@ld@^$ld^g" \
99- < "$src" > "$dst"
100-}
101-102-103-# Make wrapper scripts around gcc, g++, and gfortran. Also make symlinks
104-# cc, c++, and f77.
105-mkGccWrapper() {
106- local dst=$1
107- local src=$2
108-109- if ! test -f "$src"; then
110- echo "$src does not exist (skipping)"
111- return 1
112- fi
113-114- gccProg="$src"
115- doSubstitute "$gccWrapper" "$dst"
116- chmod +x "$dst"
117-}
118-119-mkGnatWrapper() {
120- local dst=$1
121- local src=$2
122-123- if ! test -f "$src"; then
124- echo "$src does not exist (skipping)"
125- return 1
126- fi
127-128- gnatProg="$src"
129- doSubstitute "$gnatWrapper" "$dst"
130- chmod +x "$dst"
131-}
132-133-mkGnatLinkWrapper() {
134- local dst=$1
135- local src=$2
136-137- if ! test -f "$src"; then
138- echo "$src does not exist (skipping)"
139- return 1
140- fi
141-142- gnatlinkProg="$src"
143- doSubstitute "$gnatlinkWrapper" "$dst"
144- chmod +x "$dst"
145-}
146-147-if mkGccWrapper $out/bin/gcc $gccPath/gcc
148-then
149- ln -sv gcc $out/bin/cc
150-fi
151-152-if mkGccWrapper $out/bin/g++ $gccPath/g++
153-then
154- ln -sv g++ $out/bin/c++
155-fi
156-157-mkGccWrapper $out/bin/cpp $gccPath/cpp || true
158-159-if mkGccWrapper $out/bin/gfortran $gccPath/gfortran
160-then
161- ln -sv gfortran $out/bin/g77
162- ln -sv gfortran $out/bin/f77
163-fi
164-165-mkGccWrapper $out/bin/gcj $gccPath/gcj || true
166-167-mkGccWrapper $out/bin/gccgo $gccPath/gccgo || true
168-169-mkGccWrapper $out/bin/gnatgcc $gccPath/gnatgcc || true
170-mkGnatWrapper $out/bin/gnatmake $gccPath/gnatmake || true
171-mkGnatWrapper $out/bin/gnatbind $gccPath/gnatbind || true
172-mkGnatLinkWrapper $out/bin/gnatlink $gccPath/gnatlink || true
173-174-if [ -f $gccPath/ghdl ]; then
175- ln -sf $gccPath/ghdl $out/bin/ghdl
176-fi
177-178-179-# Create a symlink to as (the assembler). This is useful when a
180-# gcc-wrapper is installed in a user environment, as it ensures that
181-# the right assembler is called.
182-ln -s $ldPath/as $out/bin/as
183-184-185-# Make a wrapper around the linker.
186-doSubstitute "$ldWrapper" "$out/bin/ld"
187-chmod +x "$out/bin/ld"
188-189-# Copy solaris ld wrapper if needed
190-if $ldPath/ld -V 2>&1 |grep Solaris; then
191- # Use Solaris specific linker wrapper
192- sed -e "s^@ld@^$ldPath/ld^g" < "$ldSolarisWrapper" > "$out/bin/ld-solaris"
193- chmod +x "$out/bin/ld-solaris"
194-fi
195-196-197-# Emit a setup hook. Also store the path to the original GCC and
198-# Glibc.
199-test -n "$gcc" && echo $gcc > $out/nix-support/orig-gcc
200-test -n "$libc" && echo $libc > $out/nix-support/orig-libc
201-202-doSubstitute "$addFlags" "$out/nix-support/add-flags.sh"
203-204-doSubstitute "$setupHook" "$out/nix-support/setup-hook"
205-206-cp -p $utils $out/nix-support/utils.sh
207-208-209-# Propagate the wrapped gcc so that if you install the wrapper, you get
210-# tools like gcov, the manpages, etc. as well (including for binutils
211-# and Glibc).
212-if test -z "$nativeTools"; then
213- echo $gcc $binutils $libc > $out/nix-support/propagated-user-env-packages
214-fi
···1-# The Nix `gcc' stdenv.mkDerivation is not directly usable, since it doesn't
2-# know where the C library and standard header files are. Therefore
3-# the compiler produced by that package cannot be installed directly
4-# in a user environment and used from the command line. This
5-# stdenv.mkDerivation provides a wrapper that sets up the right environment
6-# variables so that the compiler and the linker just "work".
78{ name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? ""
9-, gcc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? ""
10-, zlib ? null
11}:
120013assert nativeTools -> nativePrefix != "";
14assert !nativeTools -> gcc != null && binutils != null && coreutils != null;
15assert !nativeLibc -> libc != null;
1617-# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper
18-assert (gcc != null && gcc ? langVhdl && gcc.langVhdl) -> zlib != null;
1920let
2122 gccVersion = (builtins.parseDrvName gcc.name).version;
23 gccName = (builtins.parseDrvName gcc.name).name;
2425- langGo = if nativeTools then false else gcc ? langGo && gcc.langGo;
26in
2728stdenv.mkDerivation {
···30 (if name != "" then name else gccName + "-wrapper") +
31 (if gcc != null && gccVersion != "" then "-" + gccVersion else "");
3233- builder = ./builder.sh;
34- setupHook = ./setup-hook.sh;
35- gccWrapper = ./gcc-wrapper.sh;
36- gnatWrapper = ./gnat-wrapper.sh;
37- gnatlinkWrapper = ./gnatlink-wrapper.sh;
38- ldWrapper = ./ld-wrapper.sh;
39- ldSolarisWrapper = ./ld-solaris-wrapper.sh;
40- utils = ./utils.sh;
41- addFlags = ./add-flags;
4243- inherit nativeTools nativeLibc nativePrefix gcc;
44 libc = if nativeLibc then null else libc;
45 binutils = if nativeTools then null else binutils;
46- # The wrapper scripts use 'cat', so we may need coreutils
47 coreutils = if nativeTools then null else coreutils;
4849- langC = if nativeTools then true else gcc.langC;
50- langCC = if nativeTools then true else gcc.langCC;
51- langFortran = if nativeTools then false else gcc ? langFortran;
52- langAda = if nativeTools then false else gcc ? langAda && gcc.langAda;
53- langVhdl = if nativeTools then false else gcc ? langVhdl && gcc.langVhdl;
54- zlib = if gcc != null && gcc ? langVhdl then zlib else null;
55- shell = if shell == "" then stdenv.shell else
56- if builtins.isAttrs shell then (shell + shell.shellPath)
57- else shell;
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005859 crossAttrs = {
60 shell = shell.crossDrv + shell.crossDrv.shellPath;
···73 abort "don't know the name of the dynamic linker for this platform");
74 };
7576- preferLocalBuild = true;
77-78 meta =
79 let gcc_ = if gcc != null then gcc else {}; in
80 (if gcc_ ? meta then removeAttrs gcc.meta ["priority"] else {}) //
···82 stdenv.lib.attrByPath ["meta" "description"] "System C compiler" gcc_
83 + " (wrapper script)";
84 };
85-86- # The dynamic linker has different names on different Linux platforms.
87- dynamicLinker =
88- if !nativeLibc then
89- (if stdenv.system == "i686-linux" then "ld-linux.so.2" else
90- if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
91- # ARM with a wildcard, which can be "" or "-armhf".
92- if stdenv.isArm then "ld-linux*.so.3" else
93- if stdenv.system == "powerpc-linux" then "ld.so.1" else
94- if stdenv.system == "mips64el-linux" then "ld.so.1" else
95- abort "don't know the name of the dynamic linker for this platform")
96- else "";
97}
···1+# The Nixpkgs GCC is not directly usable, since it doesn't know where
2+# the C library and standard header files are. Therefore the compiler
3+# produced by that package cannot be installed directly in a user
4+# environment and used from the command line. So we use a wrapper
5+# script that sets up the right environment variables so that the
6+# compiler and the linker just "work".
78{ name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? ""
9+, gcc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? stdenv.shell
10+, zlib ? null, extraPackages ? []
11}:
1213+with stdenv.lib;
14+15assert nativeTools -> nativePrefix != "";
16assert !nativeTools -> gcc != null && binutils != null && coreutils != null;
17assert !nativeLibc -> libc != null;
1819+# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper.
20+assert gcc.langVhdl or false -> zlib != null;
2122let
2324 gccVersion = (builtins.parseDrvName gcc.name).version;
25 gccName = (builtins.parseDrvName gcc.name).name;
26027in
2829stdenv.mkDerivation {
···31 (if name != "" then name else gccName + "-wrapper") +
32 (if gcc != null && gccVersion != "" then "-" + gccVersion else "");
3334+ preferLocalBuild = true;
000000003536+ inherit gcc shell;
37 libc = if nativeLibc then null else libc;
38 binutils = if nativeTools then null else binutils;
39+ # The wrapper scripts use 'cat', so we may need coreutils.
40 coreutils = if nativeTools then null else coreutils;
4142+ passthru = { inherit nativeTools nativeLibc nativePrefix; };
43+44+ buildCommand =
45+ ''
46+ mkdir -p $out/bin $out/nix-support
47+48+ wrap() {
49+ local dst="$1"
50+ local wrapper="$2"
51+ export prog="$3"
52+ substituteAll "$wrapper" "$out/bin/$dst"
53+ chmod +x "$out/bin/$dst"
54+ }
55+ ''
56+57+ + optionalString (!nativeLibc) ''
58+ dynamicLinker="$libc/lib/$dynamicLinker"
59+ echo $dynamicLinker > $out/nix-support/dynamic-linker
60+61+ if [ -e $libc/lib/32/ld-linux.so.2 ]; then
62+ echo $libc/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
63+ fi
64+65+ # The "-B$libc/lib/" flag is a quick hack to force gcc to link
66+ # against the crt1.o from our own glibc, rather than the one in
67+ # /usr/lib. (This is only an issue when using an `impure'
68+ # compiler/linker, i.e., one that searches /usr/lib and so on.)
69+ #
70+ # Unfortunately, setting -B appears to override the default search
71+ # path. Thus, the gcc-specific "../includes-fixed" directory is
72+ # now longer searched and glibc's <limits.h> header fails to
73+ # compile, because it uses "#include_next <limits.h>" to find the
74+ # limits.h file in ../includes-fixed. To remedy the problem,
75+ # another -idirafter is necessary to add that directory again.
76+ echo "-B$libc/lib/ -idirafter $libc/include -idirafter $gcc/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
77+78+ echo "-L$libc/lib" > $out/nix-support/libc-ldflags
79+80+ # The dynamic linker is passed in `ldflagsBefore' to allow
81+ # explicit overrides of the dynamic linker by callers to gcc/ld
82+ # (the *last* value counts, so ours should come first).
83+ echo "-dynamic-linker" $dynamicLinker > $out/nix-support/libc-ldflags-before
84+85+ echo $libc > $out/nix-support/orig-libc
86+ ''
87+88+ + (if nativeTools then ''
89+ gccPath="${nativePrefix}/bin"
90+ ldPath="${nativePrefix}/bin"
91+ '' else ''
92+ echo $gcc > $out/nix-support/orig-gcc
93+94+ # GCC shows $gcc/lib in `gcc -print-search-dirs', but not
95+ # $gcc/lib64 (even though it does actually search there...)..
96+ # This confuses libtool. So add it to the compiler tool search
97+ # path explicitly.
98+ if [ -e "$gcc/lib64" -a ! -L "$gcc/lib64" ]; then
99+ gccLDFlags+=" -L$gcc/lib64"
100+ gccCFlags+=" -B$gcc/lib64"
101+ fi
102+ gccLDFlags+=" -L$gcc/lib"
103+104+ ${optionalString gcc.langVhdl or false ''
105+ gccLDFlags+=" -L${zlib}/lib"
106+ ''}
107+108+ # Find the gcc libraries path (may work only without multilib).
109+ ${optionalString gcc.langAda or false ''
110+ basePath=`echo $gcc/lib/*/*/*`
111+ gccCFlags+=" -B$basePath -I$basePath/adainclude"
112+ gnatCFlags="-aI$basePath/adainclude -aO$basePath/adalib"
113+ echo "$gnatCFlags" > $out/nix-support/gnat-cflags
114+ ''}
115+116+ echo "$gccLDFlags" > $out/nix-support/gcc-ldflags
117+ echo "$gccCFlags" > $out/nix-support/gcc-cflags
118+119+ gccPath="$gcc/bin"
120+ ldPath="$binutils/bin"
121+122+ # Propagate the wrapped gcc so that if you install the wrapper,
123+ # you get tools like gcov, the manpages, etc. as well (including
124+ # for binutils and Glibc).
125+ echo $gcc $binutils $libc > $out/nix-support/propagated-user-env-packages
126+127+ echo ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs
128+ ''
129+130+ + optionalString (stdenv.isSunOS && nativePrefix != "") ''
131+ # Solaris needs an additional ld wrapper.
132+ ldPath="${nativePrefix}/bin"
133+ ld="$out/bin/ld-solaris"
134+ wrap ld-solaris ${./ld-solaris-wrapper.sh}
135+ '')
136+137+ + ''
138+ # Create a symlink to as (the assembler). This is useful when a
139+ # gcc-wrapper is installed in a user environment, as it ensures that
140+ # the right assembler is called.
141+ if [ -e $ldPath/as ]; then
142+ ln -s $ldPath/as $out/bin/as
143+ fi
144+145+ wrap ld ${./ld-wrapper.sh} ''${ld:-$ldPath/ld}
146+147+ if [ -e $binutils/bin/ld.gold ]; then
148+ wrap ld.gold ${./ld-wrapper.sh} $binutils/bin/ld.gold
149+ fi
150+151+ if [ -e $binutils/bin/ld.bfd ]; then
152+ wrap ld.bfd ${./ld-wrapper.sh} $binutils/bin/ld.bfd
153+ fi
154+155+ if [ -e $gccPath/gcc ]; then
156+ wrap gcc ${./gcc-wrapper.sh} $gccPath/gcc
157+ ln -s gcc $out/bin/cc
158+ elif [ -e $gccPath/clang ]; then
159+ wrap clang ${./gcc-wrapper.sh} $gccPath/clang
160+ ln -s clang $out/bin/cc
161+ fi
162+163+ if [ -e $gccPath/g++ ]; then
164+ wrap g++ ${./gcc-wrapper.sh} $gccPath/g++
165+ ln -s g++ $out/bin/c++
166+ elif [ -e $gccPath/clang++ ]; then
167+ wrap clang++ ${./gcc-wrapper.sh} $gccPath/clang++
168+ ln -s clang++ $out/bin/c++
169+ fi
170+171+ if [ -e $gccPath/cpp ]; then
172+ wrap cpp ${./gcc-wrapper.sh} $gccPath/cpp
173+ fi
174+ ''
175+176+ + optionalString gcc.langFortran or false ''
177+ wrap gfortran ${./gcc-wrapper.sh} $gccPath/gfortran
178+ ln -sv gfortran $out/bin/g77
179+ ln -sv gfortran $out/bin/f77
180+ ''
181+182+ + optionalString gcc.langJava or false ''
183+ wrap gcj ${./gcc-wrapper.sh} $gccPath/gcj
184+ ''
185+186+ + optionalString gcc.langGo or false ''
187+ wrap gccgo ${./gcc-wrapper.sh} $gccPath/gccgo
188+ ''
189+190+ + optionalString gcc.langAda or false ''
191+ wrap gnatgcc ${./gcc-wrapper.sh} $gccPath/gnatgcc
192+ wrap gnatmake ${./gnat-wrapper.sh} $gccPath/gnatmake
193+ wrap gnatbind ${./gnat-wrapper.sh} $gccPath/gnatbind
194+ wrap gnatlink ${./gnatlink-wrapper.sh} $gccPath/gnatlink
195+ ''
196+197+ + optionalString gcc.langVhdl or false ''
198+ ln -s $gccPath/ghdl $out/bin/ghdl
199+ ''
200+201+ + ''
202+ substituteAll ${./setup-hook.sh} $out/nix-support/setup-hook
203+ substituteAll ${./add-flags} $out/nix-support/add-flags.sh
204+ cp -p ${./utils.sh} $out/nix-support/utils.sh
205+206+ if [ -e $out/bin/clang ]; then
207+ echo 'export CC; : ''${CC:=clang}' >> $out/nix-support/setup-hook
208+ fi
209+210+ if [ -e $out/bin/clang++ ]; then
211+ echo 'export CXX; : ''${CXX:=clang++}' >> $out/nix-support/setup-hook
212+ fi
213+ '';
214+215+ # The dynamic linker has different names on different Linux platforms.
216+ dynamicLinker =
217+ if !nativeLibc then
218+ (if stdenv.system == "i686-linux" then "ld-linux.so.2" else
219+ if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
220+ # ARM with a wildcard, which can be "" or "-armhf".
221+ if stdenv.isArm then "ld-linux*.so.3" else
222+ if stdenv.system == "powerpc-linux" then "ld.so.1" else
223+ if stdenv.system == "mips64el-linux" then "ld.so.1" else
224+ abort "Don't know the name of the dynamic linker for this platform.")
225+ else "";
226227 crossAttrs = {
228 shell = shell.crossDrv + shell.crossDrv.shellPath;
···241 abort "don't know the name of the dynamic linker for this platform");
242 };
24300244 meta =
245 let gcc_ = if gcc != null then gcc else {}; in
246 (if gcc_ ? meta then removeAttrs gcc.meta ["priority"] else {}) //
···248 stdenv.lib.attrByPath ["meta" "description"] "System C compiler" gcc_
249 + " (wrapper script)";
250 };
000000000000251}
+35-45
pkgs/build-support/gcc-wrapper/gcc-wrapper.sh
···1#! @shell@ -e
23-if test -n "$NIX_GCC_WRAPPER_START_HOOK"; then
4 source "$NIX_GCC_WRAPPER_START_HOOK"
5fi
67-if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then
8 source @out@/nix-support/add-flags.sh
9fi
10···18nonFlagArgs=0
1920for i in "$@"; do
21- if test "$i" = "-c"; then
22 dontLink=1
23- elif test "$i" = "-S"; then
24 dontLink=1
25- elif test "$i" = "-E"; then
26 dontLink=1
27- elif test "$i" = "-E"; then
28 dontLink=1
29- elif test "$i" = "-M"; then
30 dontLink=1
31- elif test "$i" = "-MM"; then
32 dontLink=1
33- elif test "$i" = "-x"; then
34 # At least for the cases c-header or c++-header we should set dontLink.
35 # I expect no one use -x other than making precompiled headers.
36 dontLink=1
37- elif test "${i:0:1}" != "-"; then
38 nonFlagArgs=1
39- elif test "$i" = "-m32"; then
40- if test -e @out@/nix-support/dynamic-linker-m32; then
41 NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
42 fi
43 fi
···48# "-c" flag). So if no non-flag arguments are given, don't pass any
49# linker flags. This catches cases like "gcc" (should just print
50# "gcc: no input files") and "gcc -v" (should print the version).
51-if test "$nonFlagArgs" = "0"; then
52 dontLink=1
53fi
545556# Optionally filter out paths not refering to the store.
57params=("$@")
58-if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then
59 rest=()
60 n=0
61- while test $n -lt ${#params[*]}; do
62 p=${params[n]}
63 p2=${params[$((n+1))]}
64- if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
65 skip $p
66- elif test "$p" = "-L" && badPath "$p2"; then
67 n=$((n + 1)); skip $p2
68- elif test "${p:0:3}" = "-I/" && badPath "${p:2}"; then
69 skip $p
70- elif test "$p" = "-I" && badPath "$p2"; then
71 n=$((n + 1)); skip $p2
72- elif test "$p" = "-isystem" && badPath "$p2"; then
73 n=$((n + 1)); skip $p2
74 else
75 rest=("${rest[@]}" "$p")
···8687# When enforcing purity, pretend gcc can't find the current date and
88# time
89-if test "$NIX_ENFORCE_PURITY" = "1"; then
90 extraAfter+=('-D__DATE__="Jan 01 1970"'
91 '-D__TIME__="00:00:01"'
92 -Wno-builtin-macro-redefined)
93fi
949596-if test "$dontLink" != "1"; then
9798 # Add the flags that should only be passed to the compiler when
99 # linking.
···105 extraBefore=(${extraBefore[@]} "-Wl,$i")
106 done
107 for i in $NIX_LDFLAGS; do
108- if test "${i:0:3}" = "-L/"; then
109- extraAfter+=("$i")
110- else
111- extraAfter+=("-Wl,$i")
112- fi
113 done
114 export NIX_LDFLAGS_SET=1
115fi
···118# add anything. This is to prevent `gcc -v' (which normally prints
119# out the version number and returns exit code 0) from printing out
120# `No input files specified' and returning exit code 1.
121-if test "$*" = "-v"; then
122 extraAfter=()
123 extraBefore=()
124-fi
125126# Optionally print debug info.
127-if test "$NIX_DEBUG" = "1"; then
128- echo "original flags to @gccProg@:" >&2
129 for i in "${params[@]}"; do
130 echo " $i" >&2
131 done
132- echo "extraBefore flags to @gccProg@:" >&2
133 for i in ${extraBefore[@]}; do
134 echo " $i" >&2
135 done
136- echo "extraAfter flags to @gccProg@:" >&2
137 for i in ${extraAfter[@]}; do
138 echo " $i" >&2
139 done
140fi
141142-if test -n "$NIX_GCC_WRAPPER_EXEC_HOOK"; then
143 source "$NIX_GCC_WRAPPER_EXEC_HOOK"
144fi
145146-147-# Call the real `gcc'. Filter out warnings from stderr about unused
148-# `-B' flags, since they confuse some programs. Deep bash magic to
149-# apply grep to stderr (by swapping stdin/stderr twice).
150-if test -z "$NIX_GCC_NEEDS_GREP"; then
151- @gccProg@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}"
152-else
153- (@gccProg@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}" 3>&2 2>&1 1>&3- \
154- | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
155- exit $?
156-fi
···1#! @shell@ -e
23+if [ -n "$NIX_GCC_WRAPPER_START_HOOK" ]; then
4 source "$NIX_GCC_WRAPPER_START_HOOK"
5fi
67+if [ -z "$NIX_GCC_WRAPPER_FLAGS_SET" ]; then
8 source @out@/nix-support/add-flags.sh
9fi
10···18nonFlagArgs=0
1920for i in "$@"; do
21+ if [ "$i" = -c ]; then
22 dontLink=1
23+ elif [ "$i" = -S ]; then
24 dontLink=1
25+ elif [ "$i" = -E ]; then
26 dontLink=1
27+ elif [ "$i" = -E ]; then
28 dontLink=1
29+ elif [ "$i" = -M ]; then
30 dontLink=1
31+ elif [ "$i" = -MM ]; then
32 dontLink=1
33+ elif [ "$i" = -x ]; then
34 # At least for the cases c-header or c++-header we should set dontLink.
35 # I expect no one use -x other than making precompiled headers.
36 dontLink=1
37+ elif [ "${i:0:1}" != - ]; then
38 nonFlagArgs=1
39+ elif [ "$i" = -m32 ]; then
40+ if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
41 NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
42 fi
43 fi
···48# "-c" flag). So if no non-flag arguments are given, don't pass any
49# linker flags. This catches cases like "gcc" (should just print
50# "gcc: no input files") and "gcc -v" (should print the version).
51+if [ "$nonFlagArgs" = 0 ]; then
52 dontLink=1
53fi
545556# Optionally filter out paths not refering to the store.
57params=("$@")
58+if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
59 rest=()
60 n=0
61+ while [ $n -lt ${#params[*]} ]; do
62 p=${params[n]}
63 p2=${params[$((n+1))]}
64+ if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
65 skip $p
66+ elif [ "$p" = -L ] && badPath "$p2"; then
67 n=$((n + 1)); skip $p2
68+ elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
69 skip $p
70+ elif [ "$p" = -I ] && badPath "$p2"; then
71 n=$((n + 1)); skip $p2
72+ elif [ "$p" = -isystem ] && badPath "$p2"; then
73 n=$((n + 1)); skip $p2
74 else
75 rest=("${rest[@]}" "$p")
···8687# When enforcing purity, pretend gcc can't find the current date and
88# time
89+if [ "$NIX_ENFORCE_PURITY" = 1 ]; then
90 extraAfter+=('-D__DATE__="Jan 01 1970"'
91 '-D__TIME__="00:00:01"'
92 -Wno-builtin-macro-redefined)
93fi
949596+if [ "$dontLink" != 1 ]; then
9798 # Add the flags that should only be passed to the compiler when
99 # linking.
···105 extraBefore=(${extraBefore[@]} "-Wl,$i")
106 done
107 for i in $NIX_LDFLAGS; do
108+ if [ "${i:0:3}" = -L/ ]; then
109+ extraAfter+=("$i")
110+ else
111+ extraAfter+=("-Wl,$i")
112+ fi
113 done
114 export NIX_LDFLAGS_SET=1
115fi
···118# add anything. This is to prevent `gcc -v' (which normally prints
119# out the version number and returns exit code 0) from printing out
120# `No input files specified' and returning exit code 1.
121+if [ "$*" = -v ]; then
122 extraAfter=()
123 extraBefore=()
124+fi
125126# Optionally print debug info.
127+if [ -n "$NIX_DEBUG" ]; then
128+ echo "original flags to @prog@:" >&2
129 for i in "${params[@]}"; do
130 echo " $i" >&2
131 done
132+ echo "extraBefore flags to @prog@:" >&2
133 for i in ${extraBefore[@]}; do
134 echo " $i" >&2
135 done
136+ echo "extraAfter flags to @prog@:" >&2
137 for i in ${extraAfter[@]}; do
138 echo " $i" >&2
139 done
140fi
141142+if [ -n "$NIX_GCC_WRAPPER_EXEC_HOOK" ]; then
143 source "$NIX_GCC_WRAPPER_EXEC_HOOK"
144fi
145146+exec @prog@ ${extraBefore[@]} "${params[@]}" "${extraAfter[@]}"
0000000000
+20-30
pkgs/build-support/gcc-wrapper/gnat-wrapper.sh
···1#! @shell@ -e
23-if test -n "$NIX_GNAT_WRAPPER_START_HOOK"; then
4 source "$NIX_GNAT_WRAPPER_START_HOOK"
5fi
67-if test -z "$NIX_GNAT_WRAPPER_FLAGS_SET"; then
8 source @out@/nix-support/add-flags.sh
9fi
10···18nonFlagArgs=0
1920for i in "$@"; do
21- if test "$i" = "-c"; then
22 dontLink=1
23- elif test "$i" = "-M"; then
24 dontLink=1
25- elif test "${i:0:1}" != "-"; then
26 nonFlagArgs=1
27- elif test "$i" = "-m32"; then
28- if test -e @out@/nix-support/dynamic-linker-m32; then
29 NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
30 fi
31 fi
···36# "-c" flag). So if no non-flag arguments are given, don't pass any
37# linker flags. This catches cases like "gcc" (should just print
38# "gcc: no input files") and "gcc -v" (should print the version).
39-if test "$nonFlagArgs" = "0"; then
40 dontLink=1
41fi
424344# Optionally filter out paths not refering to the store.
45params=("$@")
46-if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE"; then
47 rest=()
48 n=0
49- while test $n -lt ${#params[*]}; do
50 p=${params[n]}
51 p2=${params[$((n+1))]}
52- if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
53 skip $p
54- elif test "${p:0:3}" = "-I/" && badPath "${p:2}"; then
55 skip $p
56- elif test "${p:0:4}" = "-aI/" && badPath "${p:3}"; then
57 skip $p
58- elif test "${p:0:4}" = "-aO/" && badPath "${p:3}"; then
59 skip $p
60 else
61 rest=("${rest[@]}" "$p")
···81#done
8283# Optionally print debug info.
84-if test "$NIX_DEBUG" = "1"; then
85- echo "original flags to @gnatProg@:" >&2
86 for i in "${params[@]}"; do
87 echo " $i" >&2
88 done
89- echo "extraBefore flags to @gnatProg@:" >&2
90 for i in ${extraBefore[@]}; do
91 echo " $i" >&2
92 done
93- echo "extraAfter flags to @gnatProg@:" >&2
94 for i in ${extraAfter[@]}; do
95 echo " $i" >&2
96 done
97fi
9899-if test -n "$NIX_GNAT_WRAPPER_EXEC_HOOK"; then
100 source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
101fi
102103-104-# Call the real `gcc'. Filter out warnings from stderr about unused
105-# `-B' flags, since they confuse some programs. Deep bash magic to
106-# apply grep to stderr (by swapping stdin/stderr twice).
107-if test -z "$NIX_GNAT_NEEDS_GREP"; then
108- @gnatProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
109-else
110- (@gnatProg@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
111- | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
112- exit $?
113-fi
···1#! @shell@ -e
23+if [ -n "$NIX_GNAT_WRAPPER_START_HOOK" ]; then
4 source "$NIX_GNAT_WRAPPER_START_HOOK"
5fi
67+if [ -z "$NIX_GNAT_WRAPPER_FLAGS_SET" ]; then
8 source @out@/nix-support/add-flags.sh
9fi
10···18nonFlagArgs=0
1920for i in "$@"; do
21+ if [ "$i" = -c ]; then
22 dontLink=1
23+ elif [ "$i" = -M ]; then
24 dontLink=1
25+ elif [ "${i:0:1}" != - ]; then
26 nonFlagArgs=1
27+ elif [ "$i" = -m32 ]; then
28+ if [ -e @out@/nix-support/dynamic-linker-m32 ]; then
29 NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
30 fi
31 fi
···36# "-c" flag). So if no non-flag arguments are given, don't pass any
37# linker flags. This catches cases like "gcc" (should just print
38# "gcc: no input files") and "gcc -v" (should print the version).
39+if [ "$nonFlagArgs" = 0 ]; then
40 dontLink=1
41fi
424344# Optionally filter out paths not refering to the store.
45params=("$@")
46+if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
47 rest=()
48 n=0
49+ while [ $n -lt ${#params[*]} ]; do
50 p=${params[n]}
51 p2=${params[$((n+1))]}
52+ if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
53 skip $p
54+ elif [ "${p:0:3}" = -I/ ] && badPath "${p:2}"; then
55 skip $p
56+ elif [ "${p:0:4}" = -aI/ ] && badPath "${p:3}"; then
57 skip $p
58+ elif [ "${p:0:4}" = -aO/ ] && badPath "${p:3}"; then
59 skip $p
60 else
61 rest=("${rest[@]}" "$p")
···81#done
8283# Optionally print debug info.
84+if [ -n "$NIX_DEBUG" ]; then
85+ echo "original flags to @prog@:" >&2
86 for i in "${params[@]}"; do
87 echo " $i" >&2
88 done
89+ echo "extraBefore flags to @prog@:" >&2
90 for i in ${extraBefore[@]}; do
91 echo " $i" >&2
92 done
93+ echo "extraAfter flags to @prog@:" >&2
94 for i in ${extraAfter[@]}; do
95 echo " $i" >&2
96 done
97fi
9899+if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
100 source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
101fi
102103+exec @prog@ ${extraBefore[@]} "${params[@]}" ${extraAfter[@]}
0000000000
···11#done
1213# Optionally print debug info.
14-if test "$NIX_DEBUG" = "1"; then
15- echo "original flags to @gnatlinkProg@:" >&2
16 for i in "$@"; do
17 echo " $i" >&2
18 done
19- echo "extraBefore flags to @gnatlinkProg@:" >&2
20 for i in ${extraBefore[@]}; do
21 echo " $i" >&2
22 done
23- echo "extraAfter flags to @gnatlinkProg@:" >&2
24 for i in ${extraAfter[@]}; do
25 echo " $i" >&2
26 done
27fi
2829-if test -n "$NIX_GNAT_WRAPPER_EXEC_HOOK"; then
30 source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
31fi
3233-34-# Call the real `gcc'. Filter out warnings from stderr about unused
35-# `-B' flags, since they confuse some programs. Deep bash magic to
36-# apply grep to stderr (by swapping stdin/stderr twice).
37-if test -z "$NIX_GNAT_NEEDS_GREP"; then
38- @gnatlinkProg@ ${extraBefore[@]} "$@" ${extraAfter[@]}
39-else
40- (@gnatlinkProg@ ${extraBefore[@]} "$@" ${extraAfter[@]} 3>&2 2>&1 1>&3- \
41- | (grep -v 'file path prefix' || true); exit ${PIPESTATUS[0]}) 3>&2 2>&1 1>&3-
42- exit $?
43-fi
···11#done
1213# Optionally print debug info.
14+if [ -n "$NIX_DEBUG" ]; then
15+ echo "original flags to @prog@:" >&2
16 for i in "$@"; do
17 echo " $i" >&2
18 done
19+ echo "extraBefore flags to @prog@:" >&2
20 for i in ${extraBefore[@]}; do
21 echo " $i" >&2
22 done
23+ echo "extraAfter flags to @prog@:" >&2
24 for i in ${extraAfter[@]}; do
25 echo " $i" >&2
26 done
27fi
2829+if [ -n "$NIX_GNAT_WRAPPER_EXEC_HOOK" ]; then
30 source "$NIX_GNAT_WRAPPER_EXEC_HOOK"
31fi
3233+exec @prog@ ${extraBefore[@]} "$@" ${extraAfter[@]}
0000000000
···6# I've also tried adding -z direct and -z lazyload, but it gave too many problems with C++ exceptions :'(
7# Also made sure libgcc would not be lazy-loaded, as suggested here: https://www.illumos.org/issues/2534#note-3
8# but still no success.
9-cmd="@ld@ -z ignore"
1011args=("$@");
12
···6# I've also tried adding -z direct and -z lazyload, but it gave too many problems with C++ exceptions :'(
7# Also made sure libgcc would not be lazy-loaded, as suggested here: https://www.illumos.org/issues/2534#note-3
8# but still no success.
9+cmd="@prog@ -z ignore"
1011args=("$@");
12
+31-31
pkgs/build-support/gcc-wrapper/ld-wrapper.sh
···1#! @shell@ -e
23-if test -n "$NIX_LD_WRAPPER_START_HOOK"; then
4 source "$NIX_LD_WRAPPER_START_HOOK"
5fi
67-if test -z "$NIX_GCC_WRAPPER_FLAGS_SET"; then
8 source @out@/nix-support/add-flags.sh
9fi
10···1314# Optionally filter out paths not refering to the store.
15params=("$@")
16-if test "$NIX_ENFORCE_PURITY" = "1" -a -n "$NIX_STORE" \
17- -a \( -z "$NIX_IGNORE_LD_THROUGH_GCC" -o -z "$NIX_LDFLAGS_SET" \); then
18 rest=()
19 n=0
20- while test $n -lt ${#params[*]}; do
21 p=${params[n]}
22 p2=${params[$((n+1))]}
23- if test "${p:0:3}" = "-L/" && badPath "${p:2}"; then
24 skip $p
25- elif test "$p" = "-L" && badPath "$p2"; then
26 n=$((n + 1)); skip $p2
27- elif test "$p" = "-rpath" && badPath "$p2"; then
28 n=$((n + 1)); skip $p2
29- elif test "$p" = "-dynamic-linker" && badPath "$p2"; then
30 n=$((n + 1)); skip $p2
31- elif test "${p:0:1}" = "/" && badPath "$p"; then
32 # We cannot skip this; barf.
33 echo "impure path \`$p' used in link" >&2
34 exit 1
35- elif test "${p:0:9}" = "--sysroot"; then
36 # Our ld is not built with sysroot support (Can we fix that?)
37 :
38 else
···47extra=()
48extraBefore=()
4950-if test -z "$NIX_LDFLAGS_SET"; then
51 extra+=($NIX_LDFLAGS)
52 extraBefore+=($NIX_LDFLAGS_BEFORE)
53fi
···565758# Add all used dynamic libraries to the rpath.
59-if test "$NIX_DONT_SET_RPATH" != "1"; then
6061 libPath=""
62 addToLibPath() {
63 local path="$1"
64- if test "${path:0:1}" != "/"; then return 0; fi
65 case "$path" in
66 *..*|*./*|*/.*|*//*)
67 local path2
···75 esac
76 libPath="$libPath $path "
77 }
78-79 addToRPath() {
80 # If the path is not in the store, don't add it to the rpath.
81 # This typically happens for libraries in /tmp that are later
82 # copied to $out/lib. If not, we're screwed.
83- if test "${1:0:${#NIX_STORE}}" != "$NIX_STORE"; then return 0; fi
84 case $rpath in
85 *\ $1\ *) return 0 ;;
86 esac
···97 # First, find all -L... switches.
98 allParams=("${params[@]}" ${extra[@]})
99 n=0
100- while test $n -lt ${#allParams[*]}; do
101 p=${allParams[n]}
102 p2=${allParams[$((n+1))]}
103- if test "${p:0:3}" = "-L/"; then
104 addToLibPath ${p:2}
105- elif test "$p" = "-L"; then
106 addToLibPath ${p2}
107 n=$((n + 1))
108- elif test "$p" = "-l"; then
109 addToLibs ${p2}
110 n=$((n + 1))
111- elif test "${p:0:2}" = "-l"; then
112 addToLibs ${p:2}
113- elif test "$p" = "-dynamic-linker"; then
114- # Ignore the dynamic linker argument, or it
115 # will get into the next 'elif'. We don't want
116 # the dynamic linker path rpath to go always first.
117 n=$((n + 1))
···129 # so, add the directory to the rpath.
130 # It's important to add the rpath in the order of -L..., so
131 # the link time chosen objects will be those of runtime linking.
132-133 for i in $libPath; do
134 for j in $libs; do
135- if test -f "$i/lib$j.so"; then
136 addToRPath $i
137 break
138 fi
139 done
140 done
141-142143 # Finally, add `-rpath' switches.
144 for i in $rpath; do
···148149150# Optionally print debug info.
151-if test "$NIX_DEBUG" = "1"; then
152- echo "original flags to @ld@:" >&2
153 for i in "${params[@]}"; do
154 echo " $i" >&2
155 done
156- echo "extra flags to @ld@:" >&2
157 for i in ${extra[@]}; do
158 echo " $i" >&2
159 done
160fi
161162-if test -n "$NIX_LD_WRAPPER_EXEC_HOOK"; then
163 source "$NIX_LD_WRAPPER_EXEC_HOOK"
164fi
165166-exec @ld@ ${extraBefore[@]} "${params[@]}" ${extra[@]}
···1#! @shell@ -e
23+if [ -n "$NIX_LD_WRAPPER_START_HOOK" ]; then
4 source "$NIX_LD_WRAPPER_START_HOOK"
5fi
67+if [ -z "$NIX_GCC_WRAPPER_FLAGS_SET" ]; then
8 source @out@/nix-support/add-flags.sh
9fi
10···1314# Optionally filter out paths not refering to the store.
15params=("$@")
16+if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" \
17+ -a \( -z "$NIX_IGNORE_LD_THROUGH_GCC" -o -z "$NIX_LDFLAGS_SET" \) ]; then
18 rest=()
19 n=0
20+ while [ $n -lt ${#params[*]} ]; do
21 p=${params[n]}
22 p2=${params[$((n+1))]}
23+ if [ "${p:0:3}" = -L/ ] && badPath "${p:2}"; then
24 skip $p
25+ elif [ "$p" = -L ] && badPath "$p2"; then
26 n=$((n + 1)); skip $p2
27+ elif [ "$p" = -rpath ] && badPath "$p2"; then
28 n=$((n + 1)); skip $p2
29+ elif [ "$p" = -dynamic-linker ] && badPath "$p2"; then
30 n=$((n + 1)); skip $p2
31+ elif [ "${p:0:1}" = / ] && badPath "$p"; then
32 # We cannot skip this; barf.
33 echo "impure path \`$p' used in link" >&2
34 exit 1
35+ elif [ "${p:0:9}" = --sysroot ]; then
36 # Our ld is not built with sysroot support (Can we fix that?)
37 :
38 else
···47extra=()
48extraBefore=()
4950+if [ -z "$NIX_LDFLAGS_SET" ]; then
51 extra+=($NIX_LDFLAGS)
52 extraBefore+=($NIX_LDFLAGS_BEFORE)
53fi
···565758# Add all used dynamic libraries to the rpath.
59+if [ "$NIX_DONT_SET_RPATH" != 1 ]; then
6061 libPath=""
62 addToLibPath() {
63 local path="$1"
64+ if [ "${path:0:1}" != / ]; then return 0; fi
65 case "$path" in
66 *..*|*./*|*/.*|*//*)
67 local path2
···75 esac
76 libPath="$libPath $path "
77 }
78+79 addToRPath() {
80 # If the path is not in the store, don't add it to the rpath.
81 # This typically happens for libraries in /tmp that are later
82 # copied to $out/lib. If not, we're screwed.
83+ if [ "${1:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then return 0; fi
84 case $rpath in
85 *\ $1\ *) return 0 ;;
86 esac
···97 # First, find all -L... switches.
98 allParams=("${params[@]}" ${extra[@]})
99 n=0
100+ while [ $n -lt ${#allParams[*]} ]; do
101 p=${allParams[n]}
102 p2=${allParams[$((n+1))]}
103+ if [ "${p:0:3}" = -L/ ]; then
104 addToLibPath ${p:2}
105+ elif [ "$p" = -L ]; then
106 addToLibPath ${p2}
107 n=$((n + 1))
108+ elif [ "$p" = -l ]; then
109 addToLibs ${p2}
110 n=$((n + 1))
111+ elif [ "${p:0:2}" = -l ]; then
112 addToLibs ${p:2}
113+ elif [ "$p" = -dynamic-linker ]; then
114+ # Ignore the dynamic linker argument, or it
115 # will get into the next 'elif'. We don't want
116 # the dynamic linker path rpath to go always first.
117 n=$((n + 1))
···129 # so, add the directory to the rpath.
130 # It's important to add the rpath in the order of -L..., so
131 # the link time chosen objects will be those of runtime linking.
132+133 for i in $libPath; do
134 for j in $libs; do
135+ if [ -f "$i/lib$j.so" ]; then
136 addToRPath $i
137 break
138 fi
139 done
140 done
141+142143 # Finally, add `-rpath' switches.
144 for i in $rpath; do
···148149150# Optionally print debug info.
151+if [ -n "$NIX_DEBUG" ]; then
152+ echo "original flags to @prog@:" >&2
153 for i in "${params[@]}"; do
154 echo " $i" >&2
155 done
156+ echo "extra flags to @prog@:" >&2
157 for i in ${extra[@]}; do
158 echo " $i" >&2
159 done
160fi
161162+if [ -n "$NIX_LD_WRAPPER_EXEC_HOOK" ]; then
163 source "$NIX_LD_WRAPPER_EXEC_HOOK"
164fi
165166+exec @prog@ ${extraBefore[@]} "${params[@]}" ${extra[@]}
+10-10
pkgs/build-support/gcc-wrapper/setup-hook.sh
···1export NIX_GCC=@out@
23addCVars () {
4- if test -d $1/include; then
5- export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -isystem $1/include"
6 fi
78- if test -d $1/lib64; then
9- export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib64"
10 fi
1112- if test -d $1/lib; then
13- export NIX_LDFLAGS="$NIX_LDFLAGS -L$1/lib"
14 fi
15}
16···1819# Note: these come *after* $out in the PATH (see setup.sh).
2021-if test -n "@gcc@"; then
22 addToSearchPath PATH @gcc@/bin
23fi
2425-if test -n "@binutils@"; then
26 addToSearchPath PATH @binutils@/bin
27fi
2829-if test -n "@libc@"; then
30 addToSearchPath PATH @libc@/bin
31fi
3233-if test -n "@coreutils@"; then
34 addToSearchPath PATH @coreutils@/bin
35fi
···1export NIX_GCC=@out@
23addCVars () {
4+ if [ -d $1/include ]; then
5+ export NIX_CFLAGS_COMPILE+=" -isystem $1/include"
6 fi
78+ if [ -d $1/lib64 -a ! -L $1/lib64 ]; then
9+ export NIX_LDFLAGS+=" -L$1/lib64"
10 fi
1112+ if [ -d $1/lib ]; then
13+ export NIX_LDFLAGS+=" -L$1/lib"
14 fi
15}
16···1819# Note: these come *after* $out in the PATH (see setup.sh).
2021+if [ -n "@gcc@" ]; then
22 addToSearchPath PATH @gcc@/bin
23fi
2425+if [ -n "@binutils@" ]; then
26 addToSearchPath PATH @binutils@/bin
27fi
2829+if [ -n "@libc@" ]; then
30 addToSearchPath PATH @libc@/bin
31fi
3233+if [ -n "@coreutils@" ]; then
34 addToSearchPath PATH @coreutils@/bin
35fi
+4-4
pkgs/build-support/gcc-wrapper/utils.sh
···1skip () {
2- if test "$NIX_DEBUG" = "1"; then
3 echo "skipping impure path $1" >&2
4 fi
5}
···9# `/nix/store/.../lib/foo.so' isn't.
10badPath() {
11 local p=$1
12-13 # Relative paths are okay (since they're presumably relative to
14 # the temporary build directory).
15- if test "${p:0:1}" != "/"; then return 1; fi
16-17 # Otherwise, the path should refer to the store or some temporary
18 # directory (including the build directory).
19 test \
···1skip () {
2+ if [ -n "$NIX_DEBUG" ]; then
3 echo "skipping impure path $1" >&2
4 fi
5}
···9# `/nix/store/.../lib/foo.so' isn't.
10badPath() {
11 local p=$1
12+13 # Relative paths are okay (since they're presumably relative to
14 # the temporary build directory).
15+ if [ "${p:0:1}" != / ]; then return 1; fi
16+17 # Otherwise, the path should refer to the store or some temporary
18 # directory (including the build directory).
19 test \
···10# their absolute path (using "install_name_tool -id"). It also
11# rewrites references in other dylibs to absolute paths.
120013fixDarwinDylibNames() {
14 local flags=()
15 local old_id
···29 local dir="$1"
30 fixDarwinDylibNames $(find "$dir" -name "*.dylib")
31}
32-33-postFixup() {
34- fixDarwinDylibNamesIn "$prefix"
35-}
···10# their absolute path (using "install_name_tool -id"). It also
11# rewrites references in other dylibs to absolute paths.
1213+postFixupHooks+=('fixDarwinDylibNamesIn $prefix')
14+15fixDarwinDylibNames() {
16 local flags=()
17 local old_id
···31 local dir="$1"
32 fixDarwinDylibNames $(find "$dir" -name "*.dylib")
33}
0000
···1+{stdenv, fetchurl, perl, ncurses, gmp}:
2+3+stdenv.mkDerivation rec {
4+ version = "7.8.3";
5+6+ name = "ghc-${version}-binary";
7+8+ src =
9+ if stdenv.system == "i686-linux" then
10+ fetchurl {
11+ url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-unknown-linux.tar.bz2";
12+ sha256 = "0gny7knhss0w0d9r6jm1gghrcb8kqjvj94bb7hxf9syrk4fxlcxi";
13+ }
14+ else if stdenv.system == "x86_64-linux" then
15+ fetchurl {
16+ url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-unknown-linux.tar.bz2";
17+ sha256 = "043jabd0lh6n1zlqhysngbpvlsdznsa2mmsj08jyqgahw9sjb5ns";
18+ }
19+ else if stdenv.system == "i686-darwin" then
20+ fetchurl {
21+ url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-i386-apple-darwin.tar.bz2";
22+ sha256 = "1vrbs3pzki37hzym1f1nh07lrqh066z3ypvm81fwlikfsvk4djc0";
23+ }
24+ else if stdenv.system == "x86_64-darwin" then
25+ fetchurl {
26+ url = "http://haskell.org/ghc/dist/${version}/ghc-${version}-x86_64-apple-darwin.tar.bz2";
27+ sha256 = "1ja0cq5xyjcvjpvjmm4nzhkpmwfs2kjlldbc48lxcs9rmqi7rnay";
28+ }
29+ else throw "cannot bootstrap GHC on this platform";
30+31+ buildInputs = [perl];
32+33+ postUnpack =
34+ # Strip is harmful, see also below. It's important that this happens
35+ # first. The GHC Cabal build system makes use of strip by default and
36+ # has hardcoded paths to /usr/bin/strip in many places. We replace
37+ # those below, making them point to our dummy script.
38+ ''
39+ mkdir "$TMP/bin"
40+ for i in strip; do
41+ echo '#! ${stdenv.shell}' > "$TMP/bin/$i"
42+ chmod +x "$TMP/bin/$i"
43+ done
44+ PATH="$TMP/bin:$PATH"
45+ '' +
46+ # We have to patch the GMP paths for the integer-gmp package.
47+ ''
48+ find . -name integer-gmp.buildinfo \
49+ -exec sed -i "s@extra-lib-dirs: @extra-lib-dirs: ${gmp}/lib@" {} \;
50+ '' +
51+ # On Linux, use patchelf to modify the executables so that they can
52+ # find editline/gmp.
53+ (if stdenv.isLinux then ''
54+ find . -type f -perm +100 \
55+ -exec patchelf --interpreter "$(cat $NIX_GCC/nix-support/dynamic-linker)" \
56+ --set-rpath "${ncurses}/lib:${gmp}/lib" {} \;
57+ sed -i "s|/usr/bin/perl|perl\x00 |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
58+ sed -i "s|/usr/bin/gcc|gcc\x00 |" ghc-${version}/ghc/stage2/build/tmp/ghc-stage2
59+ for prog in ld ar gcc strip ranlib; do
60+ find . -name "setup-config" -exec sed -i "s@/usr/bin/$prog@$(type -p $prog)@g" {} \;
61+ done
62+ '' else "");
63+64+ configurePhase = ''
65+ ./configure --prefix=$out --with-gmp-libraries=${gmp}/lib \
66+ --with-gmp-includes=${gmp}/include
67+ '';
68+69+ # Stripping combined with patchelf breaks the executables (they die
70+ # with a segfault or the kernel even refuses the execve). (NIXPKGS-85)
71+ dontStrip = true;
72+73+ # No building is necessary, but calling make without flags ironically
74+ # calls install-strip ...
75+ buildPhase = "true";
76+77+ postInstall =
78+ ''
79+ # Sanity check, can ghc create executables?
80+ cd $TMP
81+ mkdir test-ghc; cd test-ghc
82+ cat > main.hs << EOF
83+ module Main where
84+ main = putStrLn "yes"
85+ EOF
86+ $out/bin/ghc --make main.hs
87+ echo compilation ok
88+ [ $(./main) == "yes" ]
89+ '';
90+91+ meta.license = stdenv.lib.licenses.bsd3;
92+ meta.platforms = ["x86_64-linux" "i686-linux" "i686-darwin" "x86_64-darwin"];
93+}
-2
pkgs/development/compilers/ghc/7.8.3.nix
···26 export NIX_LDFLAGS="$NIX_LDFLAGS -rpath $out/lib/ghc-${version}"
27 '';
2829- configureFlags = "--with-gcc=${stdenv.gcc}/bin/gcc";
30-31 # required, because otherwise all symbols from HSffi.o are stripped, and
32 # that in turn causes GHCi to abort
33 stripDebugFlags = [ "-S" "--keep-file-symbols" ];
···26 export NIX_LDFLAGS="$NIX_LDFLAGS -rpath $out/lib/ghc-${version}"
27 '';
280029 # required, because otherwise all symbols from HSffi.o are stripped, and
30 # that in turn causes GHCi to abort
31 stripDebugFlags = [ "-S" "--keep-file-symbols" ];
···1{ stdenv, fetch, cmake, libxml2, libedit, llvm, version, clang-tools-extra_src }:
23+# be sure not to rebuild clang on darwin; some packages request it specifically
4+# we need to fix those
5+assert stdenv.isDarwin -> stdenv.gcc.nativeTools;
6+7stdenv.mkDerivation {
8 name = "clang-${version}";
9
···1+diff --git a/configure b/configure
2+index d45e88f..25d872b 100755
3+--- a/configure
4++++ b/configure
5+@@ -322,7 +322,14 @@ case "$bytecc,$target" in
6+ bytecccompopts="-fno-defer-pop $gcc_warnings -DSHRINKED_GNUC"
7+ mathlib="";;
8+ *,*-*-darwin*)
9+- bytecccompopts="-fno-defer-pop $gcc_warnings"
10++ # On recent version of OSX, gcc is a symlink to clang
11++ if $bytecc --version | grep -q clang; then
12++ # -fno-defer-pop is not supported by clang, and make recent
13++ # versions of clang to fail
14++ bytecccompopts="$gcc_warnings"
15++ else
16++ bytecccompopts="-fno-defer-pop $gcc_warnings"
17++ fi
18+ mathlib=""
19+ mkexe="$mkexe -Wl,-no_compact_unwind"
20+ # Tell gcc that we can use 32-bit code addresses for threaded code
+14
pkgs/development/interpreters/guile/clang.patch
···00000000000000
···1+diff --git a/lib/stdint.in.h b/lib/stdint.in.h
2+index 889bca7..15d39b0 100644
3+--- a/lib/stdint.in.h
4++++ b/lib/stdint.in.h
5+@@ -74,7 +74,8 @@
6+ in <inttypes.h> would reinclude us, skipping our contents because
7+ _@GUARD_PREFIX@_STDINT_H is defined.
8+ The include_next requires a split double-inclusion guard. */
9+-# @INCLUDE_NEXT@ @NEXT_STDINT_H@
10++# include <inttypes.h>
11++// # @INCLUDE_NEXT@ @NEXT_STDINT_H@
12+ #endif
13+14+ #if ! defined _@GUARD_PREFIX@_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H
+3-3
pkgs/development/interpreters/guile/default.nix
···7 else stdenv.mkDerivation)
89(rec {
10- name = "guile-2.0.9";
1112 src = fetchurl {
13 url = "mirror://gnu/guile/${name}.tar.xz";
14- sha256 = "0nw9y8vjyz4r61v06p9msks5lm58pd91irmzg4k487vmv743h2pp";
15 };
1617 nativeBuildInputs = [ makeWrapper gawk pkgconfig ];
···2930 enableParallelBuilding = true;
3132- patches = [ ./disable-gc-sensitive-tests.patch ./eai_system.patch ] ++
33 (stdenv.lib.optional (coverageAnalysis != null) ./gcov-file-name.patch);
3435 # Explicitly link against libgcc_s, to work around the infamous
···7 else stdenv.mkDerivation)
89(rec {
10+ name = "guile-2.0.11";
1112 src = fetchurl {
13 url = "mirror://gnu/guile/${name}.tar.xz";
14+ sha256 = "1qh3j7308qvsjgwf7h94yqgckpbgz2k3yqdkzsyhqcafvfka9l5f";
15 };
1617 nativeBuildInputs = [ makeWrapper gawk pkgconfig ];
···2930 enableParallelBuilding = true;
3132+ patches = [ ./disable-gc-sensitive-tests.patch ./eai_system.patch ./clang.patch ] ++
33 (stdenv.lib.optional (coverageAnalysis != null) ./gcov-file-name.patch);
3435 # Explicitly link against libgcc_s, to work around the infamous
···1+--- src/dbinc/atomic.h 2013-03-12 14:07:22.000000000 -0400
2++++ src/dbinc/atomic.h.change 2013-03-12 14:06:35.000000000 -0400
3+@@ -144,7 +144,7 @@
4+ #define atomic_inc(env, p) __atomic_inc(p)
5+ #define atomic_dec(env, p) __atomic_dec(p)
6+ #define atomic_compare_exchange(env, p, o, n) \
7+- __atomic_compare_exchange((p), (o), (n))
8++ __atomic_compare_exchange_db((p), (o), (n))
9+ static inline int __atomic_inc(db_atomic_t *p)
10+ {
11+ int temp;
12+@@ -176,7 +176,7 @@
13+ * http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html
14+ * which configure could be changed to use.
15+ */
16+-static inline int __atomic_compare_exchange(
17++static inline int __atomic_compare_exchange_db(
18+ db_atomic_t *p, atomic_value_t oldval, atomic_value_t newval)
19+ {
20+ atomic_value_t was;
+3
pkgs/development/libraries/gmp/5.1.x.nix
···16 # Build a "fat binary", with routines for several sub-architectures
17 # (x86), except on Solaris where some tests crash with "Memory fault".
18 # See <http://hydra.nixos.org/build/2760931>, for instance.
0019 optional (!stdenv.isSunOS) "--enable-fat"
20 ++ (if cxx then [ "--enable-cxx" ]
21 else [ "--disable-cxx" ])
22 ++ optional (cxx && stdenv.isDarwin) "CPPFLAGS=-fexceptions"
023 ++ optional stdenv.is64bit "--with-pic"
24 ;
25
···16 # Build a "fat binary", with routines for several sub-architectures
17 # (x86), except on Solaris where some tests crash with "Memory fault".
18 # See <http://hydra.nixos.org/build/2760931>, for instance.
19+ #
20+ # no darwin because gmp uses ASM that clang doesn't like
21 optional (!stdenv.isSunOS) "--enable-fat"
22 ++ (if cxx then [ "--enable-cxx" ]
23 else [ "--disable-cxx" ])
24 ++ optional (cxx && stdenv.isDarwin) "CPPFLAGS=-fexceptions"
25+ ++ optional stdenv.isDarwin "ABI=64"
26 ++ optional stdenv.is64bit "--with-pic"
27 ;
28
···16 "--with-gcc-arch=generic" # no detection of -march= or -mtune=
17 ] ++ stdenv.lib.optional (stdenv.needsPax) "--enable-pax_emutramp";
1819- doCheck = stdenv.isLinux; # until we solve dejagnu problems on darwin and expect on BSD
02021 dontStrip = stdenv ? cross; # Don't run the native `strip' when cross-compiling.
2223 postInstall =
24 # Install headers in the right place.
25- '' ln -s${if stdenv.isFreeBSD then "" else "r"}v "$out/lib/"libffi*/include "$out/include"
26 '';
2728 meta = {
···16 "--with-gcc-arch=generic" # no detection of -march= or -mtune=
17 ] ++ stdenv.lib.optional (stdenv.needsPax) "--enable-pax_emutramp";
1819+ #doCheck = stdenv.isLinux; # until we solve dejagnu problems on darwin and expect on BSD
20+ doCheck = false;
2122 dontStrip = stdenv ? cross; # Don't run the native `strip' when cross-compiling.
2324 postInstall =
25 # Install headers in the right place.
26+ '' ln -s${if stdenv.isBSD then "" else "r"}v "$out/lib/"libffi*/include "$out/include"
27 '';
2829 meta = {
+2
pkgs/development/libraries/libgcrypt/default.nix
···1011 propagatedBuildInputs = [ libgpgerror ];
120013 doCheck = stdenv.system != "i686-linux"; # "basic" test fails after stdenv+glibc-2.18
1415 # For some reason the tests don't find `libgpg-error.so'.
···1011 propagatedBuildInputs = [ libgpgerror ];
1213+ configureFlags = stdenv.lib.optional stdenv.isDarwin "--disable-asm";
14+15 doCheck = stdenv.system != "i686-linux"; # "basic" test fails after stdenv+glibc-2.18
1617 # For some reason the tests don't find `libgpg-error.so'.
···1011 buildInputs = [ gmp ];
120013 configureFlags =
14 /* Work around a FreeBSD bug that otherwise leads to segfaults in the test suite:
15 http://hydra.bordeaux.inria.fr/build/34862
···1011 buildInputs = [ gmp ];
1213+ CFLAGS = "-I${gmp}/include";
14+15 configureFlags =
16 /* Work around a FreeBSD bug that otherwise leads to segfaults in the test suite:
17 http://hydra.bordeaux.inria.fr/build/34862
···33 pkgs = stdenvNativePkgs;
34 };
35000000000000000000003637 # Linux standard environment.
38 stdenvLinux = (import ./linux { inherit system allPackages platform config lib; }).stdenvLinux;
···47 if system == "armv7l-linux" then stdenvLinux else
48 if system == "mips64el-linux" then stdenvLinux else
49 if system == "powerpc-linux" then /* stdenvLinux */ stdenvNative else
50- if system == "x86_64-darwin" then stdenvNix else
51 if system == "x86_64-solaris" then stdenvNix else
52 stdenvNative;
53}
···33 pkgs = stdenvNativePkgs;
34 };
3536+ stdenvDarwin = import ./darwin {
37+ inherit config;
38+ stdenv = stdenvNative;
39+ pkgs = stdenvNativePkgs;
40+ };
41+42+ stdenvDarwinNaked = import ./darwin {
43+ inherit config;
44+ stdenv = stdenvNative;
45+ pkgs = stdenvNativePkgs;
46+ haveLibCxx = false;
47+ };
48+49+ stdenvDarwin33 = import ./darwin {
50+ inherit config;
51+ stdenv = stdenvNative;
52+ pkgs = stdenvNativePkgs;
53+ useClang33 = true;
54+ };
55+5657 # Linux standard environment.
58 stdenvLinux = (import ./linux { inherit system allPackages platform config lib; }).stdenvLinux;
···67 if system == "armv7l-linux" then stdenvLinux else
68 if system == "mips64el-linux" then stdenvLinux else
69 if system == "powerpc-linux" then /* stdenvLinux */ stdenvNative else
70+ if system == "x86_64-darwin" then stdenvDarwin else
71 if system == "x86_64-solaris" then stdenvNix else
72 stdenvNative;
73}
+2-1
pkgs/stdenv/generic/default.nix
···164 isBSD = system == "i686-freebsd"
165 || system == "x86_64-freebsd"
166 || system == "i686-openbsd"
167- || system == "x86_64-openbsd";
0168 isi686 = system == "i686-linux"
169 || system == "i686-gnu"
170 || system == "i686-freebsd"
···164 isBSD = system == "i686-freebsd"
165 || system == "x86_64-freebsd"
166 || system == "i686-openbsd"
167+ || system == "x86_64-openbsd"
168+ || system == "x86_64-darwin";
169 isi686 = system == "i686-linux"
170 || system == "i686-gnu"
171 || system == "i686-freebsd"
···1-{ stdenv, fetchurl, gettext }:
23stdenv.mkDerivation rec {
4 name = "sharutils-4.11.1";
···12 ''
13 # Fix for building on Glibc 2.16. Won't be needed once the
14 # gnulib in sharutils is updated.
15- sed -i '/gets is a security hole/d' lib/stdio.in.h
16 '';
1718 # GNU Gettext is needed on non-GNU platforms.
19- buildInputs = [ gettext ];
2021 doCheck = true;
22
···1+{ stdenv, fetchurl, gettext, coreutils }:
23stdenv.mkDerivation rec {
4 name = "sharutils-4.11.1";
···12 ''
13 # Fix for building on Glibc 2.16. Won't be needed once the
14 # gnulib in sharutils is updated.
15+ sed -i ${stdenv.lib.optionalString (stdenv.isBSD && stdenv.gcc.nativeTools) "''"} '/gets is a security hole/d' lib/stdio.in.h
16 '';
1718 # GNU Gettext is needed on non-GNU platforms.
19+ buildInputs = [ gettext coreutils ];
2021 doCheck = true;
22
···66 enableParallelBuilding = true;
6768 meta = {
00069 description = "Powerful package manager that makes package management reliable and reproducible";
70 longDescription = ''
71 Nix is a powerful package manager for Linux and other Unix systems that
···66 enableParallelBuilding = true;
6768 meta = {
69+ # due to builder args bug; see
70+ # https://github.com/NixOS/nix/commit/b224ac15201c57b40ea855f5a98b1bd166c1c7f6
71+ broken = stdenv.isDarwin;
72 description = "Powerful package manager that makes package management reliable and reproducible";
73 longDescription = ''
74 Nix is a powerful package manager for Linux and other Unix systems that