-
Notifications
You must be signed in to change notification settings - Fork 1
/
myocamlbuild.ml
68 lines (60 loc) · 2.21 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
68
open Ocamlbuild_plugin ;;
open Command ;;
open Pathname ;;
open Outcome ;;
let find_modules builder mllib =
let dirs = include_dirs_of (dirname mllib) in
let modules = string_list_of_file mllib in
let make_candidates m =
List.map (expand_module dirs m) [["cmi"]; ["cmx"]; ["mli"; "inferred.mli"]] in
let dependencies = List.flatten (List.map make_candidates modules) in
let build_result = builder dependencies in
let built_files = List.filter_opt
(function Good file -> Some (!Options.build_dir/file) | Bad _ -> None) build_result in
(* add a trailing space to ease concatenation of .libfiles *)
(String.concat " " built_files) ^ " "
;;
let cil_version =
try Printf.sprintf "(version %s)" (Sys.getenv "CIL_VERSION")
with Not_found -> "" ;;
dispatch begin function
| After_rules ->
(* the main CIL library *)
ocaml_lib "src/cil";
(* residual reliance on make to build some OCaml source files *)
let make target =
let basename = Pathname.basename target in
rule ("make " ^ target)
~dep: "Makefile"
~prod: basename
(fun _ _ -> Cmd (S
[A (try Sys.getenv "MAKE" with Not_found -> "make");
A "-C"; P ".."; P ("_build" / target)]))
in
make "machdep.ml";
(* Build mllib for plugins by listing the content of their directory *)
rule "plugin dir -> mllib"
~prod: "src/ext/%.mllib"
(fun env builder ->
let files = Array.to_list (Sys.readdir (".."/(env "src/ext/%"))) in
let ml_files = List.filter
(fun f -> let ext = get_extension f in ext = "ml" || ext = "mli") files in
let modules = List.map module_name_of_pathname ml_files in
let uniq_mods =
List.fold_left (fun l m -> List.union l [m ^ "\n"]) [] modules in
Echo (uniq_mods, (env "src/ext/%.mllib")));
(* Build a list of files to install with ocamlfind *)
rule "%.mllib -> %.libfiles"
~dep: "%.mllib"
~prod: "%.libfiles"
(fun env builder -> Echo (
[find_modules builder (env "%.mllib")],
(env "%.libfiles")));
(* Flags for ocamldoc *)
flag ["ocaml";"doc"] (S [
A "-stars";
A "-hide"; A "Pervasives";
A "-t" ; A (Printf.sprintf "CIL API Documentation %s" cil_version);
]);
| _ -> ()
end ;;