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