forked from BinaryAnalysisPlatform/bap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.ml.in
182 lines (157 loc) · 4.52 KB
/
setup.ml.in
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#load "unix.cma";;
let definition_end = BaseEnv.var_ignore
let ctxt = !BaseContext.default
let piqic () : unit =
let chop str = try
Filename.chop_extension str
with _ -> str in
let piqic_path = BaseCheck.prog_best "piqic_path" ["piqic-ocaml"; "piqic"] () in
BaseEnv.var_define "piqic_flags" (fun () ->
if chop (Filename.basename (BaseEnv.var_get "piqic")) = "piqic"
then "ocaml"
else "") |>
definition_end;
BaseEnv.var_define "piqic" (fun () ->
if List.mem (BaseStandardVar.os_type ()) ["Cygwin"; "Win32"]
then
String.concat " "
(OASISExec.run_read_output ~ctxt "cygpath" [piqic_path])
else piqic_path) |>
definition_end
let cxx () : unit =
BaseEnv.var_define
~hide:false
~dump:true
~cli:BaseEnv.CLIWith
~short_desc:(fun () -> "c++ compiler")
"cxx"
(fun () -> OASISFileUtil.which ~ctxt "c++") |>
definition_end
let llvm_version () : unit =
BaseEnv.var_define
~hide:false
~dump:true
~cli:BaseEnv.CLIWith
~short_desc:(fun () -> "libllvm version (e.g., 3.4)")
"llvm_version"
(fun () -> "") |>
definition_end
let llvm_config () : unit =
BaseEnv.var_define
~hide:false
~dump:true
~cli:BaseEnv.CLIWith
~short_desc:(fun () -> "llvm-config executable")
"llvm_config"
(fun () ->
(* assume macports if we're on mac os x *)
let macosx = BaseEnv.var_get "system" = "macosx" in
let ver = match BaseEnv.var_get "llvm_version" with
| "" when macosx -> "-mp-3.4"
| "" -> ""
| ver when macosx -> "-mp-" ^ ver
| ver -> "-" ^ ver in
OASISFileUtil.which ~ctxt ("llvm-config" ^ ver)) |>
definition_end
let llvm var () : unit =
BaseEnv.var_define
~hide:true
~dump:true
~short_desc:(fun () -> "llvm-config --"^var)
("llvm_"^var)
(fun () ->
let llvm_config = BaseEnv.var_get "llvm_config" in
OASISExec.run_read_one_line ~ctxt llvm_config ["--"^var]) |>
definition_end
let cxx_flags () : unit =
BaseEnv.var_define
~hide:true
~dump:true
~short_desc:(fun () -> "c++ flags")
"cxxflags"
(fun () -> "-std=c++11") |>
definition_end
let cxx_libs () : unit =
BaseEnv.var_define
~hide:true
~dump:true
~cli:BaseEnv.CLIWith
~short_desc:(fun () -> "c++ library")
"cxxlibs"
(fun () -> if BaseEnv.var_get "system" = "macosx" then "-lc++" else "-lstdc++") |>
definition_end
let llvm_mainlib () : unit =
BaseEnv.var_define
~hide:true
~dump:true
~short_desc:(fun () -> "main LLVM library")
"llvm_mainlib"
(fun () ->
let llvm_config = BaseEnv.var_get "llvm_config" in
let ver =
OASISExec.run_read_one_line ~ctxt llvm_config ["--version"] in
"-lLLVM-"^ver) |>
definition_end
let cc_optimization () : unit =
BaseEnv.var_define
~hide:false
~dump:true
~cli:BaseEnv.CLIWith
~short_desc:(fun () -> "C compiler optimization level")
"cc_optimization"
(fun () -> "-O2") |>
definition_end
let llvm_lib () : unit =
BaseEnv.var_define
~hide:true
~dump:true
~short_desc:(fun () -> "LLVM library(ies) to link with")
"llvm_lib"
(fun () ->
let llvm_static = BaseEnv.var_get "llvm_static" in
let lib = if llvm_static = "true"
then "llvm_libs"
else "llvm_mainlib" in
BaseEnv.var_get lib) |>
definition_end
let is_defined var : bool =
try (BaseEnv.var_get var) |> ignore; true with exn -> false
let is_undefined var : bool = not (is_defined var)
let is_set_to var value : bool =
is_defined var && BaseEnv.var_get var = value
let check =
let open OASISMessage in
let error msg = error ~ctxt msg; exit 1 in
List.iter (fun (causes,expected,message) ->
if List.for_all (fun (v,e) -> is_set_to v e) causes &&
List.exists is_undefined expected
then error message)
let define definitions =
List.iter (fun f -> try f () with exn -> ()) definitions
let () =
Unix.putenv "OCAMLFIND_IGNORE_DUPS_IN" @@
BaseEnv.var_get "standard_library";
define [
piqic;
cxx;
cxx_flags;
cxx_libs;
cc_optimization;
llvm_version;
llvm_config;
llvm_mainlib;
llvm "cxxflags";
llvm "ldflags";
llvm "cflags";
llvm "libs";
llvm_lib;
];
setup ();
check [
["llvm","true"], ["llvm_lib"],
" Failed to find llvm library, consider using --with-llvm-version
or --with-llvm-config command line options, to point me on a
correct version of LLVM. ";
["serialization", "true"], ["piqic"],
"Failed find piqic compiler";
];