1 { minor_version, major_version, patch_version
4 versionNoPatch = "${toString major_version}.${toString minor_version}";
5 version = "${versionNoPatch}.${toString patch_version}";
6 safeX11 = stdenv: !(stdenv.isAarch32 || stdenv.isMips);
9 { lib, stdenv, fetchurl, ncurses, buildEnv, libunwind
10 , libX11, xorgproto, useX11 ? safeX11 stdenv && !lib.versionAtLeast version "4.09"
12 , flambdaSupport ? false
13 , spaceTimeSupport ? false
16 assert useX11 -> !stdenv.isAarch32 && !stdenv.isMips;
17 assert aflSupport -> lib.versionAtLeast version "4.05";
18 assert flambdaSupport -> lib.versionAtLeast version "4.03";
19 assert spaceTimeSupport -> lib.versionAtLeast version "4.04";
22 src = args.src or (fetchurl {
23 url = args.url or "http://caml.inria.fr/pub/distrib/ocaml-${versionNoPatch}/ocaml-${version}.tar.xz";
24 inherit (args) sha256;
29 useNativeCompilers = !stdenv.isMips;
30 inherit (lib) optional optionals optionalString;
31 name = "ocaml${optionalString aflSupport "+afl"}${optionalString spaceTimeSupport "+spacetime"}${optionalString flambdaSupport "+flambda"}-${version}";
35 x11env = buildEnv { name = "x11env"; paths = [libX11 xorgproto]; };
36 x11lib = x11env + "/lib";
37 x11inc = x11env + "/include";
40 stdenv.mkDerivation (args // {
47 prefixKey = "-prefix ";
50 if lib.versionAtLeast version "4.08"
53 optionals useX11 (flags
54 [ "--x-libraries=${x11lib}" "--x-includes=${x11inc}"]
55 [ "-x11lib" x11lib "-x11include" x11inc ])
56 ++ optional aflSupport (flags "--with-afl" "-afl-instrument")
57 ++ optional flambdaSupport (flags "--enable-flambda" "-flambda")
58 ++ optional spaceTimeSupport (flags "--enable-spacetime" "-spacetime")
61 buildFlags = [ "world" ] ++ optionals useNativeCompilers [ "bootstrap" "world.opt" ];
62 buildInputs = optional (!lib.versionAtLeast version "4.07") ncurses
63 ++ optionals useX11 [ libX11 xorgproto ];
64 propagatedBuildInputs = optional spaceTimeSupport libunwind;
65 installTargets = [ "install" ] ++ optional useNativeCompilers "installopt";
66 preConfigure = optionalString (!lib.versionAtLeast version "4.04") ''
68 sed -e "s@/bin/cat@$CAT@" -i config/auto-aux/sharpbang
69 '' + optionalString (stdenv.isDarwin && stdenv.isAarch64) ''
70 # Do what upstream does by default now: https://github.com/ocaml/ocaml/pull/10176
71 # This is required for aarch64-darwin, everything else works as is.
72 AS="${stdenv.cc}/bin/cc -c" ASPP="${stdenv.cc}/bin/cc -c"
76 ln -sv $out/lib/ocaml/caml $out/include/caml
80 nativeCompilers = useNativeCompilers;
84 homepage = "http://caml.inria.fr/ocaml";
85 branch = versionNoPatch;
86 license = with licenses; [
90 description = "Most popular variant of the Caml language";
94 OCaml is the most popular variant of the Caml language. From a
95 language standpoint, it extends the core Caml language with a
96 fully-fledged object-oriented layer, as well as a powerful module
97 system, all connected by a sound, polymorphic type system featuring
100 The OCaml system is an industrial-strength implementation of this
101 language, featuring a high-performance native-code compiler (ocamlopt)
102 for 9 processor architectures (IA32, PowerPC, AMD64, Alpha, Sparc,
103 Mips, IA64, HPPA, StrongArm), as well as a bytecode compiler (ocamlc)
104 and an interactive read-eval-print loop (ocaml) for quick development
105 and portability. The OCaml distribution includes a comprehensive
106 standard library, a replay debugger (ocamldebug), lexer (ocamllex) and
107 parser (ocamlyacc) generators, a pre-processor pretty-printer (camlp4)
108 and a documentation generator (ocamldoc).
111 platforms = with platforms; linux ++ darwin;
112 broken = stdenv.isAarch64 && !lib.versionAtLeast version "4.06";