1{
2 lib,
3 stdenv,
4 fetchurl,
5 fetchpatch,
6 ncurses,
7 libX11,
8}:
9
10let
11 useX11 = !stdenv.hostPlatform.isAarch32 && !stdenv.hostPlatform.isMips;
12 useNativeCompilers = !stdenv.hostPlatform.isMips;
13 inherit (lib) optional optionals optionalString;
14in
15
16stdenv.mkDerivation rec {
17 pname = "ocaml";
18 version = "4.00.1";
19
20 src = fetchurl {
21 url = "https://caml.inria.fr/pub/distrib/ocaml-4.00/${pname}-${version}.tar.bz2";
22 sha256 = "33c3f4acff51685f5bfd7c260f066645e767d4e865877bf1613c176a77799951";
23 };
24
25 # Compatibility with Glibc 2.34
26 patches = [
27 (fetchpatch {
28 url = "https://github.com/ocaml/ocaml/commit/60b0cdaf2519d881947af4175ac4c6ff68901be3.patch";
29 sha256 = "sha256:07g9q9sjk4xsbqix7jxggfp36v15pmqw4bms80g5car0hfbszirn";
30 })
31 ];
32
33 # Workaround build failure on -fno-common toolchains like upstream
34 # gcc-10. Otherwise build fails as:
35 # ld: libcamlrun.a(startup.o):(.bss+0x800): multiple definition of
36 # `caml_code_fragments_table'; libcamlrun.a(backtrace.o):(.bss+0x20): first defined here
37 env.NIX_CFLAGS_COMPILE = "-fcommon";
38
39 prefixKey = "-prefix ";
40 configureFlags = [
41 "-no-tk"
42 ]
43 ++ optionals useX11 [
44 "-x11lib"
45 libX11
46 ];
47 buildFlags = [
48 "world"
49 ]
50 ++ optionals useNativeCompilers [
51 "bootstrap"
52 "world.opt"
53 ];
54 buildInputs = [ ncurses ] ++ optionals useX11 [ libX11 ];
55 installTargets = "install" + optionalString useNativeCompilers " installopt";
56 preConfigure = ''
57 CAT=$(type -tp cat)
58 sed -e "s@/bin/cat@$CAT@" -i config/auto-aux/sharpbang
59 '';
60 postBuild = ''
61 mkdir -p $out/include
62 ln -sv $out/lib/ocaml/caml $out/include/caml
63 '';
64
65 passthru = {
66 nativeCompilers = useNativeCompilers;
67 };
68
69 meta = with lib; {
70 homepage = "http://caml.inria.fr/ocaml";
71 branch = "4.00";
72 license = with licenses; [
73 qpl # compiler
74 lgpl2 # library
75 ];
76 description = "Most popular variant of the Caml language";
77
78 longDescription = ''
79 OCaml is the most popular variant of the Caml language. From a
80 language standpoint, it extends the core Caml language with a
81 fully-fledged object-oriented layer, as well as a powerful module
82 system, all connected by a sound, polymorphic type system featuring
83 type inference.
84
85 The OCaml system is an industrial-strength implementation of this
86 language, featuring a high-performance native-code compiler (ocamlopt)
87 for 9 processor architectures (IA32, PowerPC, AMD64, Alpha, Sparc,
88 Mips, IA64, HPPA, StrongArm), as well as a bytecode compiler (ocamlc)
89 and an interactive read-eval-print loop (ocaml) for quick development
90 and portability. The OCaml distribution includes a comprehensive
91 standard library, a replay debugger (ocamldebug), lexer (ocamllex) and
92 parser (ocamlyacc) generators, a pre-processor pretty-printer (camlp4)
93 and a documentation generator (ocamldoc).
94 '';
95
96 platforms = with platforms; linux;
97 };
98
99}