summaryrefslogtreecommitdiff
path: root/pkgs/simple-scalar/gcc-sslittle-na-sstrix.nix
blob: 9cb6d3049bc13d7adbf02ecba22c4867bd18e573 (plain)
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
# https://www.cse.iitd.ac.in/~cs5070217/csl718/assignment1/ss_install_instructions.html
{
  bison,
  fetchurl,
  flex,
  multiStdenv,
  stdenv_32bit,
}: let
  host = "i686-pc-linux";
  target = "sslittle-na-sstrix";

  gcc-version = "2.7.2.3";
  makeflags = "LANGUAGES=c CC=\"$CC -m32 $CFLAGS\" prefix=$out";
in
  multiStdenv.mkDerivation {
    pname = "gcc-sslittle-na-sstrix";
    version = "1998-08-11"; # !!!

    nativeBuildInputs = [flex bison];

    sourceRoot = ".";

    srcs = [
      (fetchTarball {
        name = "simpleutils-990811";

        url = "https://www.cse.iitd.ac.in/~cs5070217/csl718/simpleutils-990811.tar.gz";
        sha256 = "sha256:0w952z382s7ghrxwrad7fd058b1kj5ad1abh8idxwwk47va72cdf";
      })
    ];

    # El código es muy viejo y Nix usa opciones muy estrictas por defecto
    CFLAGS = "-O3 -Wno-error=format-security";

    # Algunas tarballs vienen sin directorio de primer nivel y además requieren arreglos
    postUnpack = let
      simpletools = fetchurl {
        url = "https://www.cse.iitd.ac.in/~cs5070217/csl718/simpletools-2v0.tgz";
        sha256 = "sha256-FTDTqyQWZCnuNPmTcu3Hcjgp4pHNoUcC0GOGhSJV9Iw=";
      };

      gcc-ss = fetchurl {
        url = "https://www.cse.iitd.ac.in/~cs5070217/csl718/gcc-${gcc-version}.ss.tar.gz";
        sha256 = "sha256-3R3wsLmxoN3MkEW4gaxnhIyTBs0CUiSiH7C1/hF2atM=";
      };

      ar-and-ranlib = fetchurl {
        url = "https://www.cse.iitd.ac.in/~cs5070217/csl718/ar_and_ranlib.tar.gz";
        sha256 = "sha256-MRTO6cAg3WeXlk3jDy2lVuiSXDRz1+LLa2XDkBDygMU=";
      };
    in ''
      tar xf ${simpletools}
      rm -r gcc-2.6.3

      tar xf ${gcc-ss}

      mkdir ar-and-ranlib
      tar xf ${ar-and-ranlib} -C ar-and-ranlib

      chmod -R +w gcc-${gcc-version} ar-and-ranlib
    '';

    patches = [
      ./0001-fix-case-of-YY_CURRENT_BUFFER.patch
      ./0002-define-sys_nerr.patch
      ./0003-fix-obstack.h-post-increment.patch
      ./0004-stdarg.h-instead-of-varargs.h.patch
    ];

    postPatch = ''
      patchelf \
        --set-interpreter "$(<${stdenv_32bit.cc}/nix-support/dynamic-linker-m32)" \
        ar-and-ranlib/{ar,ranlib}
    '';

    configurePhase = ''
      BUILD=$PWD

      cd $BUILD/simpleutils-990811
      ./configure --host=${host} --target=${target} --with-gnu-as --with-gnu-ld --prefix=$out

      cd $BUILD/gcc-${gcc-version}
      ./configure --host=${host} --target=${target} --with-gnu-as --with-gnu-ld --prefix=$out
    '';

    buildPhase = ''
      make -C $BUILD/simpleutils-990811

      # GCC necesita binutils para compilar
      make -C $BUILD/simpleutils-990811 install
      cp $BUILD/ar-and-ranlib/{ar,ranlib} $out/${target}/bin/

      cd $BUILD/gcc-${gcc-version}

      mkdir -p $out/lib
      cp patched/sys/cdefs.h $BUILD/${target}/include/sys/cdefs.h
      cp -r $BUILD/${target} $out/
      cp $BUILD/${target}/lib/{libc.a,crt0.o} $out/lib/
      sed -i '130s@-I/usr/include@-I./include@' Makefile

      ! make ${makeflags}
      sed -i 's/\(return "FIXME\\n\)/\1\\/g' insn-output.c
      PATH="$out/${target}/bin:$PATH" make ${makeflags}
    '';

    installPhase = ''
      PATH="$out/${target}/bin:$PATH" make -C $BUILD/gcc-${gcc-version} ${makeflags} install
    '';
  }