2015-01-09 19:22:12 +00:00
|
|
|
|
# The Nixpkgs CC is not directly usable, since it doesn't know where
|
2014-10-10 12:49:26 +01: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 12:07:46 +01:00
|
|
|
|
|
2018-02-01 00:00:00 +00:00
|
|
|
|
{ name ? ""
|
2018-09-05 19:33:56 +01:00
|
|
|
|
, stdenvNoCC
|
2017-08-26 16:43:30 +01:00
|
|
|
|
, cc ? null, libc ? null, bintools, coreutils ? null, shell ? stdenvNoCC.shell
|
2018-09-05 19:33:56 +01:00
|
|
|
|
, nativeTools, noLibc ? false, nativeLibc, nativePrefix ? ""
|
|
|
|
|
, propagateDoc ? cc != null && cc ? man
|
2020-03-18 15:28:52 +00:00
|
|
|
|
, extraTools ? [], extraPackages ? [], extraBuildCommands ? ""
|
2018-05-24 22:43:31 +01:00
|
|
|
|
, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null
|
2017-08-21 23:26:08 +01:00
|
|
|
|
, buildPackages ? {}
|
2019-01-26 15:17:57 +00:00
|
|
|
|
, libcxx ? null
|
2008-06-26 12:07:46 +01:00
|
|
|
|
}:
|
|
|
|
|
|
2017-09-20 16:07:52 +01:00
|
|
|
|
with stdenvNoCC.lib;
|
2014-10-10 12:49:26 +01:00
|
|
|
|
|
2018-02-01 00:00:00 +00:00
|
|
|
|
assert nativeTools -> !propagateDoc && nativePrefix != "";
|
2015-12-17 22:02:40 +00:00
|
|
|
|
assert !nativeTools ->
|
2017-08-26 16:43:30 +01:00
|
|
|
|
cc != null && coreutils != null && gnugrep != null;
|
2017-05-23 01:59:39 +01:00
|
|
|
|
assert !(nativeLibc && noLibc);
|
|
|
|
|
assert (noLibc || nativeLibc) == (libc == null);
|
2008-06-26 12:07:46 +01:00
|
|
|
|
|
2009-04-09 16:24:33 +01:00
|
|
|
|
let
|
2017-09-20 16:07:52 +01:00
|
|
|
|
stdenv = stdenvNoCC;
|
2017-07-06 02:47:48 +01:00
|
|
|
|
inherit (stdenv) hostPlatform targetPlatform;
|
|
|
|
|
|
2017-02-13 23:01:04 +00:00
|
|
|
|
# Prefix for binaries. Customarily ends with a dash separator.
|
|
|
|
|
#
|
|
|
|
|
# TODO(@Ericson2314) Make unconditional, or optional but always true by
|
|
|
|
|
# default.
|
2017-11-25 18:43:57 +00:00
|
|
|
|
targetPrefix = stdenv.lib.optionalString (targetPlatform != hostPlatform)
|
|
|
|
|
(targetPlatform.config + "-");
|
2009-04-09 16:24:33 +01:00
|
|
|
|
|
2019-08-14 14:52:15 +01:00
|
|
|
|
ccVersion = stdenv.lib.getVersion cc;
|
|
|
|
|
ccName = stdenv.lib.removePrefix targetPrefix (stdenv.lib.getName cc);
|
2012-08-03 18:23:51 +01:00
|
|
|
|
|
2017-05-23 01:59:39 +01: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;
|
2019-08-12 23:59:01 +01:00
|
|
|
|
cc_solib = getLib cc
|
|
|
|
|
+ optionalString (targetPlatform != hostPlatform) "/${targetPlatform.config}";
|
|
|
|
|
|
2016-02-03 15:54:03 +00:00
|
|
|
|
# The wrapper scripts use 'cat' and 'grep', so we may need coreutils.
|
2016-04-14 17:00:39 +01:00
|
|
|
|
coreutils_bin = if nativeTools then "" else getBin coreutils;
|
2017-06-08 19:00:40 +01:00
|
|
|
|
|
2019-04-12 01:51:48 +01:00
|
|
|
|
default_cxx_stdlib_compile = if (targetPlatform.isLinux && !(cc.isGNU or false) && !nativeTools && cc ? gcc) && !(targetPlatform.useLLVM or false) then
|
2019-01-26 15:17:57 +00:00
|
|
|
|
"-isystem $(echo -n ${cc.gcc}/include/c++/*) -isystem $(echo -n ${cc.gcc}/include/c++/*)/$(${cc.gcc}/bin/gcc -dumpmachine)"
|
2019-04-12 01:51:48 +01:00
|
|
|
|
else if targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false) && !(targetPlatform.useLLVM or false) then
|
2019-01-26 15:17:57 +00:00
|
|
|
|
"-isystem ${libcxx}/include/c++/v1"
|
|
|
|
|
else "";
|
2017-05-23 01:59:39 +01:00
|
|
|
|
|
2017-06-26 05:43:06 +01:00
|
|
|
|
# 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.
|
2018-07-27 01:16:28 +01:00
|
|
|
|
infixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config;
|
2017-06-19 16:10:27 +01:00
|
|
|
|
|
2017-08-23 21:23:30 +01:00
|
|
|
|
expand-response-params =
|
stdenv: Introduce hasCC attribute
Before, we'd always use `cc = null`, and check for that. The problem is
this breaks for cross compilation to platforms that don't support a C
compiler.
It's a very subtle issue. One might think there is no problem because we
have `stdenvNoCC`, and presumably one would only build derivations that
use that. The problem is that one still wants to use tools at build-time
that are themselves built with a C compiler, and those are gotten via
"splicing". The runtime version of those deps will explode, but the
build time / `buildPackages` versions of those deps will be fine, and
splicing attempts to work this by using `builtins.tryEval` to filter out
any broken "higher priority" packages (runtime is the default and
highest priority) so that both `foo` and `foo.nativeDrv` works.
However, `tryEval` only catches certain evaluation failures (e.g.
exceptions), and not arbitrary failures (such as `cc.attr` when `cc` is
null). This means `tryEval` fails to let us use our build time deps, and
everything comes apart.
The right solution is, as usually, to get rid of splicing. Or, baring
that, to make it so `foo` never works and one has to explicitly do
`foo.*`. But that is a much larger change, and certaily one unsuitable
to be backported to stable.
Given that, we instead make an exception-throwing `cc` attribute, and
create a `hasCC` attribute for those derivations which wish to
condtionally use a C compiler: instead of doing `stdenv.cc or null ==
null` or something similar, one does `stdenv.hasCC`. This allows quering
without "tripping" the exception, while also allowing `tryEval` to work.
No platform without a C compiler is yet wired up by default. That will
be done in a following commit.
2019-11-24 23:07:20 +00:00
|
|
|
|
if buildPackages.stdenv.hasCC && buildPackages.stdenv.cc != "/dev/null"
|
2017-08-23 21:23:30 +01:00
|
|
|
|
then import ../expand-response-params { inherit (buildPackages) stdenv; }
|
|
|
|
|
else "";
|
2017-06-29 17:06:55 +01:00
|
|
|
|
|
2019-04-21 17:13:37 +01:00
|
|
|
|
# older compilers (for example bootstrap's GCC 5) fail with -march=too-modern-cpu
|
|
|
|
|
isGccArchSupported = arch:
|
|
|
|
|
if cc.isGNU or false then
|
|
|
|
|
{ skylake = versionAtLeast ccVersion "6.0";
|
|
|
|
|
skylake-avx512 = versionAtLeast ccVersion "6.0";
|
|
|
|
|
cannonlake = versionAtLeast ccVersion "8.0";
|
|
|
|
|
icelake-client = versionAtLeast ccVersion "8.0";
|
|
|
|
|
icelake-server = versionAtLeast ccVersion "8.0";
|
|
|
|
|
knm = versionAtLeast ccVersion "8.0";
|
|
|
|
|
}.${arch} or true
|
|
|
|
|
else if cc.isClang or false then
|
|
|
|
|
{ cannonlake = versionAtLeast ccVersion "5.0";
|
|
|
|
|
icelake-client = versionAtLeast ccVersion "7.0";
|
|
|
|
|
icelake-server = versionAtLeast ccVersion "7.0";
|
|
|
|
|
knm = versionAtLeast ccVersion "7.0";
|
|
|
|
|
}.${arch} or true
|
|
|
|
|
else
|
|
|
|
|
false;
|
|
|
|
|
|
2009-04-09 16:24:33 +01:00
|
|
|
|
in
|
2009-03-25 17:34:38 +00:00
|
|
|
|
|
2017-08-28 19:56:08 +01:00
|
|
|
|
# Ensure bintools matches
|
|
|
|
|
assert libc_bin == bintools.libc_bin;
|
|
|
|
|
assert libc_dev == bintools.libc_dev;
|
|
|
|
|
assert libc_lib == bintools.libc_lib;
|
|
|
|
|
assert nativeTools == bintools.nativeTools;
|
|
|
|
|
assert nativeLibc == bintools.nativeLibc;
|
|
|
|
|
assert nativePrefix == bintools.nativePrefix;
|
|
|
|
|
|
2012-12-29 14:11:32 +00:00
|
|
|
|
stdenv.mkDerivation {
|
2019-06-24 01:42:48 +01:00
|
|
|
|
pname = targetPrefix
|
|
|
|
|
+ (if name != "" then name else "${ccName}-wrapper");
|
|
|
|
|
version = if cc == null then null else ccVersion;
|
2014-02-04 15:58:12 +00:00
|
|
|
|
|
2014-10-10 12:49:26 +01:00
|
|
|
|
preferLocalBuild = true;
|
|
|
|
|
|
2017-08-28 19:56:08 +01:00
|
|
|
|
inherit cc libc_bin libc_dev libc_lib bintools coreutils_bin;
|
2018-09-04 22:13:00 +01:00
|
|
|
|
shell = getBin shell + shell.shellPath or "";
|
2016-02-01 13:42:33 +00:00
|
|
|
|
gnugrep_bin = if nativeTools then "" else gnugrep;
|
2014-02-04 15:58:12 +00:00
|
|
|
|
|
2017-11-25 18:43:57 +00:00
|
|
|
|
inherit targetPrefix infixSalt;
|
2017-06-08 19:00:40 +01:00
|
|
|
|
|
2018-02-01 00:00:00 +00:00
|
|
|
|
outputs = [ "out" ] ++ optionals propagateDoc [ "man" "info" ];
|
2017-06-08 19:00:40 +01:00
|
|
|
|
|
2016-10-07 15:31:37 +01:00
|
|
|
|
passthru = {
|
2017-10-11 00:01:42 +01:00
|
|
|
|
# "cc" is the generic name for a C compiler, but there is no one for package
|
|
|
|
|
# providing the linker and related tools. The two we use now are GNU
|
2017-08-28 19:56:08 +01:00
|
|
|
|
# Binutils, and Apple's "cctools"; "bintools" as an attempt to find an
|
2017-10-11 00:01:42 +01:00
|
|
|
|
# unused middle-ground name that evokes both.
|
2017-08-28 19:56:08 +01:00
|
|
|
|
inherit bintools;
|
2018-05-24 22:43:31 +01:00
|
|
|
|
inherit libc nativeTools nativeLibc nativePrefix isGNU isClang default_cxx_stdlib_compile;
|
2016-10-07 15:31:37 +01:00
|
|
|
|
|
|
|
|
|
emacsBufferSetup = pkgs: ''
|
|
|
|
|
; We should handle propagation here too
|
2017-08-28 19:56:08 +01:00
|
|
|
|
(mapc
|
|
|
|
|
(lambda (arg)
|
|
|
|
|
(when (file-directory-p (concat arg "/include"))
|
|
|
|
|
(setenv "NIX_${infixSalt}_CFLAGS_COMPILE" (concat (getenv "NIX_${infixSalt}_CFLAGS_COMPILE") " -isystem " arg "/include"))))
|
|
|
|
|
'(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)}))
|
2016-10-07 15:31:37 +01:00
|
|
|
|
'';
|
|
|
|
|
};
|
2014-10-10 12:49:26 +01:00
|
|
|
|
|
2017-08-23 21:55:55 +01:00
|
|
|
|
dontBuild = true;
|
|
|
|
|
dontConfigure = true;
|
|
|
|
|
|
|
|
|
|
unpackPhase = ''
|
|
|
|
|
src=$PWD
|
|
|
|
|
'';
|
|
|
|
|
|
2019-11-27 19:15:56 +00:00
|
|
|
|
wrapper = ./cc-wrapper.sh;
|
|
|
|
|
|
2017-08-23 21:55:55 +01:00
|
|
|
|
installPhase =
|
2014-10-10 12:49:26 +01:00
|
|
|
|
''
|
2018-02-01 00:00:00 +00:00
|
|
|
|
mkdir -p $out/bin $out/nix-support
|
2014-10-10 12:49:26 +01:00
|
|
|
|
|
|
|
|
|
wrap() {
|
|
|
|
|
local dst="$1"
|
|
|
|
|
local wrapper="$2"
|
|
|
|
|
export prog="$3"
|
|
|
|
|
substituteAll "$wrapper" "$out/bin/$dst"
|
|
|
|
|
chmod +x "$out/bin/$dst"
|
|
|
|
|
}
|
|
|
|
|
''
|
|
|
|
|
|
|
|
|
|
+ (if nativeTools then ''
|
2017-08-23 21:55:55 +01:00
|
|
|
|
echo ${if targetPlatform.isDarwin then cc else nativePrefix} > $out/nix-support/orig-cc
|
|
|
|
|
|
2017-05-21 19:51:02 +01:00
|
|
|
|
ccPath="${if targetPlatform.isDarwin then cc else nativePrefix}/bin"
|
2014-10-10 12:49:26 +01:00
|
|
|
|
'' else ''
|
2015-01-09 19:22:12 +00:00
|
|
|
|
echo $cc > $out/nix-support/orig-cc
|
2014-10-10 12:49:26 +01:00
|
|
|
|
|
2016-01-02 10:14:09 +00:00
|
|
|
|
ccPath="${cc}/bin"
|
2014-10-10 12:49:26 +01:00
|
|
|
|
'')
|
|
|
|
|
|
|
|
|
|
+ ''
|
2017-08-28 19:56:08 +01:00
|
|
|
|
# Create symlinks to everything in the bintools wrapper.
|
|
|
|
|
for bbin in $bintools/bin/*; do
|
|
|
|
|
mkdir -p "$out/bin"
|
|
|
|
|
ln -s "$bbin" "$out/bin/$(basename $bbin)"
|
|
|
|
|
done
|
2014-10-10 13:01:38 +01:00
|
|
|
|
|
2017-06-26 06:17:09 +01:00
|
|
|
|
# We export environment variables pointing to the wrapped nonstandard
|
|
|
|
|
# cmds, lest some lousy configure script use those to guess compiler
|
|
|
|
|
# version.
|
2017-11-25 18:43:57 +00:00
|
|
|
|
export named_cc=${targetPrefix}cc
|
|
|
|
|
export named_cxx=${targetPrefix}c++
|
2017-06-26 06:17:09 +01:00
|
|
|
|
|
2017-06-08 19:00:40 +01:00
|
|
|
|
export default_cxx_stdlib_compile="${default_cxx_stdlib_compile}"
|
2015-03-06 19:04:43 +00:00
|
|
|
|
|
2017-11-25 18:43:57 +00:00
|
|
|
|
if [ -e $ccPath/${targetPrefix}gcc ]; then
|
2019-11-27 19:15:56 +00:00
|
|
|
|
wrap ${targetPrefix}gcc $wrapper $ccPath/${targetPrefix}gcc
|
2017-11-25 18:43:57 +00:00
|
|
|
|
ln -s ${targetPrefix}gcc $out/bin/${targetPrefix}cc
|
|
|
|
|
export named_cc=${targetPrefix}gcc
|
|
|
|
|
export named_cxx=${targetPrefix}g++
|
2015-01-09 19:22:12 +00:00
|
|
|
|
elif [ -e $ccPath/clang ]; then
|
2019-11-27 19:15:56 +00:00
|
|
|
|
wrap ${targetPrefix}clang $wrapper $ccPath/clang
|
2017-11-25 18:43:57 +00:00
|
|
|
|
ln -s ${targetPrefix}clang $out/bin/${targetPrefix}cc
|
|
|
|
|
export named_cc=${targetPrefix}clang
|
|
|
|
|
export named_cxx=${targetPrefix}clang++
|
2014-10-10 12:49:26 +01:00
|
|
|
|
fi
|
|
|
|
|
|
2017-11-25 18:43:57 +00:00
|
|
|
|
if [ -e $ccPath/${targetPrefix}g++ ]; then
|
2019-11-27 19:15:56 +00:00
|
|
|
|
wrap ${targetPrefix}g++ $wrapper $ccPath/${targetPrefix}g++
|
2017-11-25 18:43:57 +00:00
|
|
|
|
ln -s ${targetPrefix}g++ $out/bin/${targetPrefix}c++
|
2015-01-09 19:22:12 +00:00
|
|
|
|
elif [ -e $ccPath/clang++ ]; then
|
2019-11-27 19:15:56 +00:00
|
|
|
|
wrap ${targetPrefix}clang++ $wrapper $ccPath/clang++
|
2017-11-25 18:43:57 +00:00
|
|
|
|
ln -s ${targetPrefix}clang++ $out/bin/${targetPrefix}c++
|
2014-10-10 14:48:34 +01:00
|
|
|
|
fi
|
|
|
|
|
|
2015-01-09 19:22:12 +00:00
|
|
|
|
if [ -e $ccPath/cpp ]; then
|
2019-11-27 19:15:56 +00:00
|
|
|
|
wrap ${targetPrefix}cpp $wrapper $ccPath/cpp
|
2014-10-10 12:49:26 +01:00
|
|
|
|
fi
|
|
|
|
|
''
|
|
|
|
|
|
2015-01-09 19:22:12 +00:00
|
|
|
|
+ optionalString cc.langFortran or false ''
|
2019-11-27 19:15:56 +00:00
|
|
|
|
wrap ${targetPrefix}gfortran $wrapper $ccPath/${targetPrefix}gfortran
|
2017-11-25 18:43:57 +00:00
|
|
|
|
ln -sv ${targetPrefix}gfortran $out/bin/${targetPrefix}g77
|
|
|
|
|
ln -sv ${targetPrefix}gfortran $out/bin/${targetPrefix}f77
|
2014-10-10 12:49:26 +01:00
|
|
|
|
''
|
|
|
|
|
|
2015-01-09 19:22:12 +00:00
|
|
|
|
+ optionalString cc.langJava or false ''
|
2019-11-27 19:15:56 +00:00
|
|
|
|
wrap ${targetPrefix}gcj $wrapper $ccPath/${targetPrefix}gcj
|
2014-10-10 12:49:26 +01:00
|
|
|
|
''
|
|
|
|
|
|
2015-01-09 19:22:12 +00:00
|
|
|
|
+ optionalString cc.langGo or false ''
|
2019-11-27 19:15:56 +00:00
|
|
|
|
wrap ${targetPrefix}gccgo $wrapper $ccPath/${targetPrefix}gccgo
|
2017-08-23 21:55:55 +01:00
|
|
|
|
'';
|
|
|
|
|
|
2018-05-13 16:31:24 +01:00
|
|
|
|
strictDeps = true;
|
2020-03-18 15:28:52 +00:00
|
|
|
|
propagatedBuildInputs = [ bintools ] ++ extraTools;
|
2017-07-07 20:57:01 +01:00
|
|
|
|
depsTargetTargetPropagated = extraPackages;
|
2017-08-23 21:55:55 +01:00
|
|
|
|
|
2018-05-07 18:07:19 +01:00
|
|
|
|
wrapperName = "CC_WRAPPER";
|
|
|
|
|
|
|
|
|
|
setupHooks = [
|
|
|
|
|
../setup-hooks/role.bash
|
|
|
|
|
./setup-hook.sh
|
|
|
|
|
];
|
2017-08-23 21:55:55 +01:00
|
|
|
|
|
|
|
|
|
postFixup =
|
|
|
|
|
''
|
2017-08-28 19:56:08 +01:00
|
|
|
|
# Backwards compatability for packages expecting this file, e.g. with
|
|
|
|
|
# `$NIX_CC/nix-support/dynamic-linker`.
|
|
|
|
|
#
|
|
|
|
|
# TODO(@Ericson2314): Remove this after stable release and force
|
|
|
|
|
# everyone to refer to bintools-wrapper directly.
|
|
|
|
|
if [[ -f "$bintools/nix-support/dynamic-linker" ]]; then
|
|
|
|
|
ln -s "$bintools/nix-support/dynamic-linker" "$out/nix-support"
|
|
|
|
|
fi
|
|
|
|
|
if [[ -f "$bintools/nix-support/dynamic-linker-m32" ]]; then
|
|
|
|
|
ln -s "$bintools/nix-support/dynamic-linker-m32" "$out/nix-support"
|
|
|
|
|
fi
|
2017-08-23 21:55:55 +01:00
|
|
|
|
''
|
|
|
|
|
|
2019-11-26 00:55:16 +00:00
|
|
|
|
+ optionalString (libc != null) (''
|
2017-08-23 21:55:55 +01:00
|
|
|
|
##
|
|
|
|
|
## General libc support
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
# The "-B${libc_lib}/lib/" flag is a quick hack to force gcc to link
|
|
|
|
|
# against the crt1.o from our own glibc, rather than the one in
|
|
|
|
|
# /usr/lib. (This is only an issue when using an `impure'
|
|
|
|
|
# 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.
|
2019-11-26 00:55:16 +00:00
|
|
|
|
echo "-B${libc_lib}${libc.libdir or "/lib/"}" >> $out/nix-support/libc-cflags
|
|
|
|
|
echo "-idirafter ${libc_dev}${libc.incdir or "/include"}" >> $out/nix-support/libc-cflags
|
|
|
|
|
'' + optionalString isGNU ''
|
|
|
|
|
for dir in "${cc}"/lib/gcc/*/*/include-fixed; do
|
|
|
|
|
echo '-idirafter' ''${dir} >> $out/nix-support/libc-cflags
|
|
|
|
|
done
|
|
|
|
|
'' + ''
|
2017-08-23 21:55:55 +01:00
|
|
|
|
|
|
|
|
|
echo "${libc_lib}" > $out/nix-support/orig-libc
|
|
|
|
|
echo "${libc_dev}" > $out/nix-support/orig-libc-dev
|
2019-11-26 00:55:16 +00:00
|
|
|
|
'')
|
2017-08-23 21:55:55 +01:00
|
|
|
|
|
|
|
|
|
+ optionalString (!nativeTools) ''
|
|
|
|
|
##
|
|
|
|
|
## Initial CFLAGS
|
|
|
|
|
##
|
|
|
|
|
|
|
|
|
|
# GCC shows ${cc_solib}/lib in `gcc -print-search-dirs', but not
|
|
|
|
|
# ${cc_solib}/lib64 (even though it does actually search there...)..
|
|
|
|
|
# This confuses libtool. So add it to the compiler tool search
|
|
|
|
|
# path explicitly.
|
|
|
|
|
if [ -e "${cc_solib}/lib64" -a ! -L "${cc_solib}/lib64" ]; then
|
|
|
|
|
ccLDFlags+=" -L${cc_solib}/lib64"
|
|
|
|
|
ccCFlags+=" -B${cc_solib}/lib64"
|
|
|
|
|
fi
|
|
|
|
|
ccLDFlags+=" -L${cc_solib}/lib"
|
|
|
|
|
ccCFlags+=" -B${cc_solib}/lib"
|
|
|
|
|
|
|
|
|
|
echo "$ccLDFlags" > $out/nix-support/cc-ldflags
|
|
|
|
|
echo "$ccCFlags" > $out/nix-support/cc-cflags
|
2019-01-26 15:17:57 +00:00
|
|
|
|
'' + optionalString (targetPlatform.isDarwin && (libcxx != null) && (cc.isClang or false)) ''
|
|
|
|
|
echo " -L${libcxx}/lib" >> $out/nix-support/cc-ldflags
|
|
|
|
|
'' + optionalString propagateDoc ''
|
2017-08-23 21:55:55 +01:00
|
|
|
|
##
|
2018-02-01 00:00:00 +00:00
|
|
|
|
## Man page and info support
|
2017-08-23 21:55:55 +01:00
|
|
|
|
##
|
|
|
|
|
|
2018-09-05 19:35:16 +01:00
|
|
|
|
ln -s ${cc.man} $man
|
|
|
|
|
ln -s ${cc.info} $info
|
2014-10-10 12:49:26 +01:00
|
|
|
|
''
|
|
|
|
|
|
|
|
|
|
+ ''
|
2017-08-23 21:55:55 +01:00
|
|
|
|
##
|
|
|
|
|
## Hardening support
|
|
|
|
|
##
|
2015-02-08 18:36:13 +00:00
|
|
|
|
|
2017-09-16 22:54:17 +01:00
|
|
|
|
export hardening_unsupported_flags="${builtins.concatStringsSep " " (cc.hardeningUnsupportedFlags or [])}"
|
2017-06-20 19:04:24 +01:00
|
|
|
|
''
|
|
|
|
|
|
2019-04-09 19:21:54 +01:00
|
|
|
|
# Machine flags. These are necessary to support
|
2016-08-23 17:13:31 +01:00
|
|
|
|
|
2019-04-09 19:21:54 +01:00
|
|
|
|
# TODO: We should make a way to support miscellaneous machine
|
|
|
|
|
# flags and other gcc flags as well.
|
|
|
|
|
|
|
|
|
|
# Always add -march based on cpu in triple. Sometimes there is a
|
|
|
|
|
# discrepency (x86_64 vs. x86-64), so we provide an "arch" arg in
|
|
|
|
|
# that case.
|
2019-04-27 03:29:52 +01:00
|
|
|
|
+ optionalString ((targetPlatform ? platform.gcc.arch) &&
|
|
|
|
|
isGccArchSupported targetPlatform.platform.gcc.arch) ''
|
|
|
|
|
echo "-march=${targetPlatform.platform.gcc.arch}" >> $out/nix-support/cc-cflags-before
|
2018-06-24 03:05:26 +01:00
|
|
|
|
''
|
|
|
|
|
|
2019-04-09 19:21:54 +01:00
|
|
|
|
# -mcpu is not very useful. You should use mtune and march
|
|
|
|
|
# instead. It’s provided here for backwards compatibility.
|
|
|
|
|
+ optionalString (targetPlatform ? platform.gcc.cpu) ''
|
|
|
|
|
echo "-mcpu=${targetPlatform.platform.gcc.cpu}" >> $out/nix-support/cc-cflags-before
|
2018-10-15 22:11:20 +01:00
|
|
|
|
''
|
|
|
|
|
|
2019-04-09 19:21:54 +01:00
|
|
|
|
# -mfloat-abi only matters on arm32 but we set it here
|
|
|
|
|
# unconditionally just in case. If the abi specifically sets hard
|
|
|
|
|
# vs. soft floats we use it here.
|
2019-04-24 21:29:45 +01:00
|
|
|
|
+ optionalString (targetPlatform ? platform.gcc.float-abi) ''
|
|
|
|
|
echo "-mfloat-abi=${targetPlatform.platform.gcc.float-abi}" >> $out/nix-support/cc-cflags-before
|
2019-04-09 19:21:54 +01:00
|
|
|
|
''
|
|
|
|
|
+ optionalString (targetPlatform ? platform.gcc.fpu) ''
|
|
|
|
|
echo "-mfpu=${targetPlatform.platform.gcc.fpu}" >> $out/nix-support/cc-cflags-before
|
|
|
|
|
''
|
|
|
|
|
+ optionalString (targetPlatform ? platform.gcc.mode) ''
|
|
|
|
|
echo "-mmode=${targetPlatform.platform.gcc.mode}" >> $out/nix-support/cc-cflags-before
|
|
|
|
|
''
|
2019-04-21 17:13:37 +01:00
|
|
|
|
+ optionalString (targetPlatform ? platform.gcc.tune &&
|
|
|
|
|
isGccArchSupported targetPlatform.platform.gcc.tune) ''
|
2019-04-09 19:21:54 +01:00
|
|
|
|
echo "-mtune=${targetPlatform.platform.gcc.tune}" >> $out/nix-support/cc-cflags-before
|
2018-07-28 17:29:02 +01:00
|
|
|
|
''
|
|
|
|
|
|
2019-04-09 19:21:54 +01:00
|
|
|
|
# TODO: categorize these and figure out a better place for them
|
|
|
|
|
+ optionalString hostPlatform.isCygwin ''
|
|
|
|
|
hardening_unsupported_flags+=" pic"
|
|
|
|
|
'' + optionalString targetPlatform.isMinGW ''
|
|
|
|
|
hardening_unsupported_flags+=" stackprotector"
|
|
|
|
|
'' + optionalString targetPlatform.isAvr ''
|
|
|
|
|
hardening_unsupported_flags+=" stackprotector pic"
|
|
|
|
|
'' + optionalString (targetPlatform.libc == "newlib") ''
|
2018-10-15 22:11:20 +01:00
|
|
|
|
hardening_unsupported_flags+=" stackprotector fortify pie pic"
|
2019-04-09 19:21:54 +01:00
|
|
|
|
'' + optionalString targetPlatform.isNetBSD ''
|
|
|
|
|
hardening_unsupported_flags+=" stackprotector fortify"
|
2018-10-15 22:11:20 +01:00
|
|
|
|
''
|
|
|
|
|
|
2019-01-30 02:01:24 +00:00
|
|
|
|
+ optionalString targetPlatform.isWasm ''
|
|
|
|
|
hardening_unsupported_flags+=" stackprotector fortify pie pic"
|
|
|
|
|
''
|
|
|
|
|
|
2018-10-15 22:11:20 +01:00
|
|
|
|
+ optionalString (libc != null && targetPlatform.isAvr) ''
|
|
|
|
|
for isa in avr5 avr3 avr4 avr6 avr25 avr31 avr35 avr51 avrxmega2 avrxmega4 avrxmega5 avrxmega6 avrxmega7 tiny-stack; do
|
|
|
|
|
echo "-B${getLib libc}/avr/lib/$isa" >> $out/nix-support/libc-cflags
|
|
|
|
|
done
|
|
|
|
|
''
|
|
|
|
|
|
2020-02-27 15:39:35 +00:00
|
|
|
|
# There are a few tools (to name one libstdcxx5) which do not work
|
|
|
|
|
# well with multi line flags, so make the flags single line again
|
2017-06-20 19:04:24 +01:00
|
|
|
|
+ ''
|
2020-03-10 10:04:32 +00:00
|
|
|
|
if [ -e "$out/nix-support/libc-cflags" ]; then
|
|
|
|
|
substituteInPlace "$out/nix-support/libc-cflags" --replace $'\n' ' '
|
|
|
|
|
fi
|
2020-02-27 15:39:35 +00:00
|
|
|
|
|
2017-06-26 05:43:06 +01:00
|
|
|
|
substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh
|
|
|
|
|
substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh
|
2018-05-07 18:15:34 +01:00
|
|
|
|
substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash
|
2017-08-23 21:55:55 +01:00
|
|
|
|
|
|
|
|
|
##
|
|
|
|
|
## Extra custom steps
|
|
|
|
|
##
|
2015-07-20 12:42:30 +01:00
|
|
|
|
''
|
2018-02-01 00:00:00 +00:00
|
|
|
|
|
2015-07-20 12:42:30 +01:00
|
|
|
|
+ extraBuildCommands;
|
2014-10-10 12:49:26 +01:00
|
|
|
|
|
2017-08-28 19:56:08 +01:00
|
|
|
|
inherit expand-response-params;
|
2017-07-01 01:27:48 +01:00
|
|
|
|
|
2018-05-07 18:15:34 +01:00
|
|
|
|
# for substitution in utils.bash
|
2017-08-23 21:39:15 +01:00
|
|
|
|
expandResponseParams = "${expand-response-params}/bin/expand-response-params";
|
2010-12-04 21:45:37 +00:00
|
|
|
|
|
2009-03-25 18:34:27 +00:00
|
|
|
|
meta =
|
2015-01-09 19:22:12 +00:00
|
|
|
|
let cc_ = if cc != null then cc else {}; in
|
|
|
|
|
(if cc_ ? meta then removeAttrs cc.meta ["priority"] else {}) //
|
2009-04-19 17:00:46 +01:00
|
|
|
|
{ description =
|
2015-01-09 19:22:12 +00:00
|
|
|
|
stdenv.lib.attrByPath ["meta" "description"] "System C compiler" cc_
|
2009-04-19 17:00:46 +01:00
|
|
|
|
+ " (wrapper script)";
|
2019-02-01 01:07:55 +00:00
|
|
|
|
priority = 10;
|
2017-07-18 04:36:17 +01:00
|
|
|
|
};
|
2008-06-26 12:07:46 +01:00
|
|
|
|
}
|