forked from xapi-project/xenopsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.ml
166 lines (143 loc) · 6.03 KB
/
configure.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
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
let config_mk = "config.mk"
(* Configure script *)
open Cmdliner
let bindir =
let doc = "Set the directory for installing binaries" in
Arg.(value & opt string "/usr/bin" & info ["bindir"] ~docv:"BINDIR" ~doc)
let sbindir =
let doc = "Set the directory for installing superuser binaries" in
Arg.(value & opt string "/usr/sbin" & info ["sbindir"] ~docv:"SBINDIR" ~doc)
let libexecdir =
let doc = "Set the directory for installing helper executables" in
Arg.(value & opt string "/usr/lib/xenopsd" & info ["libexecdir"] ~docv:"LIBEXECDIR" ~doc)
let qemu_wrapper_dir =
let doc = "Set the directory for installing xen helper executables" in
Arg.(value & opt string "/usr/lib/xenopsd" & info ["qemu_wrapper_dir"] ~docv:"QEMU_WRAPPER_DIR" ~doc)
let coverage =
let doc = "Enable coverage profiling" in
Arg.(value & flag & info ["enable-coverage"] ~doc)
let scriptsdir =
let doc = "Set the directory for installing helper scripts" in
Arg.(value & opt string "/usr/lib/xenopsd/scripts" & info ["scriptsdir"] ~docv:"SCRIPTSDIR" ~doc)
let etcdir =
let doc = "Set the directory for installing configuration files" in
Arg.(value & opt string "/etc" & info ["etcdir"] ~docv:"ETCDIR" ~doc)
let mandir =
let doc = "Set the directory for installing manpages" in
Arg.(value & opt string "/usr/share/man" & info ["mandir"] ~docv:"MANDIR" ~doc)
let optdir =
let doc = "Set the directory for installing system binaries" in
Arg.(value & opt string "/opt/xensource/libexec" & info ["optdir"] ~docv:"OPTDIR" ~doc)
let info =
let doc = "Configures a package" in
Term.info "configure" ~version:"0.1" ~doc
let find_ocamlfind verbose name =
let found =
try
let (_: string) = Findlib.package_property [] name "requires" in
true
with
| Not_found ->
(* property within the package could not be found *)
true
| Findlib.No_such_package(_,_ ) ->
false in
if verbose then Printf.fprintf stderr "querying for ocamlfind package %s: %s" name (if found then "ok" else "missing");
found
let output_file filename lines =
let oc = open_out filename in
let lines = List.map (fun line -> line ^ "\n") lines in
List.iter (output_string oc) lines;
close_out oc
let find_ml_val verbose name libs =
let ml_program = [
Printf.sprintf "let f = %s" name;
] in
let basename = Filename.temp_file "looking_for_val" "" in
let ml_file = basename ^ ".ml" in
let cmo_file = basename ^ ".cmo" in
let cmi_file = basename ^ ".cmi" in
output_file ml_file ml_program;
let found = Sys.command (Printf.sprintf "ocamlfind ocamlc -package %s -c %s %s" (String.concat "," libs) ml_file (if verbose then "" else "2>/dev/null")) = 0 in
if Sys.file_exists ml_file then Sys.remove ml_file;
if Sys.file_exists cmo_file then Sys.remove cmo_file;
if Sys.file_exists cmi_file then Sys.remove cmi_file;
Printf.printf "Looking for %s: %s\n" name (if found then "ok" else "missing");
found
let expand start finish input output =
let command = Printf.sprintf "cat %s | sed -r 's=%s=%s=g' > %s" input start finish output in
if Sys.command command <> 0
then begin
Printf.fprintf stderr "Failed to expand %s -> %s in %s producing %s\n" start finish input output;
Printf.fprintf stderr "Command-line was:\n%s\n%!" command;
exit 1;
end
let output_file filename lines =
let oc = open_out filename in
List.iter (fun line -> Printf.fprintf oc "%s\n" line) lines;
close_out oc
let find_xentoollog verbose =
let c_program = [
"int main(int argc, const char *argv){";
" return 0;";
"}";
] in
let c_file = Filename.temp_file "configure" ".c" in
let exe_file = c_file ^ ".exe" in
output_file c_file c_program;
let found = Sys.command (Printf.sprintf "cc -Werror %s -lxentoollog -o %s %s" c_file exe_file (if verbose then "" else "2>/dev/null")) = 0 in
if Sys.file_exists c_file then Sys.remove c_file;
if Sys.file_exists exe_file then Sys.remove exe_file;
Printf.printf "Looking for xentoollog: %s\n" (if found then "found" else "missing");
output_file "xentoollog_flags" (if found then ["-L/lib64"; "-lxentoollog"] else []);
found
let yesno_of_bool = function
| true -> "YES"
| false -> "NO"
let configure bindir sbindir libexecdir qemu_wrapper_dir scriptsdir etcdir mandir optdir coverage =
let xenctrl = find_ocamlfind false "xenctrl" in
let xentoollog = find_xentoollog false in
let p = Printf.sprintf in
List.iter print_endline
[ "Configure with"
; p "\tbindir=%s" bindir
; p "\tsbindir=%s" sbindir
; p "\tlibexecdir=%s" libexecdir
; p "\tqemu_wrapper_dir=%s" qemu_wrapper_dir
; p "\tscriptsdir=%s" scriptsdir
; p "\tetcdir=%s" etcdir
; p "\tmandir=%s" mandir
; p "\toptdir=%s" optdir
; p "\txenctrl=%b" xenctrl
; p "\txentoollog=%b" xentoollog
; p "\tcoverage=%b" coverage
; p "" (* new line *)
];
(* Write config.mk *)
let lines =
[ "# Warning - this file is autogenerated by the configure script";
"# Do not edit";
Printf.sprintf "BINDIR=%s" bindir;
Printf.sprintf "SBINDIR=%s" sbindir;
Printf.sprintf "LIBEXECDIR=%s" libexecdir;
Printf.sprintf "QEMU_WRAPPER_DIR=%s" qemu_wrapper_dir;
Printf.sprintf "SCRIPTSDIR=%s" scriptsdir;
Printf.sprintf "ETCDIR=%s" etcdir;
Printf.sprintf "MANDIR=%s" mandir;
Printf.sprintf "OPTDIR=%s" optdir;
Printf.sprintf "ENABLE_XEN=--%s-xen" (if xenctrl then "enable" else "disable");
Printf.sprintf "ENABLE_XENTOOLLOG=--%s-xentoollog" (if xentoollog then "enable" else "disable");
Printf.sprintf "BISECT_ENABLE=%s" (yesno_of_bool coverage);
"export BISECT_ENABLE"
] in
output_file config_mk lines;
(* Expand @LIBEXEC@ in udev rules *)
expand "@LIBEXEC@" libexecdir "scripts/vif.in" "scripts/vif";
expand "@LIBEXEC@" libexecdir "scripts/xen-backend.rules.in" "scripts/xen-backend.rules"
let configure_t = Term.(pure configure $ bindir $ sbindir $ libexecdir $ qemu_wrapper_dir $ scriptsdir $ etcdir $ mandir $ optdir $ coverage)
let () =
match
Term.eval (configure_t, info)
with
| `Error _ -> exit 1
| _ -> exit 0