1{ lib, stdenv, fetchurl, ocaml, findlib, ocamlbuild, topkg, ctypes, result, SDL2, pkg-config
2, AudioToolbox, Cocoa, CoreAudio, CoreVideo, ForceFeedback }:
3
4if lib.versionOlder ocaml.version "4.03"
5then throw "tsdl is not available for OCaml ${ocaml.version}"
6else
7
8let
9 pname = "tsdl";
10 version = "1.0.0";
11 webpage = "https://erratique.ch/software/${pname}";
12in
13
14stdenv.mkDerivation {
15 pname = "ocaml${ocaml.version}-${pname}";
16 inherit version;
17
18 src = fetchurl {
19 url = "${webpage}/releases/${pname}-${version}.tbz";
20 hash = "sha256-XdgzCj9Uqplt/8Jk8rSFaQf8zu+9SZa8b9ZIlW/gjyE=";
21 };
22
23 strictDeps = true;
24
25 nativeBuildInputs = [ pkg-config ocaml findlib ocamlbuild topkg ];
26 buildInputs = [ topkg ];
27 propagatedBuildInputs = [ SDL2 ctypes ]
28 ++ lib.optionals stdenv.isDarwin [ AudioToolbox Cocoa CoreAudio CoreVideo ForceFeedback ];
29
30 preConfigure = ''
31 # The following is done to avoid an additional dependency (ncurses)
32 # due to linking in the custom bytecode runtime. Instead, just
33 # compile directly into a native binary, even if it's just a
34 # temporary build product.
35 substituteInPlace myocamlbuild.ml \
36 --replace ".byte" ".native"
37 '';
38
39 inherit (topkg) buildPhase installPhase;
40
41 meta = with lib; {
42 homepage = webpage;
43 description = "Thin bindings to the cross-platform SDL library";
44 license = licenses.isc;
45 inherit (ocaml.meta) platforms;
46 };
47}