1{ stdenv, fetchurl, gcc, glibc, m4, coreutils }:
2
3let
4 options = rec {
5 /* TODO: there are also FreeBSD and Windows versions */
6 x86_64-linux = {
7 arch = "linuxx86";
8 sha256 = "0hs1f3z7crgzvinpj990kv9gvbsipxvcvwbmk54n51nasvc5025q";
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 = "0p0l1dzsygb6i1xxgbipjpxkn46xhq3jm41a34ga1qqp4x8lkr62";
21 runtime = "armcl";
22 kernel = "linuxarm";
23 };
24 x86_64-darwin = {
25 arch = "darwinx86";
26 sha256 = "5adbea3d8b4a2e29af30d141f781c6613844f468c0ccfa11bae908c3e9641939";
27 runtime = "dx86cl64";
28 kernel = "darwinx8664";
29 };
30 i686-darwin = {
31 arch = "darwinx86";
32 sha256 = x86_64-darwin.sha256;
33 runtime = "dx86cl";
34 kernel = "darwinx8632";
35 };
36 armv6l-linux = armv7l-linux;
37 };
38 cfg = options.${stdenv.system};
39in
40
41assert builtins.hasAttr stdenv.system options;
42
43stdenv.mkDerivation rec {
44 name = "ccl-${version}";
45 version = "1.11.5";
46
47 src = fetchurl {
48 url = "https://github.com/Clozure/ccl/releases/download/v${version}/ccl-${version}-${cfg.arch}.tar.gz";
49 sha256 = cfg.sha256;
50 };
51
52 buildInputs = if stdenv.isDarwin then [ m4 ] else [ gcc glibc m4 ];
53
54 CCL_RUNTIME = cfg.runtime;
55 CCL_KERNEL = cfg.kernel;
56
57 postPatch = if stdenv.isDarwin then ''
58 substituteInPlace lisp-kernel/${CCL_KERNEL}/Makefile \
59 --replace "M4 = gm4" "M4 = m4" \
60 --replace "dtrace" "/usr/sbin/dtrace" \
61 --replace "mig" "/usr/bin/mig" \
62 --replace "/bin/rm" "${coreutils}/bin/rm" \
63 --replace "/bin/echo" "${coreutils}/bin/echo"
64
65 substituteInPlace lisp-kernel/m4macros.m4 \
66 --replace "/bin/pwd" "${coreutils}/bin/pwd"
67 '' else ''
68 substituteInPlace lisp-kernel/${CCL_KERNEL}/Makefile \
69 --replace "/bin/rm" "${coreutils}/bin/rm" \
70 --replace "/bin/echo" "${coreutils}/bin/echo"
71
72 substituteInPlace lisp-kernel/m4macros.m4 \
73 --replace "/bin/pwd" "${coreutils}/bin/pwd"
74 '';
75
76 buildPhase = ''
77 make -C lisp-kernel/${CCL_KERNEL} clean
78 make -C lisp-kernel/${CCL_KERNEL} all
79
80 ./${CCL_RUNTIME} -n -b -e '(ccl:rebuild-ccl :full t)' -e '(ccl:quit)'
81 '';
82
83 installPhase = ''
84 mkdir -p "$out/share"
85 cp -r . "$out/share/ccl-installation"
86
87 mkdir -p "$out/bin"
88 echo -e '#!${stdenv.shell}\n'"$out/share/ccl-installation/${CCL_RUNTIME}"' "$@"\n' > "$out"/bin/"${CCL_RUNTIME}"
89 chmod a+x "$out"/bin/"${CCL_RUNTIME}"
90 ln -s "$out"/bin/"${CCL_RUNTIME}" "$out"/bin/ccl
91 '';
92
93 meta = with stdenv.lib; {
94 description = "Clozure Common Lisp";
95 homepage = https://ccl.clozure.com/;
96 maintainers = with maintainers; [ raskin muflax tohl ];
97 platforms = attrNames options;
98 license = licenses.lgpl21;
99 };
100}