2008-06-26 15:07:46 +04: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".
|
|
|
|
|
2009-04-09 19:24:33 +04:00
|
|
|
{ name ? "", stdenv, nativeTools, nativeLibc, nativePrefix ? ""
|
2010-01-26 21:10:59 +03:00
|
|
|
, gcc ? null, libc ? null, binutils ? null, coreutils ? null, shell ? ""
|
|
|
|
, zlib ? null
|
2008-06-26 15:07:46 +04:00
|
|
|
}:
|
|
|
|
|
|
|
|
assert nativeTools -> nativePrefix != "";
|
2009-11-08 03:32:12 +03:00
|
|
|
assert !nativeTools -> gcc != null && binutils != null && coreutils != null;
|
2008-06-26 15:07:46 +04:00
|
|
|
assert !nativeLibc -> libc != null;
|
|
|
|
|
2010-01-17 00:41:27 +03:00
|
|
|
# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper
|
2010-01-27 19:29:11 +03:00
|
|
|
assert (gcc != null && gcc ? langVhdl && gcc.langVhdl) -> zlib != null;
|
2010-01-17 00:41:27 +03:00
|
|
|
|
2009-04-09 19:24:33 +04:00
|
|
|
let
|
|
|
|
|
|
|
|
gccVersion = (builtins.parseDrvName gcc.name).version;
|
|
|
|
gccName = (builtins.parseDrvName gcc.name).name;
|
|
|
|
|
|
|
|
in
|
2009-03-25 20:34:38 +03:00
|
|
|
|
2008-06-26 15:07:46 +04:00
|
|
|
stdenv.mkDerivation {
|
2009-04-09 19:24:33 +04:00
|
|
|
name =
|
|
|
|
(if name != "" then name else gccName + "-wrapper") +
|
|
|
|
(if gcc != null && gccVersion != "" then "-" + gccVersion else "");
|
2009-03-25 20:34:38 +03:00
|
|
|
|
2008-06-26 15:07:46 +04:00
|
|
|
builder = ./builder.sh;
|
|
|
|
setupHook = ./setup-hook.sh;
|
|
|
|
gccWrapper = ./gcc-wrapper.sh;
|
2010-01-17 00:32:44 +03:00
|
|
|
gnatWrapper = ./gnat-wrapper.sh;
|
|
|
|
gnatlinkWrapper = ./gnatlink-wrapper.sh;
|
2008-06-26 15:07:46 +04:00
|
|
|
ldWrapper = ./ld-wrapper.sh;
|
|
|
|
utils = ./utils.sh;
|
|
|
|
addFlags = ./add-flags;
|
|
|
|
|
|
|
|
inherit nativeTools nativeLibc nativePrefix gcc;
|
|
|
|
libc = if nativeLibc then null else libc;
|
|
|
|
binutils = if nativeTools then null else binutils;
|
2009-11-08 03:32:12 +03:00
|
|
|
# The wrapper scripts use 'cat', so we may need coreutils
|
|
|
|
coreutils = if nativeTools then null else coreutils;
|
2008-06-26 15:07:46 +04:00
|
|
|
|
|
|
|
langC = if nativeTools then true else gcc.langC;
|
|
|
|
langCC = if nativeTools then true else gcc.langCC;
|
2008-06-27 18:43:25 +04:00
|
|
|
langFortran = if nativeTools then false else gcc ? langFortran;
|
2010-01-27 19:29:11 +03:00
|
|
|
langAda = if nativeTools then false else gcc ? langAda && gcc.langAda;
|
|
|
|
langVhdl = if nativeTools then false else gcc ? langVhdl && gcc.langVhdl;
|
2010-01-17 00:41:27 +03:00
|
|
|
zlib = if (gcc != null && gcc ? langVhdl) then zlib else null;
|
2010-12-07 18:18:05 +03:00
|
|
|
shell = if shell == "" then stdenv.shell else
|
|
|
|
if builtins.isAttrs shell then (shell + shell.shellPath)
|
|
|
|
else shell;
|
2010-12-05 00:45:37 +03:00
|
|
|
|
|
|
|
crossAttrs = {
|
2010-12-07 18:18:05 +03:00
|
|
|
shell = shell.hostDrv + shell.hostDrv.shellPath;
|
2010-12-05 00:45:37 +03:00
|
|
|
libc = libc.hostDrv;
|
|
|
|
coreutils = coreutils.hostDrv;
|
|
|
|
binutils = binutils.hostDrv;
|
|
|
|
gcc = gcc.hostDrv;
|
|
|
|
#
|
|
|
|
# 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 02:32:44 +04:00
|
|
|
dynamicLinker =
|
2010-12-05 00:45:37 +03:00
|
|
|
(if stdenv.cross.arch == "arm" then "ld-linux.so.3" else
|
|
|
|
if stdenv.cross.arch == "mips" then "ld.so.1" else
|
2011-06-13 02:35:20 +04:00
|
|
|
if stdenv.lib.hasSuffix "pc-gnu" stdenv.cross.config then "ld.so.1" else
|
2010-12-05 00:45:37 +03:00
|
|
|
abort "don't know the name of the dynamic linker for this platform");
|
|
|
|
};
|
2008-06-26 15:07:46 +04:00
|
|
|
|
2009-03-25 21:34:27 +03:00
|
|
|
meta =
|
2009-04-19 20:00:46 +04:00
|
|
|
let gcc_ = if gcc != null then gcc else {}; in
|
|
|
|
(if gcc_ ? meta then removeAttrs gcc.meta ["priority"] else {}) //
|
|
|
|
{ description =
|
2009-05-24 14:57:41 +04:00
|
|
|
stdenv.lib.attrByPath ["meta" "description"] "System C compiler" gcc_
|
2009-04-19 20:00:46 +04:00
|
|
|
+ " (wrapper script)";
|
|
|
|
};
|
2008-06-26 15:07:46 +04:00
|
|
|
|
|
|
|
# The dynamic linker has different names on different Linux platforms.
|
|
|
|
dynamicLinker =
|
|
|
|
if !nativeLibc then
|
|
|
|
(if stdenv.system == "i686-linux" then "ld-linux.so.2" else
|
|
|
|
if stdenv.system == "x86_64-linux" then "ld-linux-x86-64.so.2" else
|
2009-11-08 03:32:12 +03:00
|
|
|
if stdenv.system == "armv5tel-linux" then "ld-linux.so.3" else
|
2008-06-26 15:07:46 +04:00
|
|
|
if stdenv.system == "powerpc-linux" then "ld.so.1" else
|
2012-01-21 04:34:51 +04:00
|
|
|
if stdenv.system == "mips64el-linux" then "ld.so.1" else
|
2008-06-26 15:07:46 +04:00
|
|
|
abort "don't know the name of the dynamic linker for this platform")
|
|
|
|
else "";
|
|
|
|
}
|