1{
2 fetchurl,
3 lib,
4 stdenv,
5 makeWrapper,
6 gnum4,
7 texinfo,
8 texliveSmall,
9 automake,
10 autoconf,
11 libtool,
12 ghostscript,
13 ncurses,
14 enableX11 ? false,
15 libX11,
16}:
17
18let
19 version = "12.1";
20 bootstrapFromC =
21 !((stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) || stdenv.hostPlatform.isx86_64);
22
23 arch =
24 if stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64 then "-aarch64le" else "-x86-64";
25in
26stdenv.mkDerivation {
27 pname = "mit-scheme" + lib.optionalString enableX11 "-x11";
28 inherit version;
29
30 # MIT/GNU Scheme is not bootstrappable, so it's recommended to compile from
31 # the platform-specific tarballs, which contain pre-built binaries. It
32 # leads to more efficient code than when building the tarball that contains
33 # generated C code instead of those binaries.
34 src =
35 if stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64 then
36 fetchurl {
37 url = "mirror://gnu/mit-scheme/stable.pkg/${version}/mit-scheme-${version}-aarch64le.tar.gz";
38 sha256 = "12ra9bc93x8g07impbd8jr6djjzwpb9qvh9zhxvvrba3332zx3vh";
39 }
40 else
41 fetchurl {
42 url = "mirror://gnu/mit-scheme/stable.pkg/${version}/mit-scheme-${version}-x86-64.tar.gz";
43 sha256 = "035f92vni0vqmgj9hq2i7vwasz7crx52wll4823vhfkm1qdv5ywc";
44 };
45
46 buildInputs = [ ncurses ] ++ lib.optionals enableX11 [ libX11 ];
47
48 configurePhase = ''
49 runHook preConfigure
50 (cd src && ./configure)
51 (cd doc && ./configure)
52 runHook postConfigure
53 '';
54
55 env.NIX_CFLAGS_COMPILE = toString [
56 # Needed with GCC 12
57 "-Wno-error=array-parameter"
58 "-Wno-error=use-after-free"
59 ];
60
61 buildPhase = ''
62 runHook preBuild
63 cd src
64
65 ${if bootstrapFromC then "./etc/make-liarc.sh --prefix=$out" else "make compile-microcode"}
66
67 cd ../doc
68
69 make
70
71 cd ..
72
73 runHook postBuild
74 '';
75
76 installPhase = ''
77 runHook preInstall
78 make prefix=$out install -C src
79 make prefix=$out install -C doc
80 runHook postInstall
81 '';
82
83 postFixup = ''
84 wrapProgram $out/bin/mit-scheme${arch}-${version} --set MITSCHEME_LIBRARY_PATH \
85 $out/lib/mit-scheme${arch}-${version}
86 '';
87
88 nativeBuildInputs = [
89 makeWrapper
90 gnum4
91 texinfo
92 (texliveSmall.withPackages (
93 ps: with ps; [
94 epsf
95 ps.texinfo
96 ]
97 ))
98 automake
99 ghostscript
100 autoconf
101 libtool
102 ];
103
104 # XXX: The `check' target doesn't exist.
105 doCheck = false;
106
107 meta = with lib; {
108 description = "MIT/GNU Scheme, a native code Scheme compiler";
109
110 longDescription = ''
111 MIT/GNU Scheme is an implementation of the Scheme programming
112 language, providing an interpreter, compiler, source-code debugger,
113 integrated Emacs-like editor, and a large runtime library. MIT/GNU
114 Scheme is best suited to programming large applications with a rapid
115 development cycle.
116 '';
117
118 homepage = "https://www.gnu.org/software/mit-scheme/";
119
120 license = licenses.gpl2Plus;
121
122 maintainers = [ ];
123
124 # Build fails on Cygwin and Darwin:
125 # <http://article.gmane.org/gmane.lisp.scheme.mit-scheme.devel/489>.
126 platforms = platforms.gnu ++ platforms.linux ++ platforms.freebsd;
127 };
128}