2008-06-26 13:07:46 +02:00
|
|
|
# The Nix `gcc' stdenv.mkDerivation is not directly usable, since it doesn't
|
|
|
|
# know where 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. This
|
|
|
|
# stdenv.mkDerivation provides a wrapper that sets up the right environment
|
|
|
|
# variables so that the compiler and the linker just "work".
|
|
|
|
|
2016-04-14 18:00:39 +02:00
|
|
|
{ name ? "", stdenv, lib, nativeTools, nativeLibc, nativePrefix ? ""
|
2010-01-26 19:10:59 +01:00
|
|
|
, gcc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? ""
|
|
|
|
, zlib ? null
|
2017-06-28 21:59:14 +02:00
|
|
|
, hostPlatform, targetPlatform
|
2008-06-26 13:07:46 +02:00
|
|
|
}:
|
|
|
|
|
|
|
|
assert nativeTools -> nativePrefix != "";
|
2009-11-08 01:32:12 +01:00
|
|
|
assert !nativeTools -> gcc != null && binutils != null && coreutils != null;
|
2008-06-26 13:07:46 +02:00
|
|
|
assert !nativeLibc -> libc != null;
|
|
|
|
|
2010-01-16 22:41:27 +01:00
|
|
|
# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper
|
2010-01-27 17:29:11 +01:00
|
|
|
assert (gcc != null && gcc ? langVhdl && gcc.langVhdl) -> zlib != null;
|
2010-01-16 22:41:27 +01:00
|
|
|
|
2009-04-09 17:24:33 +02:00
|
|
|
let
|
|
|
|
|
|
|
|
gccVersion = (builtins.parseDrvName gcc.name).version;
|
|
|
|
gccName = (builtins.parseDrvName gcc.name).name;
|
2012-08-03 19:23:51 +02:00
|
|
|
|
|
|
|
langGo = if nativeTools then false else gcc ? langGo && gcc.langGo;
|
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 {
|
2009-04-09 17:24:33 +02:00
|
|
|
name =
|
|
|
|
(if name != "" then name else gccName + "-wrapper") +
|
|
|
|
(if gcc != null && gccVersion != "" then "-" + gccVersion else "");
|
2014-02-04 16:58:12 +01:00
|
|
|
|
2008-06-26 13:07:46 +02:00
|
|
|
builder = ./builder.sh;
|
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
gccWrapper = ./gcc-wrapper.sh;
|
2010-01-16 22:32:44 +01:00
|
|
|
gnatWrapper = ./gnat-wrapper.sh;
|
|
|
|
gnatlinkWrapper = ./gnatlink-wrapper.sh;
|
2008-06-26 13:07:46 +02:00
|
|
|
ldWrapper = ./ld-wrapper.sh;
|
2013-02-23 14:59:59 +01:00
|
|
|
ldSolarisWrapper = ./ld-solaris-wrapper.sh;
|
2008-06-26 13:07:46 +02:00
|
|
|
utils = ./utils.sh;
|
|
|
|
addFlags = ./add-flags;
|
2014-02-04 16:58:12 +01:00
|
|
|
|
2008-06-26 13:07:46 +02:00
|
|
|
inherit nativeTools nativeLibc nativePrefix gcc;
|
2016-04-14 18:00:39 +02:00
|
|
|
gcc_lib = lib.getLib gcc;
|
2008-06-26 13:07:46 +02:00
|
|
|
libc = if nativeLibc then null else libc;
|
2016-04-14 18:00:39 +02:00
|
|
|
libc_dev = if nativeLibc then null else lib.getDev libc;
|
|
|
|
libc_bin = if nativeLibc then null else lib.getBin libc;
|
2016-04-25 13:27:51 +02:00
|
|
|
binutils = if nativeTools then null else lib.getBin binutils;
|
2009-11-08 01:32:12 +01:00
|
|
|
# The wrapper scripts use 'cat', so we may need coreutils
|
2016-04-25 13:27:51 +02:00
|
|
|
coreutils = if nativeTools then null else lib.getBin coreutils;
|
2014-02-04 16:58:12 +01:00
|
|
|
|
2008-06-26 13:07:46 +02:00
|
|
|
langC = if nativeTools then true else gcc.langC;
|
|
|
|
langCC = if nativeTools then true else gcc.langCC;
|
2008-06-27 16:43:25 +02:00
|
|
|
langFortran = if nativeTools then false else gcc ? langFortran;
|
2010-01-27 17:29:11 +01:00
|
|
|
langAda = if nativeTools then false else gcc ? langAda && gcc.langAda;
|
|
|
|
langVhdl = if nativeTools then false else gcc ? langVhdl && gcc.langVhdl;
|
2012-12-28 19:54:15 +01:00
|
|
|
zlib = if gcc != null && gcc ? langVhdl then zlib else null;
|
2010-12-07 16:18:05 +01:00
|
|
|
shell = if shell == "" then stdenv.shell else
|
|
|
|
if builtins.isAttrs shell then (shell + shell.shellPath)
|
|
|
|
else shell;
|
2010-12-04 22:45:37 +01:00
|
|
|
|
|
|
|
crossAttrs = {
|
2012-12-28 19:08:19 +01:00
|
|
|
shell = shell.crossDrv + shell.crossDrv.shellPath;
|
|
|
|
coreutils = coreutils.crossDrv;
|
|
|
|
binutils = binutils.crossDrv;
|
|
|
|
gcc = gcc.crossDrv;
|
2010-12-04 22:45:37 +01:00
|
|
|
#
|
|
|
|
# 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.
|
2011-06-13 00:32:44 +02:00
|
|
|
dynamicLinker =
|
2017-06-28 21:59:14 +02:00
|
|
|
(if hostPlatform.arch == "arm" then "ld-linux.so.3" else
|
|
|
|
if hostPlatform.arch == "mips" then "ld.so.1" else
|
|
|
|
if stdenv.lib.hasSuffix "pc-gnu" hostPlatform.config then "ld.so.1" else
|
2010-12-04 22:45:37 +01:00
|
|
|
abort "don't know the name of the dynamic linker for this platform");
|
|
|
|
};
|
2014-02-04 16:58:12 +01:00
|
|
|
|
2014-03-01 14:00:54 +01:00
|
|
|
preferLocalBuild = true;
|
|
|
|
|
2009-03-25 19:34:27 +01:00
|
|
|
meta =
|
2009-04-19 18:00:46 +02:00
|
|
|
let gcc_ = if gcc != null then gcc else {}; in
|
|
|
|
(if gcc_ ? meta then removeAttrs gcc.meta ["priority"] else {}) //
|
|
|
|
{ description =
|
2009-05-24 12:57:41 +02:00
|
|
|
stdenv.lib.attrByPath ["meta" "description"] "System C compiler" gcc_
|
2009-04-19 18:00:46 +02:00
|
|
|
+ " (wrapper script)";
|
|
|
|
};
|
2008-06-26 13:07:46 +02:00
|
|
|
|
2017-06-28 21:59:14 +02:00
|
|
|
# The dynamic linker has different names on different platforms.
|
2008-06-26 13:07:46 +02:00
|
|
|
dynamicLinker =
|
|
|
|
if !nativeLibc then
|
2017-06-28 21:59:14 +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
|
2012-12-29 15:14:53 +01:00
|
|
|
# ARM with a wildcard, which can be "" or "-armhf".
|
2017-06-28 21:59:14 +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
|
|
|
|
builtins.trace
|
|
|
|
"Don't know the name of the dynamic linker for platform ${targetPlatform.config}, so guessing instead."
|
|
|
|
null)
|
2008-06-26 13:07:46 +02:00
|
|
|
else "";
|
|
|
|
}
|