Blame myocamlbuild.ml

Packit 9ff65e
(* OASIS_START *)
Packit 9ff65e
(* DO NOT EDIT (digest: 2ff2fa208b8292955ad39dda4ee05185) *)
Packit 9ff65e
module OASISGettext = struct
Packit 9ff65e
(* # 22 "src/oasis/OASISGettext.ml" *)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let ns_ str = str
Packit 9ff65e
  let s_ str = str
Packit 9ff65e
  let f_ (str: ('a, 'b, 'c, 'd) format4) = str
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let fn_ fmt1 fmt2 n =
Packit 9ff65e
    if n = 1 then
Packit 9ff65e
      fmt1^^""
Packit 9ff65e
    else
Packit 9ff65e
      fmt2^^""
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let init = []
Packit 9ff65e
end
Packit 9ff65e
Packit 9ff65e
module OASISString = struct
Packit 9ff65e
(* # 22 "src/oasis/OASISString.ml" *)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  (** Various string utilities.
Packit 9ff65e
Packit 9ff65e
      Mostly inspired by extlib and batteries ExtString and BatString libraries.
Packit 9ff65e
Packit 9ff65e
      @author Sylvain Le Gall
Packit 9ff65e
  *)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let nsplitf str f =
Packit 9ff65e
    if str = "" then
Packit 9ff65e
      []
Packit 9ff65e
    else
Packit 9ff65e
      let buf = Buffer.create 13 in
Packit 9ff65e
      let lst = ref [] in
Packit 9ff65e
      let push () =
Packit 9ff65e
        lst := Buffer.contents buf :: !lst;
Packit 9ff65e
        Buffer.clear buf
Packit 9ff65e
      in
Packit 9ff65e
      let str_len = String.length str in
Packit 9ff65e
      for i = 0 to str_len - 1 do
Packit 9ff65e
        if f str.[i] then
Packit 9ff65e
          push ()
Packit 9ff65e
        else
Packit 9ff65e
          Buffer.add_char buf str.[i]
Packit 9ff65e
      done;
Packit 9ff65e
      push ();
Packit 9ff65e
      List.rev !lst
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  (** [nsplit c s] Split the string [s] at char [c]. It doesn't include the
Packit 9ff65e
      separator.
Packit 9ff65e
  *)
Packit 9ff65e
  let nsplit str c =
Packit 9ff65e
    nsplitf str ((=) c)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let find ~what ?(offset=0) str =
Packit 9ff65e
    let what_idx = ref 0 in
Packit 9ff65e
    let str_idx = ref offset in
Packit 9ff65e
    while !str_idx < String.length str &&
Packit 9ff65e
          !what_idx < String.length what do
Packit 9ff65e
      if str.[!str_idx] = what.[!what_idx] then
Packit 9ff65e
        incr what_idx
Packit 9ff65e
      else
Packit 9ff65e
        what_idx := 0;
Packit 9ff65e
      incr str_idx
Packit 9ff65e
    done;
Packit 9ff65e
    if !what_idx <> String.length what then
Packit 9ff65e
      raise Not_found
Packit 9ff65e
    else
Packit 9ff65e
      !str_idx - !what_idx
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let sub_start str len =
Packit 9ff65e
    let str_len = String.length str in
Packit 9ff65e
    if len >= str_len then
Packit 9ff65e
      ""
Packit 9ff65e
    else
Packit 9ff65e
      String.sub str len (str_len - len)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let sub_end ?(offset=0) str len =
Packit 9ff65e
    let str_len = String.length str in
Packit 9ff65e
    if len >= str_len then
Packit 9ff65e
      ""
Packit 9ff65e
    else
Packit 9ff65e
      String.sub str 0 (str_len - len)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let starts_with ~what ?(offset=0) str =
Packit 9ff65e
    let what_idx = ref 0 in
Packit 9ff65e
    let str_idx = ref offset in
Packit 9ff65e
    let ok = ref true in
Packit 9ff65e
    while !ok &&
Packit 9ff65e
          !str_idx < String.length str &&
Packit 9ff65e
          !what_idx < String.length what do
Packit 9ff65e
      if str.[!str_idx] = what.[!what_idx] then
Packit 9ff65e
        incr what_idx
Packit 9ff65e
      else
Packit 9ff65e
        ok := false;
Packit 9ff65e
      incr str_idx
Packit 9ff65e
    done;
Packit 9ff65e
    !what_idx = String.length what
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let strip_starts_with ~what str =
Packit 9ff65e
    if starts_with ~what str then
Packit 9ff65e
      sub_start str (String.length what)
Packit 9ff65e
    else
Packit 9ff65e
      raise Not_found
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let ends_with ~what ?(offset=0) str =
Packit 9ff65e
    let what_idx = ref ((String.length what) - 1) in
Packit 9ff65e
    let str_idx = ref ((String.length str) - 1) in
Packit 9ff65e
    let ok = ref true in
Packit 9ff65e
    while !ok &&
Packit 9ff65e
          offset <= !str_idx &&
Packit 9ff65e
          0 <= !what_idx do
Packit 9ff65e
      if str.[!str_idx] = what.[!what_idx] then
Packit 9ff65e
        decr what_idx
Packit 9ff65e
      else
Packit 9ff65e
        ok := false;
Packit 9ff65e
      decr str_idx
Packit 9ff65e
    done;
Packit 9ff65e
    !what_idx = -1
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let strip_ends_with ~what str =
Packit 9ff65e
    if ends_with ~what str then
Packit 9ff65e
      sub_end str (String.length what)
Packit 9ff65e
    else
Packit 9ff65e
      raise Not_found
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let replace_chars f s =
Packit 9ff65e
    let buf = Buffer.create (String.length s) in
Packit 9ff65e
    String.iter (fun c -> Buffer.add_char buf (f c)) s;
Packit 9ff65e
    Buffer.contents buf
Packit 9ff65e
Packit 9ff65e
  let lowercase_ascii =
Packit 9ff65e
    replace_chars
Packit 9ff65e
      (fun c ->
Packit 9ff65e
         if (c >= 'A' && c <= 'Z') then
Packit 9ff65e
           Char.chr (Char.code c + 32)
Packit 9ff65e
         else
Packit 9ff65e
           c)
Packit 9ff65e
Packit 9ff65e
  let uncapitalize_ascii s =
Packit 9ff65e
    if s <> "" then
Packit 9ff65e
      (lowercase_ascii (String.sub s 0 1)) ^ (String.sub s 1 ((String.length s) - 1))
Packit 9ff65e
    else
Packit 9ff65e
      s
Packit 9ff65e
Packit 9ff65e
  let uppercase_ascii =
Packit 9ff65e
    replace_chars
Packit 9ff65e
      (fun c ->
Packit 9ff65e
         if (c >= 'a' && c <= 'z') then
Packit 9ff65e
           Char.chr (Char.code c - 32)
Packit 9ff65e
         else
Packit 9ff65e
           c)
Packit 9ff65e
Packit 9ff65e
  let capitalize_ascii s =
Packit 9ff65e
    if s <> "" then
Packit 9ff65e
      (uppercase_ascii (String.sub s 0 1)) ^ (String.sub s 1 ((String.length s) - 1))
Packit 9ff65e
    else
Packit 9ff65e
      s
Packit 9ff65e
Packit 9ff65e
end
Packit 9ff65e
Packit 9ff65e
module OASISUtils = struct
Packit 9ff65e
(* # 22 "src/oasis/OASISUtils.ml" *)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  open OASISGettext
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  module MapExt =
Packit 9ff65e
  struct
Packit 9ff65e
    module type S =
Packit 9ff65e
    sig
Packit 9ff65e
      include Map.S
Packit 9ff65e
      val add_list: 'a t -> (key * 'a) list -> 'a t
Packit 9ff65e
      val of_list: (key * 'a) list -> 'a t
Packit 9ff65e
      val to_list: 'a t -> (key * 'a) list
Packit 9ff65e
    end
Packit 9ff65e
Packit 9ff65e
    module Make (Ord: Map.OrderedType) =
Packit 9ff65e
    struct
Packit 9ff65e
      include Map.Make(Ord)
Packit 9ff65e
Packit 9ff65e
      let rec add_list t =
Packit 9ff65e
        function
Packit 9ff65e
          | (k, v) :: tl -> add_list (add k v t) tl
Packit 9ff65e
          | [] -> t
Packit 9ff65e
Packit 9ff65e
      let of_list lst = add_list empty lst
Packit 9ff65e
Packit 9ff65e
      let to_list t = fold (fun k v acc -> (k, v) :: acc) t []
Packit 9ff65e
    end
Packit 9ff65e
  end
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  module MapString = MapExt.Make(String)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  module SetExt  =
Packit 9ff65e
  struct
Packit 9ff65e
    module type S =
Packit 9ff65e
    sig
Packit 9ff65e
      include Set.S
Packit 9ff65e
      val add_list: t -> elt list -> t
Packit 9ff65e
      val of_list: elt list -> t
Packit 9ff65e
      val to_list: t -> elt list
Packit 9ff65e
    end
Packit 9ff65e
Packit 9ff65e
    module Make (Ord: Set.OrderedType) =
Packit 9ff65e
    struct
Packit 9ff65e
      include Set.Make(Ord)
Packit 9ff65e
Packit 9ff65e
      let rec add_list t =
Packit 9ff65e
        function
Packit 9ff65e
          | e :: tl -> add_list (add e t) tl
Packit 9ff65e
          | [] -> t
Packit 9ff65e
Packit 9ff65e
      let of_list lst = add_list empty lst
Packit 9ff65e
Packit 9ff65e
      let to_list = elements
Packit 9ff65e
    end
Packit 9ff65e
  end
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  module SetString = SetExt.Make(String)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let compare_csl s1 s2 =
Packit 9ff65e
    String.compare (OASISString.lowercase_ascii s1) (OASISString.lowercase_ascii s2)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  module HashStringCsl =
Packit 9ff65e
    Hashtbl.Make
Packit 9ff65e
      (struct
Packit 9ff65e
         type t = string
Packit 9ff65e
         let equal s1 s2 = (compare_csl s1 s2) = 0
Packit 9ff65e
         let hash s = Hashtbl.hash (OASISString.lowercase_ascii s)
Packit 9ff65e
       end)
Packit 9ff65e
Packit 9ff65e
  module SetStringCsl =
Packit 9ff65e
    SetExt.Make
Packit 9ff65e
      (struct
Packit 9ff65e
         type t = string
Packit 9ff65e
         let compare = compare_csl
Packit 9ff65e
       end)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let varname_of_string ?(hyphen='_') s =
Packit 9ff65e
    if String.length s = 0 then
Packit 9ff65e
      begin
Packit 9ff65e
        invalid_arg "varname_of_string"
Packit 9ff65e
      end
Packit 9ff65e
    else
Packit 9ff65e
      begin
Packit 9ff65e
        let buf =
Packit 9ff65e
          OASISString.replace_chars
Packit 9ff65e
            (fun c ->
Packit 9ff65e
               if ('a' <= c && c <= 'z')
Packit 9ff65e
                 ||
Packit 9ff65e
                  ('A' <= c && c <= 'Z')
Packit 9ff65e
                 ||
Packit 9ff65e
                  ('0' <= c && c <= '9') then
Packit 9ff65e
                 c
Packit 9ff65e
               else
Packit 9ff65e
                 hyphen)
Packit 9ff65e
            s;
Packit 9ff65e
        in
Packit 9ff65e
        let buf =
Packit 9ff65e
          (* Start with a _ if digit *)
Packit 9ff65e
          if '0' <= s.[0] && s.[0] <= '9' then
Packit 9ff65e
            "_"^buf
Packit 9ff65e
          else
Packit 9ff65e
            buf
Packit 9ff65e
        in
Packit 9ff65e
          OASISString.lowercase_ascii buf
Packit 9ff65e
      end
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let varname_concat ?(hyphen='_') p s =
Packit 9ff65e
    let what = String.make 1 hyphen in
Packit 9ff65e
    let p =
Packit 9ff65e
      try
Packit 9ff65e
        OASISString.strip_ends_with ~what p
Packit 9ff65e
      with Not_found ->
Packit 9ff65e
        p
Packit 9ff65e
    in
Packit 9ff65e
    let s =
Packit 9ff65e
      try
Packit 9ff65e
        OASISString.strip_starts_with ~what s
Packit 9ff65e
      with Not_found ->
Packit 9ff65e
        s
Packit 9ff65e
    in
Packit 9ff65e
      p^what^s
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let is_varname str =
Packit 9ff65e
    str = varname_of_string str
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let failwithf fmt = Printf.ksprintf failwith fmt
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let rec file_location ?pos1 ?pos2 ?lexbuf () =
Packit 9ff65e
      match pos1, pos2, lexbuf with
Packit 9ff65e
      | Some p, None, _ | None, Some p, _ ->
Packit 9ff65e
        file_location ~pos1:p ~pos2:p ?lexbuf ()
Packit 9ff65e
      | Some p1, Some p2, _ ->
Packit 9ff65e
        let open Lexing in
Packit 9ff65e
        let fn, lineno = p1.pos_fname, p1.pos_lnum in
Packit 9ff65e
        let c1 = p1.pos_cnum - p1.pos_bol in
Packit 9ff65e
        let c2 = c1 + (p2.pos_cnum - p1.pos_cnum) in
Packit 9ff65e
        Printf.sprintf (f_ "file %S, line %d, characters %d-%d")  fn lineno c1 c2
Packit 9ff65e
      | _, _, Some lexbuf ->
Packit 9ff65e
        file_location
Packit 9ff65e
          ~pos1:(Lexing.lexeme_start_p lexbuf)
Packit 9ff65e
          ~pos2:(Lexing.lexeme_end_p lexbuf)
Packit 9ff65e
          ()
Packit 9ff65e
      | None, None, None ->
Packit 9ff65e
        s_ "<position undefined>"
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let failwithpf ?pos1 ?pos2 ?lexbuf fmt =
Packit 9ff65e
    let loc = file_location ?pos1 ?pos2 ?lexbuf () in
Packit 9ff65e
    Printf.ksprintf (fun s -> failwith (Printf.sprintf "%s: %s" loc s)) fmt
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
end
Packit 9ff65e
Packit 9ff65e
module OASISExpr = struct
Packit 9ff65e
(* # 22 "src/oasis/OASISExpr.ml" *)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  open OASISGettext
Packit 9ff65e
  open OASISUtils
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  type test = string
Packit 9ff65e
  type flag = string
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  type t =
Packit 9ff65e
    | EBool of bool
Packit 9ff65e
    | ENot of t
Packit 9ff65e
    | EAnd of t * t
Packit 9ff65e
    | EOr of t * t
Packit 9ff65e
    | EFlag of flag
Packit 9ff65e
    | ETest of test * string
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  type 'a choices = (t * 'a) list
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let eval var_get t =
Packit 9ff65e
    let rec eval' =
Packit 9ff65e
      function
Packit 9ff65e
        | EBool b ->
Packit 9ff65e
            b
Packit 9ff65e
Packit 9ff65e
        | ENot e ->
Packit 9ff65e
            not (eval' e)
Packit 9ff65e
Packit 9ff65e
        | EAnd (e1, e2) ->
Packit 9ff65e
            (eval' e1) && (eval' e2)
Packit 9ff65e
Packit 9ff65e
        | EOr (e1, e2) ->
Packit 9ff65e
            (eval' e1) || (eval' e2)
Packit 9ff65e
Packit 9ff65e
        | EFlag nm ->
Packit 9ff65e
            let v =
Packit 9ff65e
              var_get nm
Packit 9ff65e
            in
Packit 9ff65e
              assert(v = "true" || v = "false");
Packit 9ff65e
              (v = "true")
Packit 9ff65e
Packit 9ff65e
        | ETest (nm, vl) ->
Packit 9ff65e
            let v =
Packit 9ff65e
              var_get nm
Packit 9ff65e
            in
Packit 9ff65e
              (v = vl)
Packit 9ff65e
    in
Packit 9ff65e
      eval' t
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let choose ?printer ?name var_get lst =
Packit 9ff65e
    let rec choose_aux =
Packit 9ff65e
      function
Packit 9ff65e
        | (cond, vl) :: tl ->
Packit 9ff65e
            if eval var_get cond then
Packit 9ff65e
              vl
Packit 9ff65e
            else
Packit 9ff65e
              choose_aux tl
Packit 9ff65e
        | [] ->
Packit 9ff65e
            let str_lst =
Packit 9ff65e
              if lst = [] then
Packit 9ff65e
                s_ "<empty>"
Packit 9ff65e
              else
Packit 9ff65e
                String.concat
Packit 9ff65e
                  (s_ ", ")
Packit 9ff65e
                  (List.map
Packit 9ff65e
                     (fun (cond, vl) ->
Packit 9ff65e
                        match printer with
Packit 9ff65e
                          | Some p -> p vl
Packit 9ff65e
                          | None -> s_ "<no printer>")
Packit 9ff65e
                     lst)
Packit 9ff65e
            in
Packit 9ff65e
              match name with
Packit 9ff65e
                | Some nm ->
Packit 9ff65e
                    failwith
Packit 9ff65e
                      (Printf.sprintf
Packit 9ff65e
                         (f_ "No result for the choice list '%s': %s")
Packit 9ff65e
                         nm str_lst)
Packit 9ff65e
                | None ->
Packit 9ff65e
                    failwith
Packit 9ff65e
                      (Printf.sprintf
Packit 9ff65e
                         (f_ "No result for a choice list: %s")
Packit 9ff65e
                         str_lst)
Packit 9ff65e
    in
Packit 9ff65e
      choose_aux (List.rev lst)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
end
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
# 437 "myocamlbuild.ml"
Packit 9ff65e
module BaseEnvLight = struct
Packit 9ff65e
(* # 22 "src/base/BaseEnvLight.ml" *)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  module MapString = Map.Make(String)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  type t = string MapString.t
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let default_filename = Filename.concat (Sys.getcwd ()) "setup.data"
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let load ?(allow_empty=false) ?(filename=default_filename) ?stream () =
Packit 9ff65e
    let line = ref 1 in
Packit 9ff65e
    let lexer st =
Packit 9ff65e
      let st_line =
Packit 9ff65e
        Stream.from
Packit 9ff65e
          (fun _ ->
Packit 9ff65e
             try
Packit 9ff65e
               match Stream.next st with
Packit 9ff65e
               | '\n' -> incr line; Some '\n'
Packit 9ff65e
               | c -> Some c
Packit 9ff65e
             with Stream.Failure -> None)
Packit 9ff65e
      in
Packit 9ff65e
      Genlex.make_lexer ["="] st_line
Packit 9ff65e
    in
Packit 9ff65e
    let rec read_file lxr mp =
Packit 9ff65e
      match Stream.npeek 3 lxr with
Packit 9ff65e
      | [Genlex.Ident nm; Genlex.Kwd "="; Genlex.String value] ->
Packit 9ff65e
        Stream.junk lxr; Stream.junk lxr; Stream.junk lxr;
Packit 9ff65e
        read_file lxr (MapString.add nm value mp)
Packit 9ff65e
      | [] -> mp
Packit 9ff65e
      | _ ->
Packit 9ff65e
        failwith
Packit 9ff65e
          (Printf.sprintf "Malformed data file '%s' line %d" filename !line)
Packit 9ff65e
    in
Packit 9ff65e
    match stream with
Packit 9ff65e
    | Some st -> read_file (lexer st) MapString.empty
Packit 9ff65e
    | None ->
Packit 9ff65e
      if Sys.file_exists filename then begin
Packit 9ff65e
        let chn = open_in_bin filename in
Packit 9ff65e
        let st = Stream.of_channel chn in
Packit 9ff65e
        try
Packit 9ff65e
          let mp = read_file (lexer st) MapString.empty in
Packit 9ff65e
          close_in chn; mp
Packit 9ff65e
        with e ->
Packit 9ff65e
          close_in chn; raise e
Packit 9ff65e
      end else if allow_empty then begin
Packit 9ff65e
        MapString.empty
Packit 9ff65e
      end else begin
Packit 9ff65e
        failwith
Packit 9ff65e
          (Printf.sprintf
Packit 9ff65e
             "Unable to load environment, the file '%s' doesn't exist."
Packit 9ff65e
             filename)
Packit 9ff65e
      end
Packit 9ff65e
Packit 9ff65e
  let rec var_expand str env =
Packit 9ff65e
    let buff = Buffer.create ((String.length str) * 2) in
Packit 9ff65e
    Buffer.add_substitute
Packit 9ff65e
      buff
Packit 9ff65e
      (fun var ->
Packit 9ff65e
         try
Packit 9ff65e
           var_expand (MapString.find var env) env
Packit 9ff65e
         with Not_found ->
Packit 9ff65e
           failwith
Packit 9ff65e
             (Printf.sprintf
Packit 9ff65e
                "No variable %s defined when trying to expand %S."
Packit 9ff65e
                var
Packit 9ff65e
                str))
Packit 9ff65e
      str;
Packit 9ff65e
    Buffer.contents buff
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let var_get name env = var_expand (MapString.find name env) env
Packit 9ff65e
  let var_choose lst env = OASISExpr.choose (fun nm -> var_get nm env) lst
Packit 9ff65e
end
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
# 517 "myocamlbuild.ml"
Packit 9ff65e
module MyOCamlbuildFindlib = struct
Packit 9ff65e
(* # 22 "src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  (** OCamlbuild extension, copied from
Packit 9ff65e
    * https://ocaml.org/learn/tutorials/ocamlbuild/Using_ocamlfind_with_ocamlbuild.html
Packit 9ff65e
    * by N. Pouillard and others
Packit 9ff65e
    *
Packit 9ff65e
    * Updated on 2016-06-02
Packit 9ff65e
    *
Packit 9ff65e
    * Modified by Sylvain Le Gall
Packit 9ff65e
  *)
Packit 9ff65e
  open Ocamlbuild_plugin
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  type conf = {no_automatic_syntax: bool}
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let run_and_read = Ocamlbuild_pack.My_unix.run_and_read
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let blank_sep_strings = Ocamlbuild_pack.Lexers.blank_sep_strings
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let exec_from_conf exec =
Packit 9ff65e
    let exec =
Packit 9ff65e
      let env = BaseEnvLight.load ~allow_empty:true () in
Packit 9ff65e
      try
Packit 9ff65e
        BaseEnvLight.var_get exec env
Packit 9ff65e
      with Not_found ->
Packit 9ff65e
        Printf.eprintf "W: Cannot get variable %s\n" exec;
Packit 9ff65e
        exec
Packit 9ff65e
    in
Packit 9ff65e
    let fix_win32 str =
Packit 9ff65e
      if Sys.os_type = "Win32" then begin
Packit 9ff65e
        let buff = Buffer.create (String.length str) in
Packit 9ff65e
        (* Adapt for windowsi, ocamlbuild + win32 has a hard time to handle '\\'.
Packit 9ff65e
        *)
Packit 9ff65e
        String.iter
Packit 9ff65e
          (fun c -> Buffer.add_char buff (if c = '\\' then '/' else c))
Packit 9ff65e
          str;
Packit 9ff65e
        Buffer.contents buff
Packit 9ff65e
      end else begin
Packit 9ff65e
        str
Packit 9ff65e
      end
Packit 9ff65e
    in
Packit 9ff65e
    fix_win32 exec
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let split s ch =
Packit 9ff65e
    let buf = Buffer.create 13 in
Packit 9ff65e
    let x = ref [] in
Packit 9ff65e
    let flush () =
Packit 9ff65e
      x := (Buffer.contents buf) :: !x;
Packit 9ff65e
      Buffer.clear buf
Packit 9ff65e
    in
Packit 9ff65e
    String.iter
Packit 9ff65e
      (fun c ->
Packit 9ff65e
         if c = ch then
Packit 9ff65e
           flush ()
Packit 9ff65e
         else
Packit 9ff65e
           Buffer.add_char buf c)
Packit 9ff65e
      s;
Packit 9ff65e
    flush ();
Packit 9ff65e
    List.rev !x
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let split_nl s = split s '\n'
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let before_space s =
Packit 9ff65e
    try
Packit 9ff65e
      String.before s (String.index s ' ')
Packit 9ff65e
    with Not_found -> s
Packit 9ff65e
Packit 9ff65e
  (* ocamlfind command *)
Packit 9ff65e
  let ocamlfind x = S[Sh (exec_from_conf "ocamlfind"); x]
Packit 9ff65e
Packit 9ff65e
  (* This lists all supported packages. *)
Packit 9ff65e
  let find_packages () =
Packit 9ff65e
    List.map before_space (split_nl & run_and_read (exec_from_conf "ocamlfind" ^ " list"))
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  (* Mock to list available syntaxes. *)
Packit 9ff65e
  let find_syntaxes () = ["camlp4o"; "camlp4r"]
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let well_known_syntax = [
Packit 9ff65e
    "camlp4.quotations.o";
Packit 9ff65e
    "camlp4.quotations.r";
Packit 9ff65e
    "camlp4.exceptiontracer";
Packit 9ff65e
    "camlp4.extend";
Packit 9ff65e
    "camlp4.foldgenerator";
Packit 9ff65e
    "camlp4.listcomprehension";
Packit 9ff65e
    "camlp4.locationstripper";
Packit 9ff65e
    "camlp4.macro";
Packit 9ff65e
    "camlp4.mapgenerator";
Packit 9ff65e
    "camlp4.metagenerator";
Packit 9ff65e
    "camlp4.profiler";
Packit 9ff65e
    "camlp4.tracer"
Packit 9ff65e
  ]
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let dispatch conf =
Packit 9ff65e
    function
Packit 9ff65e
      | After_options ->
Packit 9ff65e
        (* By using Before_options one let command line options have an higher
Packit 9ff65e
         * priority on the contrary using After_options will guarantee to have
Packit 9ff65e
         * the higher priority override default commands by ocamlfind ones *)
Packit 9ff65e
        Options.ocamlc     := ocamlfind & A"ocamlc";
Packit 9ff65e
        Options.ocamlopt   := ocamlfind & A"ocamlopt";
Packit 9ff65e
        Options.ocamldep   := ocamlfind & A"ocamldep";
Packit 9ff65e
        Options.ocamldoc   := ocamlfind & A"ocamldoc";
Packit 9ff65e
        Options.ocamlmktop := ocamlfind & A"ocamlmktop";
Packit 9ff65e
        Options.ocamlmklib := ocamlfind & A"ocamlmklib"
Packit 9ff65e
Packit 9ff65e
      | After_rules ->
Packit 9ff65e
Packit 9ff65e
        (* Avoid warnings for unused tag *)
Packit 9ff65e
        flag ["tests"] N;
Packit 9ff65e
Packit 9ff65e
        (* When one link an OCaml library/binary/package, one should use
Packit 9ff65e
         * -linkpkg *)
Packit 9ff65e
        flag ["ocaml"; "link"; "program"] & A"-linkpkg";
Packit 9ff65e
Packit 9ff65e
        (* For each ocamlfind package one inject the -package option when
Packit 9ff65e
         * compiling, computing dependencies, generating documentation and
Packit 9ff65e
         * linking. *)
Packit 9ff65e
        List.iter
Packit 9ff65e
          begin fun pkg ->
Packit 9ff65e
            let base_args = [A"-package"; A pkg] in
Packit 9ff65e
            (* TODO: consider how to really choose camlp4o or camlp4r. *)
Packit 9ff65e
            let syn_args = [A"-syntax"; A "camlp4o"] in
Packit 9ff65e
            let (args, pargs) =
Packit 9ff65e
              (* Heuristic to identify syntax extensions: whether they end in
Packit 9ff65e
                 ".syntax"; some might not.
Packit 9ff65e
              *)
Packit 9ff65e
              if not (conf.no_automatic_syntax) &&
Packit 9ff65e
                 (Filename.check_suffix pkg "syntax" ||
Packit 9ff65e
                  List.mem pkg well_known_syntax) then
Packit 9ff65e
                (syn_args @ base_args, syn_args)
Packit 9ff65e
              else
Packit 9ff65e
                (base_args, [])
Packit 9ff65e
            in
Packit 9ff65e
            flag ["ocaml"; "compile";  "pkg_"^pkg] & S args;
Packit 9ff65e
            flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S args;
Packit 9ff65e
            flag ["ocaml"; "doc";      "pkg_"^pkg] & S args;
Packit 9ff65e
            flag ["ocaml"; "link";     "pkg_"^pkg] & S base_args;
Packit 9ff65e
            flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S args;
Packit 9ff65e
Packit 9ff65e
            (* TODO: Check if this is allowed for OCaml < 3.12.1 *)
Packit 9ff65e
            flag ["ocaml"; "compile";  "package("^pkg^")"] & S pargs;
Packit 9ff65e
            flag ["ocaml"; "ocamldep"; "package("^pkg^")"] & S pargs;
Packit 9ff65e
            flag ["ocaml"; "doc";      "package("^pkg^")"] & S pargs;
Packit 9ff65e
            flag ["ocaml"; "infer_interface"; "package("^pkg^")"] & S pargs;
Packit 9ff65e
          end
Packit 9ff65e
          (find_packages ());
Packit 9ff65e
Packit 9ff65e
        (* Like -package but for extensions syntax. Morover -syntax is useless
Packit 9ff65e
         * when linking. *)
Packit 9ff65e
        List.iter begin fun syntax ->
Packit 9ff65e
          flag ["ocaml"; "compile";  "syntax_"^syntax] & S[A"-syntax"; A syntax];
Packit 9ff65e
          flag ["ocaml"; "ocamldep"; "syntax_"^syntax] & S[A"-syntax"; A syntax];
Packit 9ff65e
          flag ["ocaml"; "doc";      "syntax_"^syntax] & S[A"-syntax"; A syntax];
Packit 9ff65e
          flag ["ocaml"; "infer_interface"; "syntax_"^syntax] &
Packit 9ff65e
          S[A"-syntax"; A syntax];
Packit 9ff65e
        end (find_syntaxes ());
Packit 9ff65e
Packit 9ff65e
        (* The default "thread" tag is not compatible with ocamlfind.
Packit 9ff65e
         * Indeed, the default rules add the "threads.cma" or "threads.cmxa"
Packit 9ff65e
         * options when using this tag. When using the "-linkpkg" option with
Packit 9ff65e
         * ocamlfind, this module will then be added twice on the command line.
Packit 9ff65e
         *
Packit 9ff65e
         * To solve this, one approach is to add the "-thread" option when using
Packit 9ff65e
         * the "threads" package using the previous plugin.
Packit 9ff65e
        *)
Packit 9ff65e
        flag ["ocaml"; "pkg_threads"; "compile"] (S[A "-thread"]);
Packit 9ff65e
        flag ["ocaml"; "pkg_threads"; "doc"] (S[A "-I"; A "+threads"]);
Packit 9ff65e
        flag ["ocaml"; "pkg_threads"; "link"] (S[A "-thread"]);
Packit 9ff65e
        flag ["ocaml"; "pkg_threads"; "infer_interface"] (S[A "-thread"]);
Packit 9ff65e
        flag ["c"; "pkg_threads"; "compile"] (S[A "-thread"]);
Packit 9ff65e
        flag ["ocaml"; "package(threads)"; "compile"] (S[A "-thread"]);
Packit 9ff65e
        flag ["ocaml"; "package(threads)"; "doc"] (S[A "-I"; A "+threads"]);
Packit 9ff65e
        flag ["ocaml"; "package(threads)"; "link"] (S[A "-thread"]);
Packit 9ff65e
        flag ["ocaml"; "package(threads)"; "infer_interface"] (S[A "-thread"]);
Packit 9ff65e
        flag ["c"; "package(threads)"; "compile"] (S[A "-thread"]);
Packit 9ff65e
Packit 9ff65e
      | _ ->
Packit 9ff65e
        ()
Packit 9ff65e
end
Packit 9ff65e
Packit 9ff65e
module MyOCamlbuildBase = struct
Packit 9ff65e
(* # 22 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  (** Base functions for writing myocamlbuild.ml
Packit 9ff65e
      @author Sylvain Le Gall
Packit 9ff65e
    *)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  open Ocamlbuild_plugin
Packit 9ff65e
  module OC = Ocamlbuild_pack.Ocaml_compiler
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  type dir = string
Packit 9ff65e
  type file = string
Packit 9ff65e
  type name = string
Packit 9ff65e
  type tag = string
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  type t =
Packit 9ff65e
      {
Packit 9ff65e
        lib_ocaml: (name * dir list * string list) list;
Packit 9ff65e
        lib_c:     (name * dir * file list) list;
Packit 9ff65e
        flags:     (tag list * (spec OASISExpr.choices)) list;
Packit 9ff65e
        (* Replace the 'dir: include' from _tags by a precise interdepends in
Packit 9ff65e
         * directory.
Packit 9ff65e
         *)
Packit 9ff65e
        includes:  (dir * dir list) list;
Packit 9ff65e
      }
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
(* # 110 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let env_filename = Pathname.basename BaseEnvLight.default_filename
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let dispatch_combine lst =
Packit 9ff65e
    fun e ->
Packit 9ff65e
      List.iter
Packit 9ff65e
        (fun dispatch -> dispatch e)
Packit 9ff65e
        lst
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let tag_libstubs nm =
Packit 9ff65e
    "use_lib"^nm^"_stubs"
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let nm_libstubs nm =
Packit 9ff65e
    nm^"_stubs"
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let dispatch t e =
Packit 9ff65e
    let env = BaseEnvLight.load ~allow_empty:true () in
Packit 9ff65e
      match e with
Packit 9ff65e
        | Before_options ->
Packit 9ff65e
            let no_trailing_dot s =
Packit 9ff65e
              if String.length s >= 1 && s.[0] = '.' then
Packit 9ff65e
                String.sub s 1 ((String.length s) - 1)
Packit 9ff65e
              else
Packit 9ff65e
                s
Packit 9ff65e
            in
Packit 9ff65e
              List.iter
Packit 9ff65e
                (fun (opt, var) ->
Packit 9ff65e
                   try
Packit 9ff65e
                     opt := no_trailing_dot (BaseEnvLight.var_get var env)
Packit 9ff65e
                   with Not_found ->
Packit 9ff65e
                     Printf.eprintf "W: Cannot get variable %s\n" var)
Packit 9ff65e
                [
Packit 9ff65e
                  Options.ext_obj, "ext_obj";
Packit 9ff65e
                  Options.ext_lib, "ext_lib";
Packit 9ff65e
                  Options.ext_dll, "ext_dll";
Packit 9ff65e
                ]
Packit 9ff65e
Packit 9ff65e
        | After_rules ->
Packit 9ff65e
            (* Declare OCaml libraries *)
Packit 9ff65e
            List.iter
Packit 9ff65e
              (function
Packit 9ff65e
                 | nm, [], intf_modules ->
Packit 9ff65e
                     ocaml_lib nm;
Packit 9ff65e
                     let cmis =
Packit 9ff65e
                       List.map (fun m -> (OASISString.uncapitalize_ascii m) ^ ".cmi")
Packit 9ff65e
                                intf_modules in
Packit 9ff65e
                     dep ["ocaml"; "link"; "library"; "file:"^nm^".cma"] cmis
Packit 9ff65e
                 | nm, dir :: tl, intf_modules ->
Packit 9ff65e
                     ocaml_lib ~dir:dir (dir^"/"^nm);
Packit 9ff65e
                     List.iter
Packit 9ff65e
                       (fun dir ->
Packit 9ff65e
                          List.iter
Packit 9ff65e
                            (fun str ->
Packit 9ff65e
                               flag ["ocaml"; "use_"^nm; str] (S[A"-I"; P dir]))
Packit 9ff65e
                            ["compile"; "infer_interface"; "doc"])
Packit 9ff65e
                       tl;
Packit 9ff65e
                     let cmis =
Packit 9ff65e
                       List.map (fun m -> dir^"/"^(OASISString.uncapitalize_ascii m)^".cmi")
Packit 9ff65e
                                intf_modules in
Packit 9ff65e
                     dep ["ocaml"; "link"; "library"; "file:"^dir^"/"^nm^".cma"]
Packit 9ff65e
                         cmis)
Packit 9ff65e
              t.lib_ocaml;
Packit 9ff65e
Packit 9ff65e
            (* Declare directories dependencies, replace "include" in _tags. *)
Packit 9ff65e
            List.iter
Packit 9ff65e
              (fun (dir, include_dirs) ->
Packit 9ff65e
                 Pathname.define_context dir include_dirs)
Packit 9ff65e
              t.includes;
Packit 9ff65e
Packit 9ff65e
            (* Declare C libraries *)
Packit 9ff65e
            List.iter
Packit 9ff65e
              (fun (lib, dir, headers) ->
Packit 9ff65e
                   (* Handle C part of library *)
Packit 9ff65e
                   flag ["link"; "library"; "ocaml"; "byte"; tag_libstubs lib]
Packit 9ff65e
                     (S[A"-dllib"; A("-l"^(nm_libstubs lib)); A"-cclib";
Packit 9ff65e
                        A("-l"^(nm_libstubs lib))]);
Packit 9ff65e
Packit 9ff65e
                   flag ["link"; "library"; "ocaml"; "native"; tag_libstubs lib]
Packit 9ff65e
                     (S[A"-cclib"; A("-l"^(nm_libstubs lib))]);
Packit 9ff65e
Packit 9ff65e
                   if bool_of_string (BaseEnvLight.var_get "native_dynlink" env) then
Packit 9ff65e
                     flag ["link"; "program"; "ocaml"; "byte"; tag_libstubs lib]
Packit 9ff65e
                         (S[A"-dllib"; A("dll"^(nm_libstubs lib))]);
Packit 9ff65e
Packit 9ff65e
                   (* When ocaml link something that use the C library, then one
Packit 9ff65e
                      need that file to be up to date.
Packit 9ff65e
                      This holds both for programs and for libraries.
Packit 9ff65e
                    *)
Packit 9ff65e
                   dep ["link"; "ocaml"; tag_libstubs lib]
Packit 9ff65e
                     [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
Packit 9ff65e
Packit 9ff65e
                   dep  ["compile"; "ocaml"; tag_libstubs lib]
Packit 9ff65e
                     [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
Packit 9ff65e
Packit 9ff65e
                   (* TODO: be more specific about what depends on headers *)
Packit 9ff65e
                   (* Depends on .h files *)
Packit 9ff65e
                   dep ["compile"; "c"]
Packit 9ff65e
                     headers;
Packit 9ff65e
Packit 9ff65e
                   (* Setup search path for lib *)
Packit 9ff65e
                   flag ["link"; "ocaml"; "use_"^lib]
Packit 9ff65e
                     (S[A"-I"; P(dir)]);
Packit 9ff65e
              )
Packit 9ff65e
              t.lib_c;
Packit 9ff65e
Packit 9ff65e
              (* Add flags *)
Packit 9ff65e
              List.iter
Packit 9ff65e
              (fun (tags, cond_specs) ->
Packit 9ff65e
                 let spec = BaseEnvLight.var_choose cond_specs env in
Packit 9ff65e
                 let rec eval_specs =
Packit 9ff65e
                   function
Packit 9ff65e
                     | S lst -> S (List.map eval_specs lst)
Packit 9ff65e
                     | A str -> A (BaseEnvLight.var_expand str env)
Packit 9ff65e
                     | spec -> spec
Packit 9ff65e
                 in
Packit 9ff65e
                   flag tags & (eval_specs spec))
Packit 9ff65e
              t.flags
Packit 9ff65e
        | _ ->
Packit 9ff65e
            ()
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
  let dispatch_default conf t =
Packit 9ff65e
    dispatch_combine
Packit 9ff65e
      [
Packit 9ff65e
        dispatch t;
Packit 9ff65e
        MyOCamlbuildFindlib.dispatch conf;
Packit 9ff65e
      ]
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
end
Packit 9ff65e
Packit 9ff65e
Packit 9ff65e
# 878 "myocamlbuild.ml"
Packit 9ff65e
open Ocamlbuild_plugin;;
Packit 9ff65e
let package_default =
Packit 9ff65e
  {
Packit 9ff65e
     MyOCamlbuildBase.lib_ocaml =
Packit 9ff65e
       [("fileutils", ["src"], []); ("fileutils-str", ["src"], [])];
Packit 9ff65e
     lib_c = [];
Packit 9ff65e
     flags = [];
Packit 9ff65e
     includes = [("test", ["src"])]
Packit 9ff65e
  }
Packit 9ff65e
  ;;
Packit 9ff65e
Packit 9ff65e
let conf = {MyOCamlbuildFindlib.no_automatic_syntax = false}
Packit 9ff65e
Packit 9ff65e
let dispatch_default = MyOCamlbuildBase.dispatch_default conf package_default;;
Packit 9ff65e
Packit 9ff65e
# 895 "myocamlbuild.ml"
Packit 9ff65e
(* OASIS_STOP *)
Packit 9ff65e
Ocamlbuild_plugin.dispatch dispatch_default;;