2 (* DO NOT EDIT (digest: 5a9a2168dcb86db37476d58b8c0e25b3) *)
3 module OASISGettext
= struct
4 (* # 22 "src/oasis/OASISGettext.ml" *)
15 let f_ (str
: ('a
, 'b
, 'c
, 'd
) format4
) =
32 module OASISExpr
= struct
33 (* # 22 "src/oasis/OASISExpr.ml" *)
54 | ETest
of test
* string
58 type 'a choices
= (t
* 'a
) list
71 (eval' e1
) && (eval' e2
)
74 (eval' e1
) || (eval' e2
)
80 assert(v = "true" || v = "false");
92 let choose ?printer ?name var_get lst
=
96 if eval var_get cond
then
111 | None
-> s_ "<no printer>")
118 (f_ "No result for the choice list '%s': %s")
123 (f_ "No result for a choice list: %s")
126 choose_aux (List.rev lst
)
132 #
132 "myocamlbuild.ml"
133 module BaseEnvLight
= struct
134 (* # 22 "src/base/BaseEnvLight.ml" *)
137 module MapString
= Map.Make
(String
)
140 type t
= string MapString.t
143 let default_filename =
149 let load ?
(allow_empty
=false) ?
(filename
=default_filename) () =
150 if Sys.file_exists filename
then
156 Stream.of_channel
chn
165 match Stream.next
st with
166 | '
\n'
-> incr
line; Some '
\n'
168 with Stream.Failure
-> None
)
171 Genlex.make_lexer
["="] st_line
173 let rec read_file mp
=
174 match Stream.npeek
3 lexer with
175 | [Genlex.Ident nm
; Genlex.Kwd
"="; Genlex.String
value] ->
179 read_file (MapString.add nm
value mp
)
185 "Malformed data file '%s' line %d"
189 read_file MapString.empty
194 else if allow_empty
then
202 "Unable to load environment, the file '%s' doesn't exist."
207 let rec var_expand str env
=
209 Buffer.create
((String.length str
) * 2)
211 Buffer.add_substitute
215 var_expand (MapString.find var env
) env
219 "No variable %s defined when trying to expand %S."
226 let var_get name env
=
227 var_expand (MapString.find name env
) env
230 let var_choose lst env
=
232 (fun nm
-> var_get nm env
)
237 #
237 "myocamlbuild.ml"
238 module MyOCamlbuildFindlib
= struct
239 (* # 22 "src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *)
242 (** OCamlbuild extension, copied from
243 * http://brion.inria.fr/gallium/index.php/Using_ocamlfind_with_ocamlbuild
244 * by N. Pouillard and others
246 * Updated on 2009/02/28
248 * Modified by Sylvain Le Gall
250 open Ocamlbuild_plugin
253 (* these functions are not really officially exported *)
255 Ocamlbuild_pack.My_unix.run_and_read
258 let blank_sep_strings =
259 Ocamlbuild_pack.Lexers.blank_sep_strings
262 let exec_from_conf exec
=
264 let env_filename = Pathname.basename
BaseEnvLight.default_filename in
265 let env = BaseEnvLight.load ~filename
:env_filename ~allow_empty
:true () in
267 BaseEnvLight.var_get exec env
269 Printf.eprintf
"W: Cannot get variable %s\n" exec;
273 if Sys.os_type
= "Win32" then begin
274 let buff = Buffer.create
(String.length str
) in
275 (* Adapt for windowsi, ocamlbuild + win32 has a hard time to handle '\\'.
278 (fun c
-> Buffer.add_char
buff (if c
= '
\\'
then '
/'
else c
))
288 let buf = Buffer.create
13 in
291 x := (Buffer.contents
buf) :: !x;
299 Buffer.add_char
buf c
)
305 let split_nl s
= split s '
\n'
310 String.before s
(String.index s ' '
)
313 (* ocamlfind command *)
314 let ocamlfind x = S
[Sh
(exec_from_conf "ocamlfind"); x]
316 (* This lists all supported packages. *)
317 let find_packages () =
318 List.map
before_space (split_nl & run_and_read "ocamlfind list")
321 (* Mock to list available syntaxes. *)
322 let find_syntaxes () = ["camlp4o"; "camlp4r"]
325 let well_known_syntax = [
326 "camlp4.quotations.o";
327 "camlp4.quotations.r";
328 "camlp4.exceptiontracer";
330 "camlp4.foldgenerator";
331 "camlp4.listcomprehension";
332 "camlp4.locationstripper";
334 "camlp4.mapgenerator";
335 "camlp4.metagenerator";
344 (* By using Before_options one let command line options have an higher
345 * priority on the contrary using After_options will guarantee to have
346 * the higher priority override default commands by ocamlfind ones *)
347 Options.ocamlc
:= ocamlfind & A
"ocamlc";
348 Options.ocamlopt
:= ocamlfind & A
"ocamlopt";
349 Options.ocamldep
:= ocamlfind & A
"ocamldep";
350 Options.ocamldoc
:= ocamlfind & A
"ocamldoc";
351 Options.ocamlmktop
:= ocamlfind & A
"ocamlmktop";
352 Options.ocamlmklib
:= ocamlfind & A
"ocamlmklib"
356 (* When one link an OCaml library/binary/package, one should use
358 flag
["ocaml"; "link"; "program"] & A
"-linkpkg";
360 (* For each ocamlfind package one inject the -package option when
361 * compiling, computing dependencies, generating documentation and
365 let base_args = [A
"-package"; A pkg
] in
366 (* TODO: consider how to really choose camlp4o or camlp4r. *)
367 let syn_args = [A
"-syntax"; A
"camlp4o"] in
369 (* Heuristic to identify syntax extensions: whether they end in
370 ".syntax"; some might not.
372 if Filename.check_suffix pkg
"syntax" ||
373 List.mem pkg
well_known_syntax then
378 flag
["ocaml"; "compile"; "pkg_"^pkg
] & S
args;
379 flag
["ocaml"; "ocamldep"; "pkg_"^pkg
] & S
args;
380 flag
["ocaml"; "doc"; "pkg_"^pkg
] & S
args;
381 flag
["ocaml"; "link"; "pkg_"^pkg
] & S
base_args;
382 flag
["ocaml"; "infer_interface"; "pkg_"^pkg
] & S
args;
386 (* Like -package but for extensions syntax. Morover -syntax is useless
388 List.iter
begin fun syntax
->
389 flag
["ocaml"; "compile"; "syntax_"^syntax
] & S
[A
"-syntax"; A syntax
];
390 flag
["ocaml"; "ocamldep"; "syntax_"^syntax
] & S
[A
"-syntax"; A syntax
];
391 flag
["ocaml"; "doc"; "syntax_"^syntax
] & S
[A
"-syntax"; A syntax
];
392 flag
["ocaml"; "infer_interface"; "syntax_"^syntax
] &
393 S
[A
"-syntax"; A syntax
];
394 end (find_syntaxes ());
396 (* The default "thread" tag is not compatible with ocamlfind.
397 * Indeed, the default rules add the "threads.cma" or "threads.cmxa"
398 * options when using this tag. When using the "-linkpkg" option with
399 * ocamlfind, this module will then be added twice on the command line.
401 * To solve this, one approach is to add the "-thread" option when using
402 * the "threads" package using the previous plugin.
404 flag
["ocaml"; "pkg_threads"; "compile"] (S
[A
"-thread"]);
405 flag
["ocaml"; "pkg_threads"; "doc"] (S
[A
"-I"; A
"+threads"]);
406 flag
["ocaml"; "pkg_threads"; "link"] (S
[A
"-thread"]);
407 flag
["ocaml"; "pkg_threads"; "infer_interface"] (S
[A
"-thread"]);
408 flag
["ocaml"; "package(threads)"; "compile"] (S
[A
"-thread"]);
409 flag
["ocaml"; "package(threads)"; "doc"] (S
[A
"-I"; A
"+threads"]);
410 flag
["ocaml"; "package(threads)"; "link"] (S
[A
"-thread"]);
411 flag
["ocaml"; "package(threads)"; "infer_interface"] (S
[A
"-thread"]);
417 module MyOCamlbuildBase
= struct
418 (* # 22 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
421 (** Base functions for writing myocamlbuild.ml
422 @author Sylvain Le Gall
429 open Ocamlbuild_plugin
430 module OC
= Ocamlbuild_pack.Ocaml_compiler
439 (* # 62 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
444 lib_ocaml
: (name
* dir list
* string list
) list
;
445 lib_c
: (name
* dir
* file list
) list
;
446 flags
: (tag list
* (spec
OASISExpr.choices
)) list
;
447 (* Replace the 'dir: include' from _tags by a precise interdepends in
450 includes
: (dir
* dir list
) list
;
456 BaseEnvLight.default_filename
459 let dispatch_combine lst
=
462 (fun dispatch -> dispatch e
)
466 let tag_libstubs nm
=
467 "use_lib"^nm^
"_stubs"
477 ~filename
:env_filename
483 let no_trailing_dot s
=
484 if String.length s
>= 1 && s
.[0] = '
.'
then
485 String.sub s
1 ((String.length s
) - 1)
492 opt
:= no_trailing_dot (BaseEnvLight.var_get var
env)
494 Printf.eprintf
"W: Cannot get variable %s\n" var
)
496 Options.ext_obj
, "ext_obj";
497 Options.ext_lib
, "ext_lib";
498 Options.ext_dll
, "ext_dll";
502 (* Declare OCaml libraries *)
505 | nm
, [], intf_modules
->
508 List.map
(fun m
-> (String.uncapitalize m
) ^
".cmi")
510 dep
["ocaml"; "link"; "library"; "file:"^nm^
".cma"] cmis
511 | nm
, dir
:: tl
, intf_modules
->
512 ocaml_lib ~dir
:dir
(dir^
"/"^nm
);
517 flag
["ocaml"; "use_"^nm
; str
] (S
[A
"-I"; P dir
]))
518 ["compile"; "infer_interface"; "doc"])
521 List.map
(fun m
-> dir^
"/"^
(String.uncapitalize m
)^
".cmi")
523 dep
["ocaml"; "link"; "library"; "file:"^dir^
"/"^nm^
".cma"]
527 (* Declare directories dependencies, replace "include" in _tags. *)
529 (fun (dir
, include_dirs
) ->
530 Pathname.define_context dir include_dirs
)
533 (* Declare C libraries *)
535 (fun (lib
, dir
, headers
) ->
536 (* Handle C part of library *)
537 flag
["link"; "library"; "ocaml"; "byte"; tag_libstubs lib
]
538 (S
[A
"-dllib"; A
("-l"^
(nm_libstubs lib
)); A
"-cclib";
539 A
("-l"^
(nm_libstubs lib
))]);
541 flag
["link"; "library"; "ocaml"; "native"; tag_libstubs lib
]
542 (S
[A
"-cclib"; A
("-l"^
(nm_libstubs lib
))]);
544 flag
["link"; "program"; "ocaml"; "byte"; tag_libstubs lib
]
545 (S
[A
"-dllib"; A
("dll"^
(nm_libstubs lib
))]);
547 (* When ocaml link something that use the C library, then one
548 need that file to be up to date.
550 dep
["link"; "ocaml"; "program"; tag_libstubs lib
]
551 [dir
/"lib"^
(nm_libstubs lib
)^
"."^
(!Options.ext_lib
)];
553 dep
["compile"; "ocaml"; "program"; tag_libstubs lib
]
554 [dir
/"lib"^
(nm_libstubs lib
)^
"."^
(!Options.ext_lib
)];
556 (* TODO: be more specific about what depends on headers *)
557 (* Depends on .h files *)
561 (* Setup search path for lib *)
562 flag
["link"; "ocaml"; "use_"^lib
]
569 (fun (tags
, cond_specs
) ->
570 let spec = BaseEnvLight.var_choose cond_specs
env in
573 | S lst
-> S
(List.map
eval_specs lst
)
574 | A str
-> A
(BaseEnvLight.var_expand str
env)
577 flag tags
& (eval_specs spec))
583 let dispatch_default t
=
587 MyOCamlbuildFindlib.dispatch;
594 #
594 "myocamlbuild.ml"
595 open Ocamlbuild_plugin
;;
596 let package_default =
597 {MyOCamlbuildBase.lib_ocaml
= []; lib_c
= []; flags
= []; includes
= []}
600 let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;
602 #
603 "myocamlbuild.ml"
606 let bracket res destroy k
= let x = (try k res
with e
-> destroy res
; raise e
) in destroy res
; x in
607 let get_line r d
= bracket r d input_line
in
609 bracket (open_out
"src/version.ml") close_out
(fun out
->
611 let revision = get_line (Unix.open_process_in
"git describe --always") (Unix.close_process_in
) in
612 Printf.fprintf out
"let id=%S\n" revision
614 _
-> Printf.fprintf out
"let id = Version_release.id\n"
618 let dispatch = function
619 | After_rules
as t
->
620 flag
["compile"; "ocaml"; "warn_no_44"] (S
[A
"-w";A
"-44"]);
621 flag
["ocaml"; "link"; "toplevel"] (A
"-linkpkg");
623 | t
-> dispatch_default t
626 Ocamlbuild_plugin.dispatch dispatch;;