Merge pull request #119126 from fabaff/pycomfoconnect
[NixPkgs.git] / pkgs / development / compilers / ocaml / generic.nix
blobd9853dd642ab1f8d0ba9c88fbf96ec025e1d370a
1 { minor_version, major_version, patch_version
2 , ...}@args:
3 let
4   versionNoPatch = "${toString major_version}.${toString minor_version}";
5   version = "${versionNoPatch}.${toString patch_version}";
6   safeX11 = stdenv: !(stdenv.isAarch32 || stdenv.isMips);
7 in
9 { lib, stdenv, fetchurl, ncurses, buildEnv, libunwind
10 , libX11, xorgproto, useX11 ? safeX11 stdenv && !lib.versionAtLeast version "4.09"
11 , aflSupport ? false
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";
21 let
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;
25   });
28 let
29    useNativeCompilers = !stdenv.isMips;
30    inherit (lib) optional optionals optionalString;
31    name = "ocaml${optionalString aflSupport "+afl"}${optionalString spaceTimeSupport "+spacetime"}${optionalString flambdaSupport "+flambda"}-${version}";
34 let
35   x11env = buildEnv { name = "x11env"; paths = [libX11 xorgproto]; };
36   x11lib = x11env + "/lib";
37   x11inc = x11env + "/include";
40 stdenv.mkDerivation (args // {
42   inherit name;
43   inherit version;
45   inherit src;
47   prefixKey = "-prefix ";
48   configureFlags =
49     let flags = new: old:
50       if lib.versionAtLeast version "4.08"
51       then new else old
52     ; in
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")
59   ;
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") ''
67     CAT=$(type -tp cat)
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"
73   '';
74   postBuild = ''
75     mkdir -p $out/include
76     ln -sv $out/lib/ocaml/caml $out/include/caml
77   '';
79   passthru = {
80     nativeCompilers = useNativeCompilers;
81   };
83   meta = with lib; {
84     homepage = "http://caml.inria.fr/ocaml";
85     branch = versionNoPatch;
86     license = with licenses; [
87       qpl /* compiler */
88       lgpl2 /* library */
89     ];
90     description = "Most popular variant of the Caml language";
92     longDescription =
93       ''
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
98         type inference.
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).
109       '';
111     platforms = with platforms; linux ++ darwin;
112     broken = stdenv.isAarch64 && !lib.versionAtLeast version "4.06";
113   };