1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 ocaml,
6 writeText,
7}:
8
9lib.throwIfNot (lib.versionAtLeast ocaml.version "4.03")
10 "camlidl is not available for OCaml ${ocaml.version}"
11
12 stdenv.mkDerivation
13 rec {
14 pname = "ocaml${ocaml.version}-camlidl";
15 version = "1.12";
16
17 src = fetchFromGitHub {
18 owner = "xavierleroy";
19 repo = "camlidl";
20 rev = "camlidl112";
21 hash = "sha256-ONPQMDFaU2OzFa5jgMVKx+ZRKk8ZgBZyk42vDvbM7E0=";
22 };
23
24 nativeBuildInputs = [ ocaml ];
25
26 # build fails otherwise
27 enableParallelBuilding = false;
28
29 preBuild = ''
30 mv config/Makefile.unix config/Makefile
31 substituteInPlace config/Makefile --replace BINDIR=/usr/local/bin BINDIR=$out
32 substituteInPlace config/Makefile --replace 'OCAMLLIB=$(shell $(OCAMLC) -where)' OCAMLLIB=$out/lib/ocaml/${ocaml.version}/site-lib/camlidl
33 substituteInPlace config/Makefile --replace CPP=cpp CPP=${stdenv.cc}/bin/cpp
34 substituteInPlace lib/Makefile --replace '$(OCAMLLIB)/Makefile.config' "${ocaml}/lib/ocaml/Makefile.config"
35 mkdir -p $out/lib/ocaml/${ocaml.version}/site-lib/camlidl/caml
36 mkdir -p $out/lib/ocaml/${ocaml.version}/site-lib/camlidl/stublibs
37 '';
38
39 postInstall = ''
40 cat >$out/lib/ocaml/${ocaml.version}/site-lib/camlidl/META <<EOF
41 # Courtesy of GODI
42 description = "Stub generator"
43 version = "${version}"
44 archive(byte) = "com.cma"
45 archive(native) = "com.cmxa"
46 EOF
47 mkdir -p $out/bin
48 ln -s $out/camlidl $out/bin
49 '';
50
51 setupHook = writeText "setupHook.sh" ''
52 export NIX_CFLAGS_COMPILE+=" -isystem $1/lib/ocaml/${ocaml.version}/site-lib/camlidl"
53 export NIX_LDFLAGS+=" -L $1/lib/ocaml/${ocaml.version}/site-lib/camlidl"
54 '';
55
56 meta = {
57 description = "Stub code generator and COM binding for Objective Caml";
58 mainProgram = "camlidl";
59 homepage = "https://xavierleroy.org/camlidl/";
60 license = lib.licenses.lgpl21;
61 maintainers = [ lib.maintainers.roconnor ];
62 };
63 }