summary refs log tree commit diff
path: root/pkgs/os-specific/linux/minimal-bootstrap/gcc/8.nix
blob: d6a6560e01e7811453743bdf9890c603bacade7f (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
130
131
132
133
134
135
136
137
138
139
140
{ lib
, buildPlatform
, hostPlatform
, fetchurl
, bash
, coreutils
, gcc
, musl
, binutils
, gnumake
, gnused
, gnugrep
, gawk
, diffutils
, findutils
, gnutar
, gzip
, bzip2
, xz
}:
let
  pname = "gcc";
  version = "8.5.0";

  src = fetchurl {
    url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz";
    hash = "sha256-0wiEGlEbuDCmEAOXsAQtskzhH2Qtq26m7kSELlMl7VA=";
  };

  # last version to compile with gcc 4.6
  gmpVersion = "6.2.1";
  gmp = fetchurl {
    url = "mirror://gnu/gmp/gmp-${gmpVersion}.tar.xz";
    hash = "sha256-/UgpkSzd0S+EGBw0Ucx1K+IkZD6H+sSXtp7d2txJtPI=";
  };

  mpfrVersion = "4.2.1";
  mpfr = fetchurl {
    url = "mirror://gnu/mpfr/mpfr-${mpfrVersion}.tar.xz";
    hash = "sha256-J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I=";
  };

  mpcVersion = "1.3.1";
  mpc = fetchurl {
    url = "mirror://gnu/mpc/mpc-${mpcVersion}.tar.gz";
    hash = "sha256-q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg=";
  };

  islVersion = "0.24";
  isl = fetchurl {
    url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${islVersion}.tar.bz2";
    hash = "sha256-/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA=";
  };
in
bash.runCommand "${pname}-${version}" {
  inherit pname version;

  nativeBuildInputs = [
    gcc
    binutils
    gnumake
    gnused
    gnugrep
    gawk
    diffutils
    findutils
    gnutar
    gzip
    bzip2
    xz
  ];

  passthru.tests.hello-world = result:
    bash.runCommand "${pname}-simple-program-${version}" {
        nativeBuildInputs = [ binutils musl result ];
      } ''
        cat <<EOF >> test.c
        #include <stdio.h>
        int main() {
          printf("Hello World!\n");
          return 0;
        }
        EOF
        musl-gcc -o test test.c
        ./test
        mkdir $out
      '';

  meta = with lib; {
    description = "GNU Compiler Collection, version ${version}";
    homepage = "https://gcc.gnu.org";
    license = licenses.gpl3Plus;
    maintainers = teams.minimal-bootstrap.members;
    platforms = platforms.unix;
  };
} ''
  # Unpack
  tar xf ${src}
  tar xf ${gmp}
  tar xf ${mpfr}
  tar xf ${mpc}
  tar xf ${isl}
  cd gcc-${version}

  ln -s ../gmp-${gmpVersion} gmp
  ln -s ../mpfr-${mpfrVersion} mpfr
  ln -s ../mpc-${mpcVersion} mpc
  ln -s ../isl-${islVersion} isl

  # Patch
  # doesn't recognise musl
  sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host

  # Configure
  export CC="gcc -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
  export CXX="g++ -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
  export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${musl}/lib/libc.so"
  export C_INCLUDE_PATH="${musl}/include"
  export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH"
  export LIBRARY_PATH="${musl}/lib"

  bash ./configure \
    --prefix=$out \
    --build=${buildPlatform.config} \
    --host=${hostPlatform.config} \
    --with-native-system-header-dir=/include \
    --with-sysroot=${musl} \
    --enable-languages=c,c++ \
    --disable-bootstrap \
    --disable-libmpx \
    --disable-libsanitizer \
    --disable-lto \
    --disable-multilib

  # Build
  make -j $NIX_BUILD_CORES

  # Install
  make -j $NIX_BUILD_CORES install
''