lol
1{ lib, stdenv, fetchurl, fetchpatch, runCommand, bootstrap_cmds, coreutils, glibc, m4, runtimeShell }:
2
3let
4 options = rec {
5 /* TODO: there are also FreeBSD and Windows versions */
6 x86_64-linux = {
7 arch = "linuxx86";
8 sha256 = "0d5bsizgpw9hv0jfsf4bp5sf6kxh8f9hgzz9hsjzpfhs3npmmac4";
9 runtime = "lx86cl64";
10 kernel = "linuxx8664";
11 };
12 i686-linux = {
13 arch = "linuxx86";
14 sha256 = x86_64-linux.sha256;
15 runtime = "lx86cl";
16 kernel = "linuxx8632";
17 };
18 armv7l-linux = {
19 arch = "linuxarm";
20 sha256 = throw "ccl all-in-one linuxarm archive missing upstream";
21 runtime = "armcl";
22 kernel = "linuxarm";
23 };
24 x86_64-darwin = {
25 arch = "darwinx86";
26 sha256 = "1l060719k8mjd70lfdnr0hkybk7v88zxvfrsp7ww50q808cjffqk";
27 runtime = "dx86cl64";
28 kernel = "darwinx8664";
29 };
30 armv6l-linux = armv7l-linux;
31 };
32 cfg = options.${stdenv.hostPlatform.system} or (throw "missing source url for platform ${stdenv.hostPlatform.system}");
33
34 # The 1.12 github release of CCL seems to be missing the usual
35 # ccl-1.12-linuxarm.tar.gz tarball, so we build it ourselves here
36 linuxarm-src = runCommand "ccl-1.12-linuxarm.tar.gz" {
37 outer = fetchurl {
38 url = "https://github.com/Clozure/ccl/archive/v1.12.tar.gz";
39 sha256 = "0lmxhll6zgni0l41h4kcf3khbih9r0f8xni6zcfvbi3dzfs0cjkp";
40 };
41 inner = fetchurl {
42 url = "https://github.com/Clozure/ccl/releases/download/v1.12/linuxarm.tar.gz";
43 sha256 = "0x4bjx6cxsjvxyagijhlvmc7jkyxifdvz5q5zvz37028va65243c";
44 };
45 } ''
46 tar xf $outer
47 tar xf $inner -C ccl
48 tar czf $out ccl
49 '';
50
51in
52
53stdenv.mkDerivation rec {
54 pname = "ccl";
55 version = "1.12";
56
57 src = if cfg.arch == "linuxarm" then linuxarm-src else fetchurl {
58 url = "https://github.com/Clozure/ccl/releases/download/v${version}/ccl-${version}-${cfg.arch}.tar.gz";
59 sha256 = cfg.sha256;
60 };
61
62 patches = [
63 # Pull upstream fiux for -fno-common toolchains:
64 # https://github.com/Clozure/ccl/pull/316
65 (fetchpatch {
66 name = "fno-common-p1.patch";
67 url = "https://github.com/Clozure/ccl/commit/185dc1a00e7492f8be98e5f93b561758423595f1.patch";
68 sha256 = "0wqfds7346qdwdsxz3bl2p601ib94rdp9nknj7igj01q8lqfpajw";
69 })
70 (fetchpatch {
71 name = "fno-common-p2.patch";
72 url = "https://github.com/Clozure/ccl/commit/997de91062d1f152d0c3b322a1e3694243e4a403.patch";
73 sha256 = "10w6zw8wgalkdyya4m48lgca4p9wgcp1h44hy9wqr94dzlllq0f6";
74 })
75 ];
76
77 buildInputs = if stdenv.isDarwin then [ bootstrap_cmds m4 ] else [ glibc m4 ];
78
79 CCL_RUNTIME = cfg.runtime;
80 CCL_KERNEL = cfg.kernel;
81
82 postPatch = if stdenv.isDarwin then ''
83 substituteInPlace lisp-kernel/${CCL_KERNEL}/Makefile \
84 --replace "M4 = gm4" "M4 = m4" \
85 --replace "dtrace" "/usr/sbin/dtrace" \
86 --replace "/bin/rm" "${coreutils}/bin/rm" \
87 --replace "/bin/echo" "${coreutils}/bin/echo"
88
89 substituteInPlace lisp-kernel/m4macros.m4 \
90 --replace "/bin/pwd" "${coreutils}/bin/pwd"
91 '' else ''
92 substituteInPlace lisp-kernel/${CCL_KERNEL}/Makefile \
93 --replace "/bin/rm" "${coreutils}/bin/rm" \
94 --replace "/bin/echo" "${coreutils}/bin/echo"
95
96 substituteInPlace lisp-kernel/m4macros.m4 \
97 --replace "/bin/pwd" "${coreutils}/bin/pwd"
98 '';
99
100 buildPhase = ''
101 make -C lisp-kernel/${CCL_KERNEL} clean
102 make -C lisp-kernel/${CCL_KERNEL} all
103
104 ./${CCL_RUNTIME} -n -b -e '(ccl:rebuild-ccl :full t)' -e '(ccl:quit)'
105 '';
106
107 installPhase = ''
108 mkdir -p "$out/share"
109 cp -r . "$out/share/ccl-installation"
110
111 mkdir -p "$out/bin"
112 echo -e '#!${runtimeShell}\n'"$out/share/ccl-installation/${CCL_RUNTIME}"' "$@"\n' > "$out"/bin/"${CCL_RUNTIME}"
113 chmod a+x "$out"/bin/"${CCL_RUNTIME}"
114 ln -s "$out"/bin/"${CCL_RUNTIME}" "$out"/bin/ccl
115 '';
116
117 hardeningDisable = [ "format" ];
118
119 meta = with lib; {
120 description = "Clozure Common Lisp";
121 homepage = "https://ccl.clozure.com/";
122 maintainers = with maintainers; [ raskin ];
123 platforms = attrNames options;
124 # assembler failures during build, x86_64-darwin broken since 2020-10-14
125 broken = (stdenv.isDarwin && stdenv.isx86_64);
126 license = licenses.asl20;
127 };
128}