blob: ef605d8702fa30ec0b4dd02e501956dad5e7069e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
{ stdenvNoLibs, buildPackages, buildPlatform, hostPlatform
, gcc, glibc
, libiberty
}:
stdenvNoLibs.mkDerivation rec {
name = "libgcc-${version}";
inherit (gcc.cc) src version;
outputs = [ "out" "dev" ];
strictDeps = true;
depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ libiberty ];
postUnpack = ''
mkdir -p ./build
buildRoot=$(readlink -e "./build")
'';
postPatch = ''
sourceRoot=$(readlink -e "./libgcc")
'';
preConfigure = ''
cd "$buildRoot"
''
# Drop in libiberty, as external builds are not expected
+ ''
(
mkdir -p build-${buildPlatform.config}/libiberty/
cd build-${buildPlatform.config}/libiberty/
ln -s ${buildPackages.libiberty}/lib/libiberty.a ./
)
''
# A few misc bits of gcc need to be built.
#
# - We "shift" the tools over to fake platforms perspective from the previous
# stage.
#
# - We define GENERATOR_FILE so nothing bothers looking for GNU GMP.
#
# - We remove the `libgcc.mvar` deps so that the bootstrap xgcc isn't built.
+ ''
mkdir -p "$buildRoot/gcc"
cd "$buildRoot/gcc"
(
export AS=$AS_FOR_BUILD
export CC=$CC_FOR_BUILD
export CPP=$CPP_FOR_BUILD
export CXX=$CXX_FOR_BUILD
export LD=$LD_FOR_BUILD
export AS_FOR_TARGET=$AS
export CC_FOR_TARGET=$CC
export CPP_FOR_TARGET=$CPP
export LD_FOR_TARGET=$LD
export NIX_BUILD_CFLAGS_COMPILE+=' -DGENERATOR_FILE=1'
"$sourceRoot/../gcc/configure" $gccConfigureFlags
sed -e 's,libgcc.mvars:.*$,libgcc.mvars:,' -i Makefile
make \
config.h \
libgcc.mvars \
tconfig.h \
tm.h \
options.h \
insn-constants.h \
insn-modes.h \
gcov-iov.h
)
mkdir -p "$buildRoot/gcc/include"
''
# Preparing to configure + build libgcc itself
+ ''
mkdir -p "$buildRoot/gcc/${hostPlatform.config}/libgcc"
cd "$buildRoot/gcc/${hostPlatform.config}/libgcc"
configureScript=$sourceRoot/configure
chmod +x "$configureScript"
'';
gccConfigureFlags = [
"--build=${buildPlatform.config}"
"--host=${buildPlatform.config}"
"--target=${hostPlatform.config}"
"--disable-bootstrap"
"--disable-multilib" "--with-multilib-list="
"--enable-languages=c"
"--disable-fixincludes"
"--disable-intl"
"--disable-lto"
"--disable-libatomic"
"--disable-libbacktrace"
"--disable-libcpp"
"--disable-libssp"
"--disable-libquadmath"
"--disable-libgomp"
"--disable-libvtv"
"--disable-vtable-verify"
"--with-system-zlib"
] ++ stdenvNoLibs.lib.optional (hostPlatform.libc == "glibc")
"--with-glibc-version=${glibc.version}";
configurePlatforms = [ "build" "host" ];
configureFlags = [
"--disable-dependency-tracking"
# $CC cannot link binaries, let alone run then
"cross_compiling=true"
# Do not have dynamic linker without libc
"--enable-static"
"--disable-shared"
];
makeFlags = [ "MULTIBUILDTOP:=../" ];
postInstall = ''
moveToOutput "lib/gcc/${hostPlatform.config}/${version}/include" "$dev"
mkdir -p "$out/lib" "$dev/include"
ln -s "$out/lib/gcc/${hostPlatform.config}/${version}"/* "$out/lib"
ln -s "$dev/lib/gcc/${hostPlatform.config}/${version}/include"/* "$dev/include/"
'';
}
|