forked from BinaryAnalysisPlatform/bap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbapbuild.ml
More file actions
88 lines (77 loc) · 2.08 KB
/
bapbuild.ml
File metadata and controls
88 lines (77 loc) · 2.08 KB
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
open Ocamlbuild_pack
open Ocamlbuild_plugin
open Core_kernel.Std
let syntax_packages = List.map [
"sexplib";
"comparelib";
"fieldslib";
"variantslib";
] ~f:(fun pkg -> pkg ^ "." ^ "syntax")
let default_pkgs = ["bap"; "bap.plugins"; "core_kernel"]
(* there is no way to figure out what libraries were linked into
the bap executable in the runtime. Later we can try to figure
this out from the _oasis file for example, but right now I will
hardcode the dependencies here.
*)
let bap_packages = [
"ocamlgraph";
"ezjsonm";
"cmdliner";
"fileutils";
"re.posix";
]
let packages = default_pkgs @ syntax_packages @ bap_packages
let default_tags = [
"thread";
"debug";
"annot";
"bin_annot";
"short_paths"
]
let set_default_options () : unit =
Options.(begin
use_ocamlfind := true;
ocaml_syntax := Some "camlp4o";
ocaml_pkgs := packages;
tags := default_tags;
end)
let extern_deps_link_flags () =
let interns = packages |>
List.map ~f:Findlib.query |>
Findlib.topological_closure in
!Options.ocaml_pkgs |>
List.map ~f:Findlib.query |>
Findlib.topological_closure |>
List.filter ~f:(fun pkg -> not (List.mem interns pkg)) |>
Findlib.link_flags_native
let symlink env =
if Options.make_links.contents then
Cmd (S [A"ln"; A"-sf";
P (env (!Options.build_dir / "%.plugin"));
A Pathname.parent_dir_name])
else Nop
let plugin () =
rule "bap: cmxa & a -> plugin"
~prods:["%.plugin"]
~deps:["%.cmxa"; "%" -.- !Options.ext_lib]
(fun env _ ->
Seq [Cmd (S [
!Options.ocamlopt;
A "-linkpkg";
A "-shared";
S [extern_deps_link_flags ()];
P (env "%.cmxa");
A "-o"; Px (env "%.plugin")
]);
symlink env
])
let main () =
set_default_options ();
flag ["ocaml"; "library"; "link"] (A"-linkall");
Command.jobs := 4;
Ocamlbuild_plugin.dispatch (function
| Before_rules -> plugin ()
| _ -> ());
Ocamlbuild_unix_plugin.setup ();
Main.main ()
let () = main ()