summary refs log tree commit diff
path: root/pkgs/development/tools/ocaml/findlib/default.nix
blob: e7abf32eae5ffe9359870b7bf80c068c3d98dde8 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{ lib, stdenv, fetchurl, fetchpatch, m4, ncurses, ocaml, writeText }:

stdenv.mkDerivation rec {
  pname = "ocaml-findlib";
  version = "1.9.1";

  src = fetchurl {
    url = "http://download.camlcity.org/download/findlib-${version}.tar.gz";
    sha256 = "sha256-K0K4vVRIjWTEvzy3BUtLN70wwdwSvUMeoeTXrYqYD+I=";
  };

  nativeBuildInputs = [m4 ocaml];
  buildInputs = [ ncurses ];

  patches = [ ./ldconf.patch ./install_topfind.patch ];

  dontAddPrefix=true;
  dontAddStaticConfigureFlags = true;
  configurePlatforms = [];

  configureFlags = [
      "-bindir" "${placeholder "out"}/bin"
      "-mandir" "${placeholder "out"}/share/man"
      "-sitelib" "${placeholder "out"}/lib/ocaml/${ocaml.version}/site-lib"
      "-config" "${placeholder "out"}/etc/findlib.conf"
  ];

  buildFlags = [ "all" "opt" ];

  setupHook = writeText "setupHook.sh" ''
    addOCamlPath () {
        if test -d "''$1/lib/ocaml/${ocaml.version}/site-lib"; then
            export OCAMLPATH="''${OCAMLPATH-}''${OCAMLPATH:+:}''$1/lib/ocaml/${ocaml.version}/site-lib/"
        fi
        if test -d "''$1/lib/ocaml/${ocaml.version}/site-lib/stublibs"; then
            export CAML_LD_LIBRARY_PATH="''${CAML_LD_LIBRARY_PATH-}''${CAML_LD_LIBRARY_PATH:+:}''$1/lib/ocaml/${ocaml.version}/site-lib/stublibs"
        fi
    }
    exportOcamlDestDir () {
        export OCAMLFIND_DESTDIR="''$out/lib/ocaml/${ocaml.version}/site-lib/"
    }
    createOcamlDestDir () {
        if test -n "''${createFindlibDestdir-}"; then
          mkdir -p $OCAMLFIND_DESTDIR
        fi
    }

    # run for every buildInput
    addEnvHooks "$targetOffset" addOCamlPath
    # run before installPhase, even without buildInputs, and not in nix-shell
    preInstallHooks+=(createOcamlDestDir)
    # run even in nix-shell, and even without buildInputs
    addEnvHooks "$hostOffset" exportOcamlDestDir
  '';

  meta = {
    homepage = "http://projects.camlcity.org/projects/findlib.html";
    description = "O'Caml library manager";
    license = lib.licenses.mit;
    platforms = ocaml.meta.platforms or [];
    maintainers = [
      lib.maintainers.maggesi
      lib.maintainers.vbmithr
    ];
  };
}