-
Notifications
You must be signed in to change notification settings - Fork 6
/
myocamlbuild.ml
67 lines (59 loc) · 2.09 KB
/
myocamlbuild.ml
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
(* OASIS_START *)
(* OASIS_STOP *)
open Ocamlbuild_plugin
module Menhir = struct
let menhir () =
if !Options.ocamlyacc = N then V"MENHIR" else !Options.ocamlyacc
let menhir_tags mly =
tags_of_pathname mly ++"ocaml"++"parser"++"menhir"
let menhir_produce_messages env build =
let messages, mly = env "%.messages", env "%.mly" in
let open Ocamlbuild_pack in
Ocaml_compiler.prepare_compile build mly;
Cmd(S[menhir (); T (menhir_tags mly);
A "--list-errors"; P mly; Sh ">"; Px messages])
let menhir_compile_messages env build =
let mly = env "%.mly" in
let messages = env "%.messages" in
let target = env "%_messages.ml" in
Cmd(S[menhir (); T (menhir_tags mly); P mly;
A "--compile-errors"; P messages;
Sh ">"; Px target])
let menhir_update_messages env build =
let mly = env "%.mly" in
let messages = env "%.messages" in
let tmp = Filename.temp_file "menhir" ".messages" in
Seq [
Cmd(S[menhir (); T (menhir_tags mly); P mly;
A "--update-errors"; P messages;
Sh ">"; P tmp]);
Cmd(S[A "mv"; P tmp; P messages]);
]
let dispatcher = function
| After_rules ->
flag ["menhir"; "parser"; "menhir_trace"] (A"--trace");
flag ["menhir"; "parser"; "menhir_table"] (A "--table");
flag ["menhir"; "parser"; "menhir_canonical"] (A"--canonical");
rule "menhir: .mly -> .messages"
~prod:"%.messages"
~deps:["%.mly"]
menhir_produce_messages;
rule "menhir: .mly & .messages -> _messages.ml"
~prod:"%_messages.ml"
~deps:["%.mly"; "%.messages"]
menhir_compile_messages;
rule "menhir: .mly & .messages -> .messages & .messages.update"
~stamp:"%.messages.update"
~deps:["%.mly"; "%.messages"]
menhir_update_messages;
| _ -> ()
end
let _ =
dispatch
(fun hook ->
dispatch_default hook;
Menhir.dispatcher hook;
Ocamlbuild_js_of_ocaml.dispatcher
~oasis_executables:["web.byte"]
hook;
)