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-12-17 23:02:40 +01:00
|
|
|
, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null
|
2017-08-22 00:26:08 +02:00
|
|
|
, buildPackages ? {}
|
2017-07-18 05:36:17 +02:00
|
|
|
, useMacosReexportHack ? false
|
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
|
|
|
|
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-07-06 03:47:48 +02:00
|
|
|
inherit (stdenv) hostPlatform targetPlatform;
|
|
|
|
|
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;
|
2017-06-26 06:43:06 +02: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.
|
|
|
|
infixSalt = dashlessTarget;
|
2017-06-19 17:10:27 +02:00
|
|
|
|
2017-06-26 08:01:03 +02:00
|
|
|
# The dynamic linker has different names on different platforms. This is a
|
|
|
|
# shell glob that ought to match it.
|
2017-06-19 17:10:27 +02:00
|
|
|
dynamicLinker =
|
2017-06-26 08:01:03 +02:00
|
|
|
/**/ 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".
|
2017-09-19 01:23:50 +02:00
|
|
|
else if (with targetPlatform; isArm && isLinux) then "${libc_lib}/lib/ld-linux*.so.3"
|
2017-06-26 08:01:03 +02:00
|
|
|
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"
|
2017-09-19 01:23:50 +02:00
|
|
|
else if targetPlatform.isDarwin then "/usr/lib/dyld"
|
2017-06-26 08:01:03 +02:00
|
|
|
else if stdenv.lib.hasSuffix "pc-gnu" targetPlatform.config then "ld.so.1"
|
|
|
|
else null;
|
2017-06-19 17:10:27 +02:00
|
|
|
|
2017-08-23 22:23:30 +02:00
|
|
|
expand-response-params =
|
|
|
|
if buildPackages.stdenv.cc or null != null && buildPackages.stdenv.cc != "/dev/null"
|
|
|
|
then import ../expand-response-params { inherit (buildPackages) stdenv; }
|
|
|
|
else "";
|
2017-06-29 18:06:55 +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-26 07:17:09 +02:00
|
|
|
binPrefix = prefix;
|
2017-06-26 06:43:06 +02:00
|
|
|
inherit infixSalt;
|
2017-06-08 20:00:40 +02:00
|
|
|
|
2017-07-25 14:22:33 +02:00
|
|
|
outputs = [ "out" "man" ];
|
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-06-26 06:43:06 +02:00
|
|
|
prefix;
|
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-06-26 06:43:06 +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-06-26 06:43:06 +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-06-26 06:43:06 +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
|
|
|
|
2017-08-23 22:55:55 +02:00
|
|
|
dontBuild = true;
|
|
|
|
dontConfigure = true;
|
|
|
|
|
|
|
|
unpackPhase = ''
|
|
|
|
src=$PWD
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase =
|
2014-10-10 13:49:26 +02:00
|
|
|
''
|
2017-08-23 23:30:56 +02:00
|
|
|
set -u
|
|
|
|
|
2017-07-25 14:22:33 +02:00
|
|
|
mkdir -p $out/bin $out/nix-support $man/nix-support
|
2014-10-10 13:49:26 +02: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 22:55:55 +02:00
|
|
|
echo ${if targetPlatform.isDarwin then cc else nativePrefix} > $out/nix-support/orig-cc
|
|
|
|
|
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
|
|
|
ccPath="${cc}/bin"
|
2015-04-18 11:00:58 +02:00
|
|
|
ldPath="${binutils_bin}/bin"
|
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-06-26 06:43:06 +02:00
|
|
|
wrap ld-solaris ${./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-07-21 19:29:47 +02:00
|
|
|
'' + (if !useMacosReexportHack then ''
|
|
|
|
wrap ${prefix}ld ${./ld-wrapper.sh} ''${ld:-$ldPath/${prefix}ld}
|
|
|
|
'' else ''
|
2017-07-27 02:26:57 +02:00
|
|
|
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
|
2017-07-21 19:29:47 +02:00
|
|
|
'') + ''
|
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-06-26 06:43:06 +02:00
|
|
|
wrap ${prefix}ld.gold ${./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-06-26 06:43:06 +02:00
|
|
|
wrap ${prefix}ld.bfd ${./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.bfd
|
2014-10-10 14:01:38 +02:00
|
|
|
fi
|
|
|
|
|
2017-06-26 07:17:09 +02:00
|
|
|
# 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++
|
|
|
|
|
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-06-26 06:43:06 +02:00
|
|
|
wrap ${prefix}gcc ${./cc-wrapper.sh} $ccPath/${prefix}gcc
|
2017-02-14 00:01:04 +01:00
|
|
|
ln -s ${prefix}gcc $out/bin/${prefix}cc
|
2017-06-26 07:17:09 +02:00
|
|
|
export named_cc=${prefix}gcc
|
|
|
|
export named_cxx=${prefix}g++
|
2015-01-09 20:22:12 +01:00
|
|
|
elif [ -e $ccPath/clang ]; then
|
2017-06-26 06:43:06 +02:00
|
|
|
wrap ${prefix}clang ${./cc-wrapper.sh} $ccPath/clang
|
2017-02-14 00:01:04 +01:00
|
|
|
ln -s ${prefix}clang $out/bin/${prefix}cc
|
2017-06-26 07:17:09 +02:00
|
|
|
export named_cc=${prefix}clang
|
|
|
|
export named_cxx=${prefix}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-06-26 06:43:06 +02:00
|
|
|
wrap ${prefix}g++ ${./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-06-26 06:43:06 +02:00
|
|
|
wrap ${prefix}clang++ ${./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-06-26 06:43:06 +02:00
|
|
|
wrap ${prefix}cpp ${./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-06-26 06:43:06 +02:00
|
|
|
wrap ${prefix}gfortran ${./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-06-26 06:43:06 +02:00
|
|
|
wrap ${prefix}gcj ${./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-06-26 06:43:06 +02:00
|
|
|
wrap ${prefix}gccgo ${./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-06-26 06:43:06 +02:00
|
|
|
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
|
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
|
2017-08-23 22:55:55 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
propagatedBuildInputs = extraPackages;
|
|
|
|
|
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
|
|
|
|
postFixup =
|
|
|
|
''
|
|
|
|
set -u
|
|
|
|
''
|
|
|
|
|
|
|
|
+ optionalString (libc != null) (''
|
|
|
|
##
|
|
|
|
## 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.
|
|
|
|
echo "-B${libc_lib}/lib/ -idirafter ${libc_dev}/include -idirafter ${cc}/lib/gcc/*/*/include-fixed" > $out/nix-support/libc-cflags
|
|
|
|
|
|
|
|
echo "-L${libc_lib}/lib" > $out/nix-support/libc-ldflags
|
|
|
|
|
|
|
|
echo "${libc_lib}" > $out/nix-support/orig-libc
|
|
|
|
echo "${libc_dev}" > $out/nix-support/orig-libc-dev
|
|
|
|
|
|
|
|
##
|
|
|
|
## Dynamic linker support
|
|
|
|
##
|
|
|
|
|
|
|
|
if [[ -z ''${dynamicLinker+x} ]]; then
|
|
|
|
echo "Don't know the name of the dynamic linker for platform '${targetPlatform.config}', so guessing instead." >&2
|
|
|
|
local dynamicLinker="${libc_lib}/lib/ld*.so.?"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
local 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).
|
|
|
|
printWords "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before
|
|
|
|
'')
|
|
|
|
|
|
|
|
+ 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"
|
|
|
|
|
|
|
|
${optionalString cc.langVhdl or false ''
|
|
|
|
ccLDFlags+=" -L${zlib.out}/lib"
|
|
|
|
''}
|
|
|
|
|
|
|
|
# Find the gcc libraries path (may work only without multilib).
|
|
|
|
${optionalString cc.langAda or false ''
|
|
|
|
basePath=`echo ${cc_solib}/lib/*/*/*`
|
|
|
|
ccCFlags+=" -B$basePath -I$basePath/adainclude"
|
|
|
|
gnatCFlags="-aI$basePath/adainclude -aO$basePath/adalib"
|
|
|
|
echo "$gnatCFlags" > $out/nix-support/gnat-cflags
|
|
|
|
''}
|
|
|
|
|
|
|
|
echo "$ccLDFlags" > $out/nix-support/cc-ldflags
|
|
|
|
echo "$ccCFlags" > $out/nix-support/cc-cflags
|
|
|
|
|
|
|
|
##
|
|
|
|
## User env support
|
|
|
|
##
|
|
|
|
|
|
|
|
# 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).
|
|
|
|
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
|
2014-10-10 13:49:26 +02:00
|
|
|
''
|
|
|
|
|
|
|
|
+ ''
|
2017-08-23 22:55:55 +02:00
|
|
|
|
|
|
|
##
|
|
|
|
## Hardening support
|
|
|
|
##
|
2015-02-08 19:36:13 +01:00
|
|
|
|
2016-08-24 10:59:52 +02:00
|
|
|
# some linkers on some platforms don't support specific -z flags
|
2017-08-23 23:30:56 +02:00
|
|
|
export 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
|
2017-06-20 20:04:24 +02:00
|
|
|
''
|
|
|
|
|
|
|
|
+ optionalString hostPlatform.isCygwin ''
|
|
|
|
hardening_unsupported_flags+=" pic"
|
|
|
|
''
|
2016-08-23 18:13:31 +02:00
|
|
|
|
2017-06-20 20:04:24 +02:00
|
|
|
+ ''
|
2017-06-26 06:43:06 +02:00
|
|
|
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
|
2017-08-23 22:55:55 +02:00
|
|
|
|
|
|
|
##
|
|
|
|
## Extra custom steps
|
|
|
|
##
|
|
|
|
|
2015-07-20 13:42:30 +02:00
|
|
|
''
|
|
|
|
+ extraBuildCommands;
|
2014-10-10 13:49:26 +02:00
|
|
|
|
2017-07-01 02:27:48 +02:00
|
|
|
inherit dynamicLinker expand-response-params;
|
|
|
|
|
2017-08-23 22:39:15 +02:00
|
|
|
# for substitution in utils.sh
|
|
|
|
expandResponseParams = "${expand-response-params}/bin/expand-response-params";
|
2010-12-04 22:45:37 +01:00
|
|
|
|
|
|
|
crossAttrs = {
|
2012-12-28 19:08:19 +01:00
|
|
|
shell = shell.crossDrv + shell.crossDrv.shellPath;
|
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)";
|
2017-07-18 05:36:17 +02:00
|
|
|
} // optionalAttrs useMacosReexportHack {
|
|
|
|
platforms = stdenv.lib.platforms.darwin;
|
|
|
|
};
|
2008-06-26 13:07:46 +02:00
|
|
|
}
|