-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyocamlbuild.ml
69 lines (57 loc) · 2.25 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
(* OASIS_START *)
(* OASIS_STOP *)
let dispatch = function
| After_rules ->
let stubgen = "stubgen/ffi_stubgen.byte" in
let stubgen_types = "stubgen/ffi_types_stubgen.byte" in
let stubgen_ml_types = "stubgen/ffi_ml_types_stubgen" in
rule "generated ml"
~dep:stubgen
~prod:"lib/factory_generated.ml"
(fun _ _ ->
Cmd(S[P stubgen; A"-ml"; Sh">"; A"lib/factory_generated.ml"]));
rule "generated-types c"
~dep:stubgen_types
~prod:"stubgen/ffi_ml_types_stubgen.c"
(fun _ _ ->
Cmd (S [P stubgen_types; Sh">"; A"stubgen/ffi_ml_types_stubgen.c"]));
rule "generated-types exe"
~dep:"stubgen/ffi_ml_types_stubgen.c"
~prod:stubgen_ml_types
(fun _ _ ->
let env = BaseEnvLight.load () in
let cc = BaseEnvLight.var_get "bytecomp_c_compiler" env in
let stdlib = BaseEnvLight.var_get "standard_library" env in
let ctypes = BaseEnvLight.var_get "pkg_ctypes_stubs" env in
Cmd (S [Sh cc; A"stubgen/ffi_ml_types_stubgen.c";
A"-I"; P ctypes; A"-I"; P stdlib;
A"-o"; A stubgen_ml_types])
);
rule "generated-types ml"
~dep:stubgen_ml_types
~prod:"lib/factory_generated_types.ml"
(fun _ _ ->
Cmd (S [P stubgen_ml_types; Sh">>"; A"lib/factory_generated_types.ml"]));
rule "generated c"
~dep:stubgen
~prod:"lib/ffi_generated_stubs.c"
(fun _ _ ->
Cmd(S[P stubgen; A"-c"; Sh">"; A"lib/ffi_generated_stubs.c"]));
(* If there are only C++ files, a simple 'CCOpt: -std=c++98 -x c++'
suffices, but we also have C files and must therefore change this
on a per-file basis. *)
rule ~insert:`top "cpp wrapper"
~dep:"lib/factory_wrapper.c"
~prod:"lib/factory_wrapper.o"
(fun _ _ ->
let env = BaseEnvLight.load () in
let cc = BaseEnvLight.var_get "bytecomp_c_compiler" env in
Cmd (S [Sh cc;
A"-x"; A"c++";
A"-c"; A"lib/factory_wrapper.c";
A"-o"; A "lib/factory_wrapper.o"])
);
flag ["c"; "compile"] & S[A"-I"; A"lib"; A"-package"; A"ctypes"]
| _ ->
()
let () = Ocamlbuild_plugin.dispatch (fun hook -> dispatch hook; dispatch_default hook)