-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmyocamlbuild.ml
128 lines (116 loc) · 3.78 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
open Ocamlbuild_pack
open Ocamlbuild_plugin
let ext_obj = !Options.ext_obj;;
let x_o = "%"-.-ext_obj;;
let refmt = "refmt --print binary"
let add_printers_tag = "reason.add_printers"
let ocamldep_command' tags =
let tags' = tags++"ocaml"++"ocamldep" in
let specs =
[ !Options.ocamldep;
T tags';
Ocaml_utils.ocaml_ppflags (tags++"pp:dep");
A "-modules" ] in
S specs
let impl_intf ~impl ?(intf_suffix=false) arg =
let inft_suffix_specs =
if intf_suffix
then [ A "-intf-suffix"; P ".rei" ]
else [] in
inft_suffix_specs
@
[ A (if impl then "-impl" else "-intf");
P arg ]
let compile_c ~impl ~native tags arg out =
let tags =
tags ++
"ocaml" ++
(if native then "native" else "byte") ++
"compile" in
let specs =
[ if native then !Options.ocamlopt else !Options.ocamlc;
A "-c";
T tags;
Ocaml_utils.ocaml_ppflags tags;
Ocaml_utils.ocaml_include_flags arg;
A "-pp"; P refmt;
A "-o"; Px out ]
@ impl_intf ~impl ~intf_suffix:true arg in
Cmd (S specs)
let union_tags re cm tag =
Tags.union (tags_of_pathname re) (tags_of_pathname cm)++"implem"+++tag
let byte_compile_re_implem ?tag re cmo env build =
let re = env re and cmo = env cmo in
Ocaml_compiler.prepare_compile build re;
compile_c ~impl:true ~native:false (union_tags re cmo tag) re cmo
let native_compile_re_implem ?tag ?(cmx_ext="cmx") re env build =
let re = env re in
let cmi = Pathname.update_extensions "cmi" re in
let cmx = Pathname.update_extensions cmx_ext re in
Ocaml_compiler.prepare_link cmx cmi [cmx_ext; "cmi"] build;
compile_c ~impl:true ~native:true (union_tags re cmx tag) re cmx
let compile_ocaml_interf rei cmi env build =
let rei = env rei and cmi = env cmi in
Ocaml_compiler.prepare_compile build rei;
let tags = tags_of_pathname rei++"interf" in
let native = Tags.mem "native" tags in
compile_c ~impl:false ~native tags rei cmi
let ocamldep_command ~impl arg out env _build =
let out = List.map env out in
let out = List.map (fun n -> Px n) out in
let out =
match List.rev out with
| ([] | [_]) as out -> out
| last :: rev_prefix -> [Sh "|"; P "tee"] @ List.rev_append rev_prefix [Sh ">"; last] in
let arg = env arg in
let tags = tags_of_pathname arg in
let specs =
[ ocamldep_command' tags;
A "-pp"; P refmt ]
@ impl_intf ~impl arg
@ out in
Cmd (S specs)
;;
rule "rei -> cmi"
~prod:"%.cmi"
~deps:["%.rei"; "%.rei.depends"]
(compile_ocaml_interf "%.rei" "%.cmi")
;;
rule "re dependecies"
~prods:["%.re.depends"; "%.ml.depends" (* .ml.depends is also needed since
the function "prepare_link" requires .ml.depends *)]
~deps:(["%.re"])
(ocamldep_command ~impl:true "%.re" ["%.re.depends"; "%.ml.depends"])
;;
rule "rei dependencies"
~prods:["%.rei.depends"; "%.mli.depends"]
~dep:"%.rei"
(ocamldep_command ~impl:false "%.rei" ["%.rei.depends"; "%.mli.depends"])
;;
rule "re -> d.cmo & cmi"
~prods:["%.d.cmo"]
~deps:["%.re"; "%.re.depends"; "%.cmi"]
(byte_compile_re_implem ~tag:"debug" "%.re" "%.d.cmo")
;;
rule "re & cmi -> cmo"
~prod:"%.cmo"
~deps:["%.rei"(* This one is inserted to force this rule to be skipped when
a .ml is provided without a .mli *); "%.re"; "%.re.depends"; "%.cmi"]
(byte_compile_re_implem "%.re" "%.cmo")
;;
rule "re -> cmo & cmi"
~prods:["%.cmo"; "%.cmi"]
~deps:(["%.re"; "%.re.depends"])
(byte_compile_re_implem "%.re" "%.cmo")
;;
rule "re & cmi -> d.cmo"
~prod:"%.d.cmo"
~deps:["%.rei"(* This one is inserted to force this rule to be skipped when
a .re is provided without a .rei *); "%.re"; "%.re.depends"; "%.cmi"]
(byte_compile_re_implem ~tag:"debug" "%.re" "%.d.cmo")
;;
rule "re & rei -> cmx & o"
~prods:["%.cmx"; x_o]
~deps:["%.re"; "%.ml.depends"; "%.cmi"]
(native_compile_re_implem "%.re")
;;