2015-01-09 20:22:12 +01:00
|
|
|
# The Nixpkgs CC is not directly usable, since it doesn't know where
|
2014-10-10 13:49:26 +02:00
|
|
|
# the C library and standard header files are. Therefore the compiler
|
|
|
|
# produced by that package cannot be installed directly in a user
|
|
|
|
# environment and used from the command line. So we use a wrapper
|
|
|
|
# script that sets up the right environment variables so that the
|
|
|
|
# compiler and the linker just "work".
|
2008-06-26 13:07:46 +02:00
|
|
|
|
2017-05-23 02:59:39 +02:00
|
|
|
{ name ? "", stdenv, nativeTools, noLibc ? false, nativeLibc, nativePrefix ? ""
|
2015-01-09 20:22:12 +01:00
|
|
|
, cc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? stdenv.shell
|
2015-07-20 13:42:30 +02:00
|
|
|
, zlib ? null, extraPackages ? [], extraBuildCommands ? ""
|
2015-02-08 19:36:13 +01:00
|
|
|
, dyld ? null # TODO: should this be a setup-hook on dyld?
|
2015-12-17 23:02:40 +01:00
|
|
|
, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null
|
2017-02-14 00:01:04 +01:00
|
|
|
, hostPlatform, targetPlatform
|
2017-05-23 03:00:21 +02:00
|
|
|
, runCommand ? null
|
2008-06-26 13:07:46 +02:00
|
|
|
}:
|
|
|
|
|
2014-10-10 13:49:26 +02:00
|
|
|
with stdenv.lib;
|
|
|
|
|
2008-06-26 13:07:46 +02:00
|
|
|
assert nativeTools -> nativePrefix != "";
|
2015-12-17 23:02:40 +01:00
|
|
|
assert !nativeTools ->
|
|
|
|
cc != null && binutils != null && coreutils != null && gnugrep != null;
|
2017-05-23 02:59:39 +02:00
|
|
|
assert !(nativeLibc && noLibc);
|
|
|
|
assert (noLibc || nativeLibc) == (libc == null);
|
2008-06-26 13:07:46 +02:00
|
|
|
|
2017-05-23 03:00:21 +02:00
|
|
|
assert targetPlatform != hostPlatform -> runCommand != null;
|
|
|
|
|
2014-10-10 13:49:26 +02:00
|
|
|
# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper.
|
2015-01-09 20:22:12 +01:00
|
|
|
assert cc.langVhdl or false -> zlib != null;
|
2010-01-16 22:41:27 +01:00
|
|
|
|
2009-04-09 17:24:33 +02:00
|
|
|
let
|
2017-02-14 00:01:04 +01:00
|
|
|
# Prefix for binaries. Customarily ends with a dash separator.
|
|
|
|
#
|
|
|
|
# TODO(@Ericson2314) Make unconditional, or optional but always true by
|
|
|
|
# default.
|
|
|
|
prefix = stdenv.lib.optionalString (targetPlatform != hostPlatform)
|
|
|
|
(targetPlatform.config + "-");
|
2009-04-09 17:24:33 +02:00
|
|
|
|
2015-01-09 20:22:12 +01:00
|
|
|
ccVersion = (builtins.parseDrvName cc.name).version;
|
|
|
|
ccName = (builtins.parseDrvName cc.name).name;
|
2012-08-03 19:23:51 +02:00
|
|
|
|
2017-05-23 02:59:39 +02:00
|
|
|
libc_bin = if libc == null then null else getBin libc;
|
|
|
|
libc_dev = if libc == null then null else getDev libc;
|
|
|
|
libc_lib = if libc == null then null else getLib libc;
|
2016-04-14 18:00:39 +02:00
|
|
|
cc_solib = getLib cc;
|
|
|
|
binutils_bin = if nativeTools then "" else getBin binutils;
|
2016-02-03 16:54:03 +01:00
|
|
|
# The wrapper scripts use 'cat' and 'grep', so we may need coreutils.
|
2016-04-14 18:00:39 +02:00
|
|
|
coreutils_bin = if nativeTools then "" else getBin coreutils;
|
2017-06-08 20:00:40 +02:00
|
|
|
|
2017-05-21 20:51:02 +02:00
|
|
|
default_cxx_stdlib_compile=optionalString (targetPlatform.isLinux && !(cc.isGNU or false))
|
2017-06-08 20:00:40 +02:00
|
|
|
"-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/$(${cc.gcc}/bin/gcc -dumpmachine)";
|
2017-05-23 02:59:39 +02:00
|
|
|
|
|
|
|
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);
|
2017-05-23 03:00:21 +02:00
|
|
|
|
|
|
|
# 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
|
2017-05-31 05:31:44 +02:00
|
|
|
else runCommand "sed-nix-env-vars" {} (''
|
|
|
|
cp --no-preserve=mode ${textFile} $out
|
2017-05-23 03:00:21 +02:00
|
|
|
|
|
|
|
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'
|
|
|
|
|
2017-05-31 05:31:44 +02:00
|
|
|
'' + stdenv.lib.optionalString (textFile == ./setup-hook.sh) ''
|
|
|
|
cat << 'EOF' >> $out
|
|
|
|
for CMD in ar as nm objcopy ranlib strip strings size ld
|
|
|
|
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
|
|
|
|
'' + ''
|
|
|
|
|
2017-05-23 03:00:21 +02:00
|
|
|
# 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
|
2017-05-31 05:31:44 +02:00
|
|
|
'');
|
2009-04-09 17:24:33 +02:00
|
|
|
in
|
2009-03-25 18:34:38 +01:00
|
|
|
|
2012-12-29 15:11:32 +01:00
|
|
|
stdenv.mkDerivation {
|
2017-02-14 00:01:04 +01:00
|
|
|
name = prefix
|
|
|
|
+ (if name != "" then name else "${ccName}-wrapper")
|
|
|
|
+ (stdenv.lib.optionalString (cc != null && ccVersion != "") "-${ccVersion}");
|
2014-02-04 16:58:12 +01:00
|
|
|
|
2014-10-10 13:49:26 +02:00
|
|
|
preferLocalBuild = true;
|
|
|
|
|
2015-04-18 15:46:00 +02:00
|
|
|
inherit cc shell libc_bin libc_dev libc_lib binutils_bin coreutils_bin;
|
2016-02-01 14:42:33 +01:00
|
|
|
gnugrep_bin = if nativeTools then "" else gnugrep;
|
2014-02-04 16:58:12 +01:00
|
|
|
|
2017-06-08 20:00:40 +02:00
|
|
|
|
2016-10-07 16:31:37 +02:00
|
|
|
passthru = {
|
2017-02-14 00:01:04 +01:00
|
|
|
inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile
|
2017-05-23 02:59:39 +02:00
|
|
|
prefix infixSalt infixSalt_ _infixSalt;
|
2016-10-07 16:31:37 +02:00
|
|
|
|
|
|
|
emacsBufferSetup = pkgs: ''
|
|
|
|
; We should handle propagation here too
|
|
|
|
(mapc (lambda (arg)
|
|
|
|
(when (file-directory-p (concat arg "/include"))
|
2017-05-23 02:59:39 +02:00
|
|
|
(setenv "NIX_${infixSalt_}CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt_}CFLAGS_COMPILE") " -isystem " arg "/include")))
|
2016-10-07 16:31:37 +02:00
|
|
|
(when (file-directory-p (concat arg "/lib"))
|
2017-05-23 02:59:39 +02:00
|
|
|
(setenv "NIX_${infixSalt_}LDFLAGS" (concat (getenv "NIX_${infixSalt_}LDFLAGS") " -L" arg "/lib")))
|
2016-10-07 16:31:37 +02:00
|
|
|
(when (file-directory-p (concat arg "/lib64"))
|
2017-05-23 02:59:39 +02:00
|
|
|
(setenv "NIX_${infixSalt_}LDFLAGS" (concat (getenv "NIX_${infixSalt_}LDFLAGS") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
|
2016-10-07 16:31:37 +02:00
|
|
|
'';
|
|
|
|
};
|
2014-10-10 13:49:26 +02:00
|
|
|
|
|
|
|
buildCommand =
|
|
|
|
''
|
|
|
|
mkdir -p $out/bin $out/nix-support
|
|
|
|
|
|
|
|
wrap() {
|
|
|
|
local dst="$1"
|
|
|
|
local wrapper="$2"
|
|
|
|
export prog="$3"
|
|
|
|
substituteAll "$wrapper" "$out/bin/$dst"
|
|
|
|
chmod +x "$out/bin/$dst"
|
|
|
|
}
|
|
|
|
''
|
|
|
|
|
2017-05-23 02:59:39 +02:00
|
|
|
+ optionalString (libc != null) (if (!targetPlatform.isDarwin) then ''
|
2015-04-18 15:46:00 +02:00
|
|
|
dynamicLinker="${libc_lib}/lib/$dynamicLinker"
|
2014-10-10 13:49:26 +02:00
|
|
|
echo $dynamicLinker > $out/nix-support/dynamic-linker
|
|
|
|
|
2015-04-18 15:46:00 +02:00
|
|
|
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
|
2014-10-10 13:49:26 +02:00
|
|
|
fi
|
|
|
|
|
2015-02-08 19:36:13 +01:00
|
|
|
# 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
|
|
|
|
'')
|
|
|
|
|
2017-05-23 02:59:39 +02:00
|
|
|
+ optionalString (libc != null) ''
|
2016-01-02 11:14:09 +01:00
|
|
|
# The "-B${libc_lib}/lib/" flag is a quick hack to force gcc to link
|
2014-10-10 13:49:26 +02:00
|
|
|
# against the crt1.o from our own glibc, rather than the one in
|
|
|
|
# /usr/lib. (This is only an issue when using an `impure'
|
|
|
|
# compiler/linker, i.e., one that searches /usr/lib and so on.)
|
|
|
|
#
|
|
|
|
# Unfortunately, setting -B appears to override the default search
|
|
|
|
# path. Thus, the gcc-specific "../includes-fixed" directory is
|
|
|
|
# now longer searched and glibc's <limits.h> header fails to
|
|
|
|
# compile, because it uses "#include_next <limits.h>" to find the
|
|
|
|
# limits.h file in ../includes-fixed. To remedy the problem,
|
|
|
|
# another -idirafter is necessary to add that directory again.
|
2016-01-02 11:14:09 +01:00
|
|
|
echo "-B${libc_lib}/lib/ -idirafter ${libc_dev}/include -idirafter ${cc}/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
|
2014-10-10 13:49:26 +02:00
|
|
|
|
2015-04-18 15:46:00 +02:00
|
|
|
echo "-L${libc_lib}/lib" > $out/nix-support/libc-ldflags
|
2014-10-10 13:49:26 +02:00
|
|
|
|
2015-04-18 15:46:00 +02:00
|
|
|
echo "${libc_lib}" > $out/nix-support/orig-libc
|
2016-06-01 22:01:24 +02:00
|
|
|
echo "${libc_dev}" > $out/nix-support/orig-libc-dev
|
2014-10-10 13:49:26 +02:00
|
|
|
''
|
|
|
|
|
|
|
|
+ (if nativeTools then ''
|
2017-05-21 20:51:02 +02:00
|
|
|
ccPath="${if targetPlatform.isDarwin then cc else nativePrefix}/bin"
|
2014-10-10 13:49:26 +02:00
|
|
|
ldPath="${nativePrefix}/bin"
|
|
|
|
'' else ''
|
2015-01-09 20:22:12 +01:00
|
|
|
echo $cc > $out/nix-support/orig-cc
|
2014-10-10 13:49:26 +02:00
|
|
|
|
2016-01-02 11:14:09 +01:00
|
|
|
# GCC shows ${cc_solib}/lib in `gcc -print-search-dirs', but not
|
|
|
|
# ${cc_solib}/lib64 (even though it does actually search there...)..
|
2014-10-10 13:49:26 +02:00
|
|
|
# This confuses libtool. So add it to the compiler tool search
|
|
|
|
# path explicitly.
|
2016-01-02 11:14:09 +01:00
|
|
|
if [ -e "${cc_solib}/lib64" -a ! -L "${cc_solib}/lib64" ]; then
|
2015-10-25 11:33:39 +01:00
|
|
|
ccLDFlags+=" -L${cc_solib}/lib64"
|
2016-01-02 11:14:09 +01:00
|
|
|
ccCFlags+=" -B${cc_solib}/lib64"
|
2014-10-10 13:49:26 +02:00
|
|
|
fi
|
2015-10-25 11:33:39 +01:00
|
|
|
ccLDFlags+=" -L${cc_solib}/lib"
|
2016-05-04 14:23:54 +02:00
|
|
|
ccCFlags+=" -B${cc_solib}/lib"
|
2014-10-10 13:49:26 +02:00
|
|
|
|
2015-01-09 20:22:12 +01:00
|
|
|
${optionalString cc.langVhdl or false ''
|
2015-10-25 11:33:39 +01:00
|
|
|
ccLDFlags+=" -L${zlib.out}/lib"
|
2014-10-10 13:49:26 +02:00
|
|
|
''}
|
|
|
|
|
|
|
|
# Find the gcc libraries path (may work only without multilib).
|
2015-01-09 20:22:12 +01:00
|
|
|
${optionalString cc.langAda or false ''
|
2016-01-02 11:14:09 +01:00
|
|
|
basePath=`echo ${cc_solib}/lib/*/*/*`
|
2015-01-09 20:22:12 +01:00
|
|
|
ccCFlags+=" -B$basePath -I$basePath/adainclude"
|
2014-10-10 13:49:26 +02:00
|
|
|
gnatCFlags="-aI$basePath/adainclude -aO$basePath/adalib"
|
|
|
|
echo "$gnatCFlags" > $out/nix-support/gnat-cflags
|
|
|
|
''}
|
|
|
|
|
2015-01-09 20:22:12 +01:00
|
|
|
if [ -e $ccPath/clang ]; then
|
|
|
|
# Need files like crtbegin.o from gcc
|
|
|
|
# It's unclear if these will ever be provided by an LLVM project
|
|
|
|
ccCFlags="$ccCFlags -B$basePath"
|
|
|
|
ccCFlags="$ccCFlags -isystem$cc/lib/clang/$ccVersion/include"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$ccLDFlags" > $out/nix-support/cc-ldflags
|
|
|
|
echo "$ccCFlags" > $out/nix-support/cc-cflags
|
2014-10-10 13:49:26 +02:00
|
|
|
|
2016-01-02 11:14:09 +01:00
|
|
|
ccPath="${cc}/bin"
|
2015-04-18 11:00:58 +02:00
|
|
|
ldPath="${binutils_bin}/bin"
|
2014-10-10 13:49:26 +02:00
|
|
|
|
2015-01-09 20:22:12 +01:00
|
|
|
# Propagate the wrapped cc so that if you install the wrapper,
|
2014-10-10 13:49:26 +02:00
|
|
|
# you get tools like gcov, the manpages, etc. as well (including
|
|
|
|
# for binutils and Glibc).
|
2017-05-23 02:59:39 +02:00
|
|
|
echo ${cc} ${cc.man or ""} ${binutils_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages
|
2014-10-10 15:48:34 +02:00
|
|
|
|
|
|
|
echo ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs
|
2014-10-10 13:49:26 +02:00
|
|
|
''
|
|
|
|
|
2017-05-21 20:51:02 +02:00
|
|
|
+ optionalString (targetPlatform.isSunOS && nativePrefix != "") ''
|
2014-10-10 13:49:26 +02:00
|
|
|
# Solaris needs an additional ld wrapper.
|
|
|
|
ldPath="${nativePrefix}/bin"
|
2017-02-14 00:01:04 +01:00
|
|
|
exec="$ldPath/${prefix}ld"
|
2017-05-23 03:00:21 +02:00
|
|
|
wrap ld-solaris ${preWrap ./ld-solaris-wrapper.sh}
|
2014-10-10 13:49:26 +02:00
|
|
|
'')
|
|
|
|
|
|
|
|
+ ''
|
|
|
|
# Create a symlink to as (the assembler). This is useful when a
|
2015-01-09 20:22:12 +01:00
|
|
|
# cc-wrapper is installed in a user environment, as it ensures that
|
2014-10-10 13:49:26 +02:00
|
|
|
# the right assembler is called.
|
2017-02-14 00:01:04 +01:00
|
|
|
if [ -e $ldPath/${prefix}as ]; then
|
|
|
|
ln -s $ldPath/${prefix}as $out/bin/${prefix}as
|
2014-10-10 13:49:26 +02:00
|
|
|
fi
|
|
|
|
|
2017-05-23 03:00:21 +02:00
|
|
|
wrap ${prefix}ld ${preWrap ./ld-wrapper.sh} ''${ld:-$ldPath/${prefix}ld}
|
2014-10-10 13:49:26 +02:00
|
|
|
|
2017-02-14 00:01:04 +01:00
|
|
|
if [ -e ${binutils_bin}/bin/${prefix}ld.gold ]; then
|
2017-05-23 03:00:21 +02:00
|
|
|
wrap ${prefix}ld.gold ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold
|
2014-10-10 14:01:38 +02:00
|
|
|
fi
|
|
|
|
|
2015-04-18 11:00:58 +02:00
|
|
|
if [ -e ${binutils_bin}/bin/ld.bfd ]; then
|
2017-05-23 03:00:21 +02:00
|
|
|
wrap ${prefix}ld.bfd ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd
|
2014-10-10 14:01:38 +02:00
|
|
|
fi
|
|
|
|
|
2017-02-14 00:01:04 +01:00
|
|
|
export real_cc=${prefix}cc
|
|
|
|
export real_cxx=${prefix}c++
|
2017-06-08 20:00:40 +02:00
|
|
|
export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}"
|
2015-03-06 20:04:43 +01:00
|
|
|
|
2017-02-14 00:01:04 +01:00
|
|
|
if [ -e $ccPath/${prefix}gcc ]; then
|
2017-05-23 03:00:21 +02:00
|
|
|
wrap ${prefix}gcc ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcc
|
2017-02-14 00:01:04 +01:00
|
|
|
ln -s ${prefix}gcc $out/bin/${prefix}cc
|
|
|
|
export real_cc=${prefix}gcc
|
|
|
|
export real_cxx=${prefix}g++
|
2015-01-09 20:22:12 +01:00
|
|
|
elif [ -e $ccPath/clang ]; then
|
2017-05-23 03:00:21 +02:00
|
|
|
wrap ${prefix}clang ${preWrap ./cc-wrapper.sh} $ccPath/clang
|
2017-02-14 00:01:04 +01:00
|
|
|
ln -s ${prefix}clang $out/bin/${prefix}cc
|
2015-01-16 16:50:53 +01:00
|
|
|
export real_cc=clang
|
|
|
|
export real_cxx=clang++
|
2014-10-10 13:49:26 +02:00
|
|
|
fi
|
|
|
|
|
2017-02-14 00:01:04 +01:00
|
|
|
if [ -e $ccPath/${prefix}g++ ]; then
|
2017-05-23 03:00:21 +02:00
|
|
|
wrap ${prefix}g++ ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}g++
|
2017-02-14 00:01:04 +01:00
|
|
|
ln -s ${prefix}g++ $out/bin/${prefix}c++
|
2015-01-09 20:22:12 +01:00
|
|
|
elif [ -e $ccPath/clang++ ]; then
|
2017-05-23 03:00:21 +02:00
|
|
|
wrap ${prefix}clang++ ${preWrap ./cc-wrapper.sh} $ccPath/clang++
|
2017-02-14 00:01:04 +01:00
|
|
|
ln -s ${prefix}clang++ $out/bin/${prefix}c++
|
2014-10-10 15:48:34 +02:00
|
|
|
fi
|
|
|
|
|
2015-01-09 20:22:12 +01:00
|
|
|
if [ -e $ccPath/cpp ]; then
|
2017-05-23 03:00:21 +02:00
|
|
|
wrap ${prefix}cpp ${preWrap ./cc-wrapper.sh} $ccPath/cpp
|
2014-10-10 13:49:26 +02:00
|
|
|
fi
|
|
|
|
''
|
|
|
|
|
2015-01-09 20:22:12 +01:00
|
|
|
+ optionalString cc.langFortran or false ''
|
2017-05-23 03:00:21 +02:00
|
|
|
wrap ${prefix}gfortran ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gfortran
|
2017-02-14 00:01:04 +01:00
|
|
|
ln -sv ${prefix}gfortran $out/bin/${prefix}g77
|
|
|
|
ln -sv ${prefix}gfortran $out/bin/${prefix}f77
|
2014-10-10 13:49:26 +02:00
|
|
|
''
|
|
|
|
|
2015-01-09 20:22:12 +01:00
|
|
|
+ optionalString cc.langJava or false ''
|
2017-05-23 03:00:21 +02:00
|
|
|
wrap ${prefix}gcj ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gcj
|
2014-10-10 13:49:26 +02:00
|
|
|
''
|
|
|
|
|
2015-01-09 20:22:12 +01:00
|
|
|
+ optionalString cc.langGo or false ''
|
2017-05-23 03:00:21 +02:00
|
|
|
wrap ${prefix}gccgo ${preWrap ./cc-wrapper.sh} $ccPath/${prefix}gccgo
|
2014-10-10 13:49:26 +02:00
|
|
|
''
|
|
|
|
|
2015-01-09 20:22:12 +01:00
|
|
|
+ optionalString cc.langAda or false ''
|
2017-05-23 03:00:21 +02:00
|
|
|
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
|
2014-10-10 13:49:26 +02:00
|
|
|
''
|
|
|
|
|
2015-01-09 20:22:12 +01:00
|
|
|
+ optionalString cc.langVhdl or false ''
|
2017-02-14 00:01:04 +01:00
|
|
|
ln -s $ccPath/${prefix}ghdl $out/bin/${prefix}ghdl
|
2014-10-10 13:49:26 +02:00
|
|
|
''
|
|
|
|
|
|
|
|
+ ''
|
2017-05-23 03:00:21 +02:00
|
|
|
substituteAll ${preWrap ./setup-hook.sh} $out/nix-support/setup-hook.tmp
|
2015-02-08 19:36:13 +01:00
|
|
|
cat $out/nix-support/setup-hook.tmp >> $out/nix-support/setup-hook
|
|
|
|
rm $out/nix-support/setup-hook.tmp
|
|
|
|
|
2016-08-24 10:59:52 +02:00
|
|
|
# some linkers on some platforms don't support specific -z flags
|
|
|
|
hardening_unsupported_flags=""
|
2017-02-14 00:01:04 +01:00
|
|
|
if [[ "$($ldPath/${prefix}ld -z now 2>&1 || true)" =~ un(recognized|known)\ option ]]; then
|
2016-08-24 10:59:52 +02:00
|
|
|
hardening_unsupported_flags+=" bindnow"
|
|
|
|
fi
|
2017-02-14 00:01:04 +01:00
|
|
|
if [[ "$($ldPath/${prefix}ld -z relro 2>&1 || true)" =~ un(recognized|known)\ option ]]; then
|
2016-08-24 10:59:52 +02:00
|
|
|
hardening_unsupported_flags+=" relro"
|
|
|
|
fi
|
2016-08-23 18:13:31 +02:00
|
|
|
|
2017-05-23 03:00:21 +02:00
|
|
|
substituteAll ${preWrap ./add-flags.sh} $out/nix-support/add-flags.sh
|
|
|
|
substituteAll ${preWrap ./add-hardening.sh} $out/nix-support/add-hardening.sh
|
|
|
|
cp -p ${preWrap ./utils.sh} $out/nix-support/utils.sh
|
2015-07-20 13:42:30 +02:00
|
|
|
''
|
|
|
|
+ extraBuildCommands;
|
2014-10-10 13:49:26 +02:00
|
|
|
|
|
|
|
# The dynamic linker has different names on different Linux platforms.
|
2017-05-23 02:59:39 +02:00
|
|
|
#
|
|
|
|
# TODO(1b62c9c06173f4d5e6b090e5ae0c68fa5f478faf): This is not the best way to
|
|
|
|
# do this. I think the reference should be the style in the gcc-cross-wrapper,
|
|
|
|
# but to keep a stable stdenv now I do this sufficient if/else.
|
2014-10-10 13:49:26 +02:00
|
|
|
dynamicLinker =
|
|
|
|
if !nativeLibc then
|
2017-05-23 02:59:39 +02:00
|
|
|
(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
|
2014-10-10 13:49:26 +02:00
|
|
|
# ARM with a wildcard, which can be "" or "-armhf".
|
2017-05-23 02:59:39 +02:00
|
|
|
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
|
2014-10-10 13:49:26 +02:00
|
|
|
abort "Don't know the name of the dynamic linker for this platform.")
|
|
|
|
else "";
|
2010-12-04 22:45:37 +01:00
|
|
|
|
|
|
|
crossAttrs = {
|
2012-12-28 19:08:19 +01:00
|
|
|
shell = shell.crossDrv + shell.crossDrv.shellPath;
|
2014-12-17 19:11:30 +01:00
|
|
|
libc = stdenv.ccCross.libc;
|
2010-12-04 22:45:37 +01:00
|
|
|
};
|
2014-02-04 16:58:12 +01:00
|
|
|
|
2009-03-25 19:34:27 +01:00
|
|
|
meta =
|
2015-01-09 20:22:12 +01:00
|
|
|
let cc_ = if cc != null then cc else {}; in
|
|
|
|
(if cc_ ? meta then removeAttrs cc.meta ["priority"] else {}) //
|
2009-04-19 18:00:46 +02:00
|
|
|
{ description =
|
2015-01-09 20:22:12 +01:00
|
|
|
stdenv.lib.attrByPath ["meta" "description"] "System C compiler" cc_
|
2009-04-19 18:00:46 +02:00
|
|
|
+ " (wrapper script)";
|
|
|
|
};
|
2008-06-26 13:07:46 +02:00
|
|
|
}
|