summaryrefslogtreecommitdiff
path: root/pkgs/development/compilers/ccl/default.nix
blob: 33bbba1bb930db301a4bed1dd658a4c3bfb69671 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
{
  lib,
  stdenv,
  fetchurl,
  bootstrap_cmds,
  coreutils,
  glibc,
  m4,
  runtimeShell,
}:

let
  options = rec {
    # TODO: there are also FreeBSD and Windows versions
    x86_64-linux = {
      arch = "linuxx86";
      hash = "sha256-cAae50xvBoXfg+tiJM4i8+eRnheyM0dseE5EDWDia/E=";
      runtime = "lx86cl64";
      kernel = "linuxx8664";
    };
    i686-linux = {
      arch = "linuxx86";
      hash = x86_64-linux.hash;
      runtime = "lx86cl";
      kernel = "linuxx8632";
    };
    armv7l-linux = {
      arch = "linuxarm";
      hash = "sha256-iyUMTDuHbyfEAxAAhjXANjh6HhpLkWG5+diXI6aFUUc=";
      runtime = "armcl";
      kernel = "linuxarm";
    };
    x86_64-darwin = {
      arch = "darwinx86";
      hash = "sha256-r+OhkU0b+QDgoZpZb0Xpc3V0yRq8GBKcNLt2IzeOSdE=";
      runtime = "dx86cl64";
      kernel = "darwinx8664";
    };
    armv6l-linux = armv7l-linux;
  };
  cfg =
    options.${stdenv.hostPlatform.system}
      or (throw "missing source url for platform ${stdenv.hostPlatform.system}");

in
stdenv.mkDerivation (finalAttrs: {
  pname = "ccl";
  version = "1.13";

  src = fetchurl {
    url = "https://github.com/Clozure/ccl/releases/download/v${finalAttrs.version}/ccl-${finalAttrs.version}-${cfg.arch}.tar.gz";
    hash = cfg.hash;
  };

  buildInputs =
    if stdenv.hostPlatform.isDarwin then
      [
        bootstrap_cmds
        m4
      ]
    else
      [
        glibc
        m4
      ];

  env = {
    CCL_RUNTIME = cfg.runtime;
    CCL_KERNEL = cfg.kernel;
  };

  postPatch =
    if stdenv.hostPlatform.isDarwin then
      ''
        substituteInPlace lisp-kernel/${finalAttrs.env.CCL_KERNEL}/Makefile \
          --replace "M4 = gm4"   "M4 = m4" \
          --replace "dtrace"     "/usr/sbin/dtrace" \
          --replace "/bin/rm"    "${coreutils}/bin/rm" \
          --replace "/bin/echo"  "${coreutils}/bin/echo"

        substituteInPlace lisp-kernel/m4macros.m4 \
          --replace "/bin/pwd" "${coreutils}/bin/pwd"
      ''
    else
      ''
        substituteInPlace lisp-kernel/${finalAttrs.env.CCL_KERNEL}/Makefile \
          --replace "/bin/rm"    "${coreutils}/bin/rm" \
          --replace "/bin/echo"  "${coreutils}/bin/echo"

        substituteInPlace lisp-kernel/m4macros.m4 \
          --replace "/bin/pwd" "${coreutils}/bin/pwd"
      '';

  buildPhase = ''
    make -C lisp-kernel/${finalAttrs.env.CCL_KERNEL} clean
    make -C lisp-kernel/${finalAttrs.env.CCL_KERNEL} all

    ./${finalAttrs.env.CCL_RUNTIME} -n -b -e '(ccl:rebuild-ccl :full t)' -e '(ccl:quit)'
  '';

  installPhase = ''
    mkdir -p "$out/share"
    cp -r .  "$out/share/ccl-installation"

    mkdir -p "$out/bin"
    echo -e '#!${runtimeShell}\n'"$out/share/ccl-installation/${finalAttrs.env.CCL_RUNTIME}"' "$@"\n' > "$out"/bin/"${finalAttrs.env.CCL_RUNTIME}"
    chmod a+x "$out"/bin/"${finalAttrs.env.CCL_RUNTIME}"
    ln -s "$out"/bin/"${finalAttrs.env.CCL_RUNTIME}" "$out"/bin/ccl
  '';

  hardeningDisable = [ "format" ];

  meta = {
    # assembler failures during build, x86_64-darwin broken since 2020-10-14
    broken = (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64);
    description = "Clozure Common Lisp";
    homepage = "https://ccl.clozure.com/";
    license = lib.licenses.asl20;
    mainProgram = "ccl";
    teams = [ lib.teams.lisp ];
    platforms = lib.attrNames options;
  };
})