1{
2 lib,
3 stdenv,
4 fetchzip,
5 which,
6 ocaml,
7 camlp-streams,
8 ocamlbuild,
9 findlib,
10}:
11
12if lib.versionAtLeast ocaml.version "5.4" then
13 throw "camlp4 is not available for OCaml ${ocaml.version}"
14else
15
16 let
17 param =
18 {
19 "4.02" = {
20 version = "4.02+6";
21 sha256 = "06yl4q0qazl7g25b0axd1gdkfd4qpqzs1gr5fkvmkrcbz113h1hj";
22 };
23 "4.03" = {
24 version = "4.03+1";
25 sha256 = "1f2ndch6f1m4fgnxsjb94qbpwjnjgdlya6pard44y6n0dqxi1wsq";
26 };
27 "4.04" = {
28 version = "4.04+1";
29 sha256 = "1ad7rygqjxrc1im95gw9lp8q83nhdaf383f2808f1p63yl42xm7k";
30 };
31 "4.05" = {
32 version = "4.05+1";
33 sha256 = "0wm795hpwvwpib9c9z6p8kw2fh7p7b2hml6g15z8zry3y7w738sv";
34 };
35 "4.06" = {
36 version = "4.06+1";
37 sha256 = "0fazfw2l7wdmbwnqc22xby5n4ri1wz27lw9pfzhsbcdrighykysf";
38 };
39 "4.07" = {
40 version = "4.07+1";
41 sha256 = "0cxl4hkqcvspvkx4f2k83217rh6051fll9i2yz7cw6m3bq57mdvl";
42 };
43 "4.08" = {
44 version = "4.08+1";
45 sha256 = "0qplawvxwai25bi27niw2cgz2al01kcnkj8wxwhxslpi21z6pyx1";
46 };
47 "4.09" = {
48 version = "4.09+1";
49 sha256 = "1gr33x6xs1rs0bpyq4vzyfxd6vn47jfkg8imi81db2r0cbs0kxx1";
50 };
51 "4.10" = {
52 version = "4.10+1";
53 sha256 = "093bc1c28wid5li0jwglnd4p3csxw09fmbs9ffybq2z41a5mgay6";
54 };
55 "4.11" = {
56 version = "4.11+1";
57 sha256 = "0sn7f6im940qh0ixmx1k738xrwwdvy9g7r19bv5218jb6mh0g068";
58 };
59 "4.12" = {
60 version = "4.12+1";
61 sha256 = "1cfk5ppnd511vzsr9gc0grxbafmh0m3m897aij198rppzxps5kyz";
62 };
63 "4.13" = {
64 version = "4.13+1";
65 sha256 = "0fzxa1zdhk74mlxpin7p90flks6sp4gkc0mfclmj9zak15rii55n";
66 };
67 "4.14" = {
68 version = "4.14+1";
69 sha256 = "sha256-cPN3GioZT/Zt6uzbjGUPEGVJcPQdsAnCkU/AQoPfvuo=";
70 };
71 "5.0" = {
72 version = "5.0";
73 sha256 = "sha256-oZptFNPUEAq5YlcqAoDWfLghGMF9AN7E7hUN55SAX+4=";
74 };
75 "5.1" = {
76 version = "5.1";
77 sha256 = "sha256-Ubedjg3BeHA0bJbEalQN9eEk5+LRAI/er+8mWfVYchg=";
78 };
79 "5.2" = {
80 version = "5.2";
81 sha256 = "sha256-lzbc9xsgeYlbVf71O+PWYS14QivAH1aPdnvWhe0HHME=";
82 };
83 "5.3" = {
84 version = "5.3";
85 sha256 = "sha256-V/kKhTP9U4jWDFuQKuB7BS3XICg1lq/2Avj7UJR55+k=";
86 };
87 }
88 .${ocaml.meta.branch};
89 in
90
91 stdenv.mkDerivation rec {
92 pname = "camlp4";
93 inherit (param) version;
94
95 src = fetchzip {
96 url = "https://github.com/ocaml/camlp4/archive/${version}.tar.gz";
97 inherit (param) sha256;
98 };
99
100 strictDeps = true;
101
102 nativeBuildInputs = [
103 which
104 ocaml
105 ocamlbuild
106 ]
107 ++ lib.optionals (lib.versionAtLeast ocaml.version "5.0") [
108 findlib
109 ];
110
111 buildInputs = lib.optionals (lib.versionAtLeast ocaml.version "5.0") [
112 camlp-streams
113 ocamlbuild
114 ];
115
116 # build fails otherwise
117 enableParallelBuilding = false;
118
119 dontAddPrefix = true;
120
121 preConfigure = ''
122 # increase stack space for spacetime variant of the compiler
123 # https://github.com/ocaml/ocaml/issues/7435
124 # but disallowed by darwin sandbox
125 ulimit -s unlimited || true
126
127 configureFlagsArray=(
128 --bindir=$out/bin
129 --libdir=$out/lib/ocaml/${ocaml.version}/site-lib
130 --pkgdir=$out/lib/ocaml/${ocaml.version}/site-lib
131 )
132 '';
133
134 postConfigure = ''
135 substituteInPlace camlp4/META.in \
136 --replace +camlp4 $out/lib/ocaml/${ocaml.version}/site-lib/camlp4
137 '';
138
139 makeFlags = [ "all" ];
140
141 installTargets = [
142 "install"
143 "install-META"
144 ];
145
146 dontStrip = true;
147
148 meta = with lib; {
149 description = "Software system for writing extensible parsers for programming languages";
150 homepage = "https://github.com/ocaml/camlp4";
151 platforms = ocaml.meta.platforms or [ ];
152 };
153 }