at master 152 lines 3.4 kB view raw
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 mainProgram = "gcc"; 105 }; 106 } 107 '' 108 # Unpack 109 tar xf ${src} 110 tar xf ${gmp} 111 tar xf ${mpfr} 112 tar xf ${mpc} 113 tar xf ${isl} 114 cd gcc-${version} 115 116 ln -s ../gmp-${gmpVersion} gmp 117 ln -s ../mpfr-${mpfrVersion} mpfr 118 ln -s ../mpc-${mpcVersion} mpc 119 ln -s ../isl-${islVersion} isl 120 121 # Patch 122 # doesn't recognise musl 123 sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host 124 125 # Configure 126 export CC="gcc -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so" 127 export CXX="g++ -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so" 128 export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${musl}/lib/libc.so" 129 export C_INCLUDE_PATH="${musl}/include" 130 export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH" 131 export LIBRARY_PATH="${musl}/lib" 132 133 bash ./configure \ 134 --prefix=$out \ 135 --build=${buildPlatform.config} \ 136 --host=${hostPlatform.config} \ 137 --with-native-system-header-dir=/include \ 138 --with-sysroot=${musl} \ 139 --enable-languages=c,c++ \ 140 --disable-bootstrap \ 141 --disable-libmpx \ 142 --disable-libsanitizer \ 143 --disable-lto \ 144 --disable-multilib \ 145 --disable-plugin 146 147 # Build 148 make -j $NIX_BUILD_CORES 149 150 # Install 151 make -j $NIX_BUILD_CORES install-strip 152 ''