-
Notifications
You must be signed in to change notification settings - Fork 32
/
configure.ml
83 lines (71 loc) · 2.61 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
let config_mk = "config.mk"
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
(* 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 libexecdir =
let doc = "Set the directory for installing helper executables" in
Arg.(value & opt string "/usr/lib/xapi" & info ["libexecdir"] ~docv:"LIBEXECDIR" ~doc)
let etcdir =
let doc = "Set the directory for installing configuration files" in
Arg.(value & opt string "/etc" & info ["etcdir"] ~docv:"ETCDIR" ~doc)
let info =
let doc = "Configures a package" in
Term.info "configure" ~version:"0.1" ~doc
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 configure bindir libexecdir etcdir =
Printf.printf "Configuring with:\n\tbindir=%s\n\tlibexecdir=%s\n\tetcdir=%s\n" bindir libexecdir etcdir;
let xcp = find_ocamlfind false "xcp" in
let xenstore_transport = find_ocamlfind false "xenstore_transport" in
let xenstore = find_ocamlfind false "xenstore" in
let tapctl = find_ocamlfind false "tapctl" in
let enable_xenserver = xcp && xenstore_transport && xenstore && tapctl in
let lines =
[ "# Warning - this file is autogenerated by the configure script";
"# Do not edit";
Printf.sprintf "BINDIR=%s" bindir;
Printf.sprintf "LIBEXECDIR=%s" libexecdir;
Printf.sprintf "ETCDIR=%s" etcdir;
Printf.sprintf "ENABLE_XENSERVER=--%sable-xenserver" (if enable_xenserver then "en" else "dis");
] in
output_file config_mk lines;
let lines =
[ "bin: [";
" \"main.native\" { \"vhd-tool\" }";
] @ (if enable_xenserver
then [ " \"sparse_dd.native\" { \"sparse_dd\" }" ]
else []) @ [
"]";
"man: [";
" \"vhd-tool.1\" { \"vhd-tool.1\" }";
] @ (if enable_xenserver
then [ " \"sparse_dd.1\" { \"sparse_dd.1\" }" ]
else []) @ [
"]";
] in
output_file "vhd-tool.install" lines
let configure_t = Term.(pure configure $ bindir $ libexecdir $ etcdir )
let () =
match
Term.eval (configure_t, info)
with
| `Error _ -> exit 1
| _ -> exit 0