myocamlbuild.ml 2.7 KB
Newer Older
fpottier's avatar
fpottier committed
1 2 3 4 5 6 7 8 9
open Ocamlbuild_plugin
open Command

(* ---------------------------------------------------------------------------- *)

(* Compilation flags. *)

let flags () =
  (* -inline 1000 *)
10
  flag ["ocaml"; "compile"; "native"] (S [A "-inline"; A "1000"]);
POTTIER Francois's avatar
POTTIER Francois committed
11 12
  (* -noassert *)
  flag ["ocaml"; "compile"; "noassert"] (S [A "-noassert"]);
13
  (* nazi warnings *)
14
  flag ["ocaml"; "compile"; "my_warnings"] (S[A "-w"; A "@1..49-4-9-41-44"])
fpottier's avatar
fpottier committed
15 16 17 18 19 20 21 22 23

(* ---------------------------------------------------------------------------- *)

(* Dealing with the two parsers. *)

(* Just for fun, Menhir comes with two parsers for its own input files. One is
   called [yacc-parser.mly] and is built using [ocamlyacc]. The other is called
   [fancy-parser.mly] and is built using Menhir. It depends on [standard.mly].
   The choice between the two parsers is determined by the presence of the tag
24
   [fancy_parser]. *)
fpottier's avatar
fpottier committed
25 26

let parser_rule () =
27 28 29 30 31 32 33
  let source =
    mark_tag_used "fancy_parser";
    if Tags.mem "fancy_parser" (tags_of_pathname "")
    then "fancy-parser.mly"
    else "yacc-parser.mly"
  in
  copy_rule "create parser.mly" source "parser.mly"
fpottier's avatar
fpottier committed
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 69 70 71 72 73 74 75 76
let driver_rule () =
  (* The source file is either [yaccDriver.ml] or [fancyDriver.ml], depending
     on which tag is (globally) present: [yacc_parser] or [fancy_parser]. *)
  let source =
    if Tags.mem "yacc_parser" (tags_of_pathname "")
    then "yaccDriver.ml"
    else "fancyDriver.ml"
  in
  (* The target file is [Driver.ml]. *)
  let target =
    "Driver.ml"
  in
  (* A copy rule. *)
  copy_rule "create Driver.ml" source target

(* ---------------------------------------------------------------------------- *)

(* The file [FancyParserMessages.ml] is generated by Menhir based on
   [fancy-parser.messages], which is maintained by hand. Of course,
   this is possible only in stage 2 of the bootstrap process, since
   Menhir is required. *)

let messages_rule () =
  if Tags.mem "fancy_parser" (tags_of_pathname "") then
    (* The target. *)
    let prod = "FancyParserMessages.ml" in
    (* The two source files. *)
    let messages = "fancy-parser.messages"
    and grammar = "parser.mly" in
    (* The production rule. *)
    rule
      "fancy parser messages"
      ~prod:prod
      ~deps:[ messages; grammar ]
      (fun env _ ->
        Cmd(S[
          !Options.ocamlyacc; (* menhir *)
          P (env grammar);
          A "--compile-errors"; P (env messages);
          Sh ">"; Px (env prod);
        ]))

fpottier's avatar
fpottier committed
77 78 79 80 81 82 83 84
(* ---------------------------------------------------------------------------- *)

(* Define custom compilation rules. *)

let () =
  dispatch (function After_rules ->
    (* Add our rules after the standard ones. *)
    parser_rule();
85 86
    driver_rule();
    messages_rule();
fpottier's avatar
fpottier committed
87 88 89
    flags();
  | _ -> ()
  )