about summary refs log tree commit diff
path: root/pkgs/build-support/ocaml/oasis.nix
blob: ad1ba065ef720bdfbf205f595f46425be4448e9c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{ stdenv, ocaml_oasis, ocaml, findlib, ocamlbuild, camlp4 }:

{ name, version, buildInputs ? [], meta ? { platforms = ocaml.meta.platforms or []; },
  minimumOcamlVersion ? null,
  createFindlibDestdir ? true,
  dontStrip ? true,
  hasSharedObjects ? false,
  setupHook ? null,
  ...
}@args:

 assert minimumOcamlVersion != null ->
          stdenv.lib.versionOlder minimumOcamlVersion ocaml.version;

stdenv.mkDerivation (args // {
  name = "ocaml-${name}-${version}";

  buildInputs = [ ocaml findlib ocamlbuild camlp4 ocaml_oasis ] ++ buildInputs;

  inherit createFindlibDestdir;
  inherit dontStrip;

  buildPhase = ''
    runHook preBuild
    oasis setup
    ocaml setup.ml -configure
    ocaml setup.ml -build
    runHook postBuild
  '';

  checkPhase = ''
    runHook preCheck
    ocaml setup.ml -test
    runHook postCheck
  '';

  installPhase = ''
    runHook preInstall
    mkdir -p $out
    sed -i s+/usr/local+$out+g setup.ml
    sed -i s+/usr/local+$out+g setup.data
    prefix=$OCAMLFIND_DESTDIR ocaml setup.ml -install
    runHook postInstall
  '';

  setupHook = if setupHook == null && hasSharedObjects
              then stdenv.writeText "setupHook.sh" ''
              export CAML_LD_LIBRARY_PATH="''${CAML_LD_LIBRARY_PATH}''${CAML_LD_LIBRARY_PATH:+:}''$1/lib/ocaml/${ocaml.version}/site-lib/${name}/"
              ''
              else setupHook;

})