Merge branch 'master' into gcc-6
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null
|
||||
, buildPackages ? {}, hostPlatform, targetPlatform
|
||||
, runCommand ? null
|
||||
, useMacosReexportHack ? false
|
||||
}:
|
||||
|
||||
with stdenv.lib;
|
||||
@@ -52,75 +53,28 @@ let
|
||||
"-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/$(${cc.gcc}/bin/gcc -dumpmachine)";
|
||||
|
||||
dashlessTarget = stdenv.lib.replaceStrings ["-"] ["_"] targetPlatform.config;
|
||||
# TODO(@Ericson2314) Make unconditional
|
||||
infixSalt = stdenv.lib.optionalString (targetPlatform != hostPlatform) dashlessTarget;
|
||||
infixSalt_ = stdenv.lib.optionalString (targetPlatform != hostPlatform) (dashlessTarget + "_");
|
||||
_infixSalt = stdenv.lib.optionalString (targetPlatform != hostPlatform) ("_" + dashlessTarget);
|
||||
|
||||
# We want to prefix all NIX_ flags with the target triple
|
||||
preWrap = textFile:
|
||||
# TODO: Do even when not cross on next mass-rebuild
|
||||
# TODO: use @target_tripple@ for consistency
|
||||
if targetPlatform == hostPlatform
|
||||
then textFile
|
||||
else runCommand "sed-nix-env-vars" {} (''
|
||||
cp --no-preserve=mode ${textFile} $out
|
||||
# The "infix salt" is a arbitrary string added in the middle of env vars
|
||||
# defined by cc-wrapper's hooks so that multiple cc-wrappers can be used
|
||||
# without interfering. For the moment, it is defined as the target triple,
|
||||
# adjusted to be a valid bash identifier. This should be considered an
|
||||
# unstable implementation detail, however.
|
||||
infixSalt = dashlessTarget;
|
||||
|
||||
sed -i $out \
|
||||
-e 's^NIX_^NIX_${infixSalt_}^g' \
|
||||
-e 's^addCVars^addCVars${_infixSalt}^g' \
|
||||
-e 's^\[ -z "\$crossConfig" \]^\[\[ "${builtins.toString (targetPlatform != hostPlatform)}" || -z "$crossConfig" \]\]^g'
|
||||
|
||||
'' + stdenv.lib.optionalString (textFile == ./setup-hook.sh) ''
|
||||
cat << 'EOF' >> $out
|
||||
for CMD in ar as nm objcopy ranlib strip strings size ld windres
|
||||
do
|
||||
# which is not part of stdenv, but compgen will do for now
|
||||
if
|
||||
PATH=$_PATH type -p ${prefix}$CMD > /dev/null
|
||||
then
|
||||
export ''$(echo "$CMD" | tr "[:lower:]" "[:upper:]")=${prefix}''${CMD};
|
||||
fi
|
||||
done
|
||||
EOF
|
||||
|
||||
sed -i $out -e 's_envHooks_crossEnvHooks_g'
|
||||
'' + ''
|
||||
|
||||
# NIX_ things which we don't both use and define, we revert them
|
||||
#asymmetric=$(
|
||||
# for pre in "" "\\$"
|
||||
# do
|
||||
# grep -E -ho $pre'NIX_[a-zA-Z_]*' ./* | sed 's/\$//' | sort | uniq
|
||||
# done | sort | uniq -c | sort -nr | sed -n 's/^1 NIX_//gp')
|
||||
|
||||
# hard-code for now
|
||||
asymmetric=("CXXSTDLIB_COMPILE" "CC")
|
||||
|
||||
# The ([^a-zA-Z_]|$) bussiness is to ensure environment variables that
|
||||
# begin with `NIX_CC` don't also get blacklisted.
|
||||
for var in "''${asymmetric[@]}"
|
||||
do
|
||||
sed -i $out -E -e "s~NIX_${infixSalt_}$var([^a-zA-Z_]|$)~NIX_$var\1~g"
|
||||
done
|
||||
'');
|
||||
|
||||
# The dynamic linker has different names on different platforms.
|
||||
# The dynamic linker has different names on different platforms. This is a
|
||||
# shell glob that ought to match it.
|
||||
dynamicLinker =
|
||||
if !nativeLibc then
|
||||
(if targetPlatform.system == "i686-linux" then "ld-linux.so.2" else
|
||||
if targetPlatform.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
|
||||
# ARM with a wildcard, which can be "" or "-armhf".
|
||||
if targetPlatform.isArm32 then "ld-linux*.so.3" else
|
||||
if targetPlatform.system == "aarch64-linux" then "ld-linux-aarch64.so.1" else
|
||||
if targetPlatform.system == "powerpc-linux" then "ld.so.1" else
|
||||
if targetPlatform.system == "mips64el-linux" then "ld.so.1" else
|
||||
if targetPlatform.system == "x86_64-darwin" then "/usr/lib/dyld" else
|
||||
if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1" else
|
||||
builtins.trace
|
||||
"Don't know the name of the dynamic linker for platform ${targetPlatform.config}, so guessing instead."
|
||||
null)
|
||||
else "";
|
||||
/**/ if libc == null then null
|
||||
else if targetPlatform.system == "i686-linux" then "${libc_lib}/lib/ld-linux.so.2"
|
||||
else if targetPlatform.system == "x86_64-linux" then "${libc_lib}/lib/ld-linux-x86-64.so.2"
|
||||
# ARM with a wildcard, which can be "" or "-armhf".
|
||||
else if targetPlatform.isArm32 then "${libc_lib}/lib/ld-linux*.so.3"
|
||||
else if targetPlatform.system == "aarch64-linux" then "${libc_lib}/lib/ld-linux-aarch64.so.1"
|
||||
else if targetPlatform.system == "powerpc-linux" then "${libc_lib}/lib/ld.so.1"
|
||||
else if targetPlatform.system == "mips64el-linux" then "${libc_lib}/lib/ld.so.1"
|
||||
else if targetPlatform.system == "x86_64-darwin" then "/usr/lib/dyld"
|
||||
else if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1"
|
||||
else null;
|
||||
|
||||
expand-response-params = if buildPackages.stdenv.cc or null != null && buildPackages.stdenv.cc != "/dev/null"
|
||||
then buildPackages.stdenv.mkDerivation {
|
||||
@@ -147,21 +101,24 @@ stdenv.mkDerivation {
|
||||
inherit cc shell libc_bin libc_dev libc_lib binutils_bin coreutils_bin;
|
||||
gnugrep_bin = if nativeTools then "" else gnugrep;
|
||||
|
||||
binPrefix = prefix;
|
||||
inherit infixSalt;
|
||||
|
||||
outputs = [ "out" "man" ];
|
||||
|
||||
passthru = {
|
||||
inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile
|
||||
prefix infixSalt infixSalt_ _infixSalt;
|
||||
prefix;
|
||||
|
||||
emacsBufferSetup = pkgs: ''
|
||||
; We should handle propagation here too
|
||||
(mapc (lambda (arg)
|
||||
(when (file-directory-p (concat arg "/include"))
|
||||
(setenv "NIX_${infixSalt_}CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt_}CFLAGS_COMPILE") " -isystem " arg "/include")))
|
||||
(setenv "NIX_${infixSalt}_CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt}_CFLAGS_COMPILE") " -isystem " arg "/include")))
|
||||
(when (file-directory-p (concat arg "/lib"))
|
||||
(setenv "NIX_${infixSalt_}LDFLAGS" (concat (getenv "NIX_${infixSalt_}LDFLAGS") " -L" arg "/lib")))
|
||||
(setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib")))
|
||||
(when (file-directory-p (concat arg "/lib64"))
|
||||
(setenv "NIX_${infixSalt_}LDFLAGS" (concat (getenv "NIX_${infixSalt_}LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
|
||||
(setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
|
||||
'';
|
||||
};
|
||||
|
||||
@@ -178,39 +135,39 @@ stdenv.mkDerivation {
|
||||
}
|
||||
''
|
||||
|
||||
# TODO(@Ericson2314): Unify logic next hash break
|
||||
+ optionalString (libc != null) (if (targetPlatform.isDarwin) then ''
|
||||
echo $dynamicLinker > $out/nix-support/dynamic-linker
|
||||
|
||||
echo "export LD_DYLD_PATH=\"$dynamicLinker\"" >> $out/nix-support/setup-hook
|
||||
'' else if dynamicLinker != null then ''
|
||||
dynamicLinker="${libc_lib}/lib/$dynamicLinker"
|
||||
echo $dynamicLinker > $out/nix-support/dynamic-linker
|
||||
|
||||
if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then
|
||||
echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
|
||||
+ optionalString (libc != null) (''
|
||||
if [[ -z ''${dynamicLinker+x} ]]; then
|
||||
echo "Don't know the name of the dynamic linker for platform '${targetPlatform.config}', so guessing instead." >&2
|
||||
dynamicLinker="${libc_lib}/lib/ld*.so.?"
|
||||
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 ''
|
||||
dynamicLinker=`eval 'echo $libc/lib/ld*.so.?'`
|
||||
# Expand globs to fill array of options
|
||||
dynamicLinker=($dynamicLinker)
|
||||
|
||||
case ''${#dynamicLinker[@]} in
|
||||
0) echo "No dynamic linker found for platform '${targetPlatform.config}'." >&2;;
|
||||
1) echo "Using dynamic linker: '$dynamicLinker'" >&2;;
|
||||
*) echo "Multiple dynamic linkers found for platform '${targetPlatform.config}'." >&2;;
|
||||
esac
|
||||
|
||||
if [ -n "$dynamicLinker" ]; then
|
||||
echo $dynamicLinker > $out/nix-support/dynamic-linker
|
||||
|
||||
'' + (if targetPlatform.isDarwin then ''
|
||||
printf "export LD_DYLD_PATH=%q\n" "$dynamicLinker" >> $out/nix-support/setup-hook
|
||||
'' else ''
|
||||
if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then
|
||||
echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32
|
||||
fi
|
||||
|
||||
ldflagsBefore="-dynamic-linker $dlinker"
|
||||
ldflagsBefore=(-dynamic-linker "$dynamicLinker")
|
||||
'') + ''
|
||||
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 "$ldflagsBefore" > $out/nix-support/libc-ldflags-before
|
||||
printWords "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before
|
||||
'')
|
||||
|
||||
+ optionalString (libc != null) ''
|
||||
@@ -278,17 +235,17 @@ stdenv.mkDerivation {
|
||||
# Propagate the wrapped cc so that if you install the wrapper,
|
||||
# you get tools like gcov, the manpages, etc. as well (including
|
||||
# for binutils and Glibc).
|
||||
echo ${cc} ${binutils_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages
|
||||
echo ${cc.man or ""} > $man/nix-support/propagated-user-env-packages
|
||||
printWords ${cc} ${binutils_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages
|
||||
printWords ${cc.man or ""} > $man/nix-support/propagated-user-env-packages
|
||||
|
||||
echo ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs
|
||||
printWords ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs
|
||||
''
|
||||
|
||||
+ optionalString (targetPlatform.isSunOS && nativePrefix != "") ''
|
||||
# Solaris needs an additional ld wrapper.
|
||||
ldPath="${nativePrefix}/bin"
|
||||
exec="$ldPath/${prefix}ld"
|
||||
wrap ld-solaris ${preWrap ./ld-solaris-wrapper.sh}
|
||||
wrap ld-solaris ${./ld-solaris-wrapper.sh}
|
||||
'')
|
||||
|
||||
+ ''
|
||||
@@ -299,64 +256,75 @@ stdenv.mkDerivation {
|
||||
ln -s $ldPath/${prefix}as $out/bin/${prefix}as
|
||||
fi
|
||||
|
||||
wrap ${prefix}ld ${preWrap ./ld-wrapper.sh} ''${ld:-$ldPath/${prefix}ld}
|
||||
'' + (if !useMacosReexportHack then ''
|
||||
wrap ${prefix}ld ${./ld-wrapper.sh} ''${ld:-$ldPath/${prefix}ld}
|
||||
'' else ''
|
||||
ldInner="${prefix}ld-reexport-delegate"
|
||||
wrap "$ldInner" ${./macos-sierra-reexport-hack.bash} ''${ld:-$ldPath/${prefix}ld}
|
||||
wrap "${prefix}ld" ${./ld-wrapper.sh} "$out/bin/$ldInner"
|
||||
unset ldInner
|
||||
'') + ''
|
||||
|
||||
if [ -e ${binutils_bin}/bin/${prefix}ld.gold ]; then
|
||||
wrap ${prefix}ld.gold ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold
|
||||
wrap ${prefix}ld.gold ${./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold
|
||||
fi
|
||||
|
||||
if [ -e ${binutils_bin}/bin/ld.bfd ]; then
|
||||
wrap ${prefix}ld.bfd ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd
|
||||
wrap ${prefix}ld.bfd ${./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd
|
||||
fi
|
||||
|
||||
export real_cc=${prefix}cc
|
||||
export real_cxx=${prefix}c++
|
||||
# We export environment variables pointing to the wrapped nonstandard
|
||||
# cmds, lest some lousy configure script use those to guess compiler
|
||||
# version.
|
||||
export named_cc=${prefix}cc
|
||||
export named_cxx=${prefix}c++
|
||||
|
||||
export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}"
|
||||
|
||||
if [ -e $ccPath/${prefix}gcc ]; then
|
||||
wrap ${prefix}gcc ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcc
|
||||
wrap ${prefix}gcc ${./cc-wrapper.sh} $ccPath/${prefix}gcc
|
||||
ln -s ${prefix}gcc $out/bin/${prefix}cc
|
||||
export real_cc=${prefix}gcc
|
||||
export real_cxx=${prefix}g++
|
||||
export named_cc=${prefix}gcc
|
||||
export named_cxx=${prefix}g++
|
||||
elif [ -e $ccPath/clang ]; then
|
||||
wrap ${prefix}clang ${preWrap ./cc-wrapper.sh} $ccPath/clang
|
||||
wrap ${prefix}clang ${./cc-wrapper.sh} $ccPath/clang
|
||||
ln -s ${prefix}clang $out/bin/${prefix}cc
|
||||
export real_cc=clang
|
||||
export real_cxx=clang++
|
||||
export named_cc=${prefix}clang
|
||||
export named_cxx=${prefix}clang++
|
||||
fi
|
||||
|
||||
if [ -e $ccPath/${prefix}g++ ]; then
|
||||
wrap ${prefix}g++ ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}g++
|
||||
wrap ${prefix}g++ ${./cc-wrapper.sh} $ccPath/${prefix}g++
|
||||
ln -s ${prefix}g++ $out/bin/${prefix}c++
|
||||
elif [ -e $ccPath/clang++ ]; then
|
||||
wrap ${prefix}clang++ ${preWrap ./cc-wrapper.sh} $ccPath/clang++
|
||||
wrap ${prefix}clang++ ${./cc-wrapper.sh} $ccPath/clang++
|
||||
ln -s ${prefix}clang++ $out/bin/${prefix}c++
|
||||
fi
|
||||
|
||||
if [ -e $ccPath/cpp ]; then
|
||||
wrap ${prefix}cpp ${preWrap ./cc-wrapper.sh} $ccPath/cpp
|
||||
wrap ${prefix}cpp ${./cc-wrapper.sh} $ccPath/cpp
|
||||
fi
|
||||
''
|
||||
|
||||
+ optionalString cc.langFortran or false ''
|
||||
wrap ${prefix}gfortran ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gfortran
|
||||
wrap ${prefix}gfortran ${./cc-wrapper.sh} $ccPath/${prefix}gfortran
|
||||
ln -sv ${prefix}gfortran $out/bin/${prefix}g77
|
||||
ln -sv ${prefix}gfortran $out/bin/${prefix}f77
|
||||
''
|
||||
|
||||
+ optionalString cc.langJava or false ''
|
||||
wrap ${prefix}gcj ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcj
|
||||
wrap ${prefix}gcj ${./cc-wrapper.sh} $ccPath/${prefix}gcj
|
||||
''
|
||||
|
||||
+ optionalString cc.langGo or false ''
|
||||
wrap ${prefix}gccgo ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gccgo
|
||||
wrap ${prefix}gccgo ${./cc-wrapper.sh} $ccPath/${prefix}gccgo
|
||||
''
|
||||
|
||||
+ optionalString cc.langAda or false ''
|
||||
wrap ${prefix}gnatgcc ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gnatgcc
|
||||
wrap ${prefix}gnatmake ${preWrap ./gnat-wrapper.sh} $ccPath/${prefix}gnatmake
|
||||
wrap ${prefix}gnatbind ${preWrap ./gnat-wrapper.sh} $ccPath/${prefix}gnatbind
|
||||
wrap ${prefix}gnatlink ${preWrap ./gnatlink-wrapper.sh} $ccPath/${prefix}gnatlink
|
||||
wrap ${prefix}gnatgcc ${./cc-wrapper.sh} $ccPath/${prefix}gnatgcc
|
||||
wrap ${prefix}gnatmake ${./gnat-wrapper.sh} $ccPath/${prefix}gnatmake
|
||||
wrap ${prefix}gnatbind ${./gnat-wrapper.sh} $ccPath/${prefix}gnatbind
|
||||
wrap ${prefix}gnatlink ${./gnatlink-wrapper.sh} $ccPath/${prefix}gnatlink
|
||||
''
|
||||
|
||||
+ optionalString cc.langVhdl or false ''
|
||||
@@ -364,7 +332,7 @@ stdenv.mkDerivation {
|
||||
''
|
||||
|
||||
+ ''
|
||||
substituteAll ${preWrap ./setup-hook.sh} $out/nix-support/setup-hook.tmp
|
||||
substituteAll ${./setup-hook.sh} $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
|
||||
|
||||
@@ -383,9 +351,9 @@ stdenv.mkDerivation {
|
||||
''
|
||||
|
||||
+ ''
|
||||
substituteAll ${preWrap ./add-flags.sh} $out/nix-support/add-flags.sh
|
||||
substituteAll ${preWrap ./add-hardening.sh} $out/nix-support/add-hardening.sh
|
||||
substituteAll ${preWrap ./utils.sh} $out/nix-support/utils.sh
|
||||
substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
|
||||
substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
|
||||
substituteAll ${./utils.sh} $out/nix-support/utils.sh
|
||||
''
|
||||
+ extraBuildCommands;
|
||||
|
||||
@@ -403,5 +371,7 @@ stdenv.mkDerivation {
|
||||
{ description =
|
||||
stdenv.lib.attrByPath ["meta" "description"] "System C compiler" cc_
|
||||
+ " (wrapper script)";
|
||||
};
|
||||
} // optionalAttrs useMacosReexportHack {
|
||||
platforms = stdenv.lib.platforms.darwin;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user