lol
1{ lib
2, buildPlatform
3, hostPlatform
4, fetchurl
5, bash
6, tinycc
7, binutils
8, gnumake
9, gnupatch
10, gnused
11, gnugrep
12, gawk
13, diffutils
14, findutils
15, gnutar
16, gzip
17}:
18let
19 pname = "gcc";
20 version = "4.6.4";
21
22 src = fetchurl {
23 url = "mirror://gnu/gcc/gcc-${version}/gcc-core-${version}.tar.gz";
24 sha256 = "173kdb188qg79pcz073cj9967rs2vzanyjdjyxy9v0xb0p5sad75";
25 };
26
27 ccSrc = fetchurl {
28 url = "mirror://gnu/gcc/gcc-${version}/gcc-g++-${version}.tar.gz";
29 sha256 = "1fqqk5zkmdg4vmqzdmip9i42q6b82i3f6yc0n86n9021cr7ms2k9";
30 };
31
32 gmpVersion = "4.3.2";
33 gmp = fetchurl {
34 url = "mirror://gnu/gmp/gmp-${gmpVersion}.tar.gz";
35 sha256 = "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv";
36 };
37
38 mpfrVersion = "2.4.2";
39 mpfr = fetchurl {
40 url = "mirror://gnu/mpfr/mpfr-${mpfrVersion}.tar.gz";
41 sha256 = "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94";
42 };
43
44 mpcVersion = "1.0.3";
45 mpc = fetchurl {
46 url = "mirror://gnu/mpc/mpc-${mpcVersion}.tar.gz";
47 sha256 = "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1";
48 };
49
50 patches = [
51 # Remove hardcoded NATIVE_SYSTEM_HEADER_DIR
52 ./no-system-headers.patch
53 ];
54in
55bash.runCommand "${pname}-${version}" {
56 inherit pname version;
57
58 nativeBuildInputs = [
59 tinycc.compiler
60 binutils
61 gnumake
62 gnupatch
63 gnused
64 gnugrep
65 gawk
66 diffutils
67 findutils
68 gnutar
69 gzip
70 ];
71
72 passthru.tests.get-version = result:
73 bash.runCommand "${pname}-get-version-${version}" {} ''
74 ${result}/bin/gcc --version
75 mkdir $out
76 '';
77
78 meta = with lib; {
79 description = "GNU Compiler Collection, version ${version}";
80 homepage = "https://gcc.gnu.org";
81 license = licenses.gpl3Plus;
82 maintainers = teams.minimal-bootstrap.members;
83 platforms = platforms.unix;
84 };
85} ''
86 # Unpack
87 tar xzf ${src}
88 tar xzf ${ccSrc}
89 tar xzf ${gmp}
90 tar xzf ${mpfr}
91 tar xzf ${mpc}
92 cd gcc-${version}
93
94 ln -s ../gmp-${gmpVersion} gmp
95 ln -s ../mpfr-${mpfrVersion} mpfr
96 ln -s ../mpc-${mpcVersion} mpc
97
98 # Patch
99 ${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches}
100
101 # Configure
102 export CC="tcc -B ${tinycc.libs}/lib"
103 export C_INCLUDE_PATH="${tinycc.libs}/include:$(pwd)/mpfr/src"
104 export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH"
105
106 # Avoid "Link tests are not allowed after GCC_NO_EXECUTABLES"
107 export lt_cv_shlibpath_overrides_runpath=yes
108 export ac_cv_func_memcpy=yes
109 export ac_cv_func_strerror=yes
110
111 bash ./configure \
112 --prefix=$out \
113 --build=${buildPlatform.config} \
114 --host=${hostPlatform.config} \
115 --with-native-system-header-dir=${tinycc.libs}/include \
116 --with-build-sysroot=${tinycc.libs}/include \
117 --disable-bootstrap \
118 --disable-decimal-float \
119 --disable-libatomic \
120 --disable-libcilkrts \
121 --disable-libgomp \
122 --disable-libitm \
123 --disable-libmudflap \
124 --disable-libquadmath \
125 --disable-libsanitizer \
126 --disable-libssp \
127 --disable-libvtv \
128 --disable-lto \
129 --disable-lto-plugin \
130 --disable-multilib \
131 --disable-plugin \
132 --disable-threads \
133 --enable-languages=c \
134 --enable-static \
135 --disable-shared \
136 --enable-threads=single \
137 --disable-libstdcxx-pch \
138 --disable-build-with-cxx
139
140 # Build
141 make -j $NIX_BUILD_CORES
142
143 # Install
144 make -j $NIX_BUILD_CORES install
145''