nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 buildPlatform,
4 hostPlatform,
5 fetchurl,
6 bash,
7 coreutils,
8 gcc,
9 musl,
10 binutils,
11 gnumake,
12 gnused,
13 gnugrep,
14 gawk,
15 diffutils,
16 findutils,
17 gnutar,
18 gzip,
19 bzip2,
20 xz,
21}:
22let
23 pname = "gcc";
24 version = "8.5.0";
25
26 src = fetchurl {
27 url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz";
28 hash = "sha256-0wiEGlEbuDCmEAOXsAQtskzhH2Qtq26m7kSELlMl7VA=";
29 };
30
31 # last version to compile with gcc 4.6
32 gmpVersion = "6.2.1";
33 gmp = fetchurl {
34 url = "mirror://gnu/gmp/gmp-${gmpVersion}.tar.xz";
35 hash = "sha256-/UgpkSzd0S+EGBw0Ucx1K+IkZD6H+sSXtp7d2txJtPI=";
36 };
37
38 mpfrVersion = "4.2.1";
39 mpfr = fetchurl {
40 url = "mirror://gnu/mpfr/mpfr-${mpfrVersion}.tar.xz";
41 hash = "sha256-J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I=";
42 };
43
44 mpcVersion = "1.3.1";
45 mpc = fetchurl {
46 url = "mirror://gnu/mpc/mpc-${mpcVersion}.tar.gz";
47 hash = "sha256-q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg=";
48 };
49
50 islVersion = "0.24";
51 isl = fetchurl {
52 url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${islVersion}.tar.bz2";
53 hash = "sha256-/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA=";
54 };
55in
56bash.runCommand "${pname}-${version}"
57 {
58 inherit pname version;
59
60 nativeBuildInputs = [
61 gcc
62 binutils
63 gnumake
64 gnused
65 gnugrep
66 gawk
67 diffutils
68 findutils
69 gnutar
70 gzip
71 bzip2
72 xz
73 ];
74
75 passthru.tests.hello-world =
76 result:
77 bash.runCommand "${pname}-simple-program-${version}"
78 {
79 nativeBuildInputs = [
80 binutils
81 musl
82 result
83 ];
84 }
85 ''
86 cat <<EOF >> test.c
87 #include <stdio.h>
88 int main() {
89 printf("Hello World!\n");
90 return 0;
91 }
92 EOF
93 musl-gcc -o test test.c
94 ./test
95 mkdir $out
96 '';
97
98 meta = with lib; {
99 description = "GNU Compiler Collection, version ${version}";
100 homepage = "https://gcc.gnu.org";
101 license = licenses.gpl3Plus;
102 teams = [ teams.minimal-bootstrap ];
103 platforms = platforms.unix;
104 };
105 }
106 ''
107 # Unpack
108 tar xf ${src}
109 tar xf ${gmp}
110 tar xf ${mpfr}
111 tar xf ${mpc}
112 tar xf ${isl}
113 cd gcc-${version}
114
115 ln -s ../gmp-${gmpVersion} gmp
116 ln -s ../mpfr-${mpfrVersion} mpfr
117 ln -s ../mpc-${mpcVersion} mpc
118 ln -s ../isl-${islVersion} isl
119
120 # Patch
121 # doesn't recognise musl
122 sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host
123
124 # Configure
125 export CC="gcc -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
126 export CXX="g++ -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
127 export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
128 export C_INCLUDE_PATH="${musl}/include"
129 export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH"
130 export LIBRARY_PATH="${musl}/lib"
131
132 bash ./configure \
133 --prefix=$out \
134 --build=${buildPlatform.config} \
135 --host=${hostPlatform.config} \
136 --with-native-system-header-dir=/include \
137 --with-sysroot=${musl} \
138 --enable-languages=c,c++ \
139 --disable-bootstrap \
140 --disable-libmpx \
141 --disable-libsanitizer \
142 --disable-lto \
143 --disable-multilib \
144 --disable-plugin
145
146 # Build
147 make -j $NIX_BUILD_CORES
148
149 # Install
150 make -j $NIX_BUILD_CORES install-strip
151 ''