-
Notifications
You must be signed in to change notification settings - Fork 25
/
configure.ml
131 lines (106 loc) · 3.12 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
(* This file is distributed under the terms and conditions of the GNU GPL
(General Public License), as detailed in the file LICENSE.
Copyright (C) 2016 by Gerd Stolpmann.
*)
(* Configuration script for omake *)
#warnings "-3";;
#load "str.cma";;
#load "unix.cma";;
open Printf
let is_windows =
Sys.os_type = "Win32"
let path =
if is_windows then
let re = Str.regexp ";" in
Str.split re (Sys.getenv "PATH")
else
let re = Str.regexp ":" in
Str.split re (Sys.getenv "PATH")
let find_in_path prog =
let prog =
if is_windows then prog ^ ".exe" else prog in
List.find
(fun p -> Sys.file_exists (Filename.concat p prog))
path
let prefix =
try
ref (Filename.dirname (find_in_path "ocamlc"))
with
| Not_found ->
prerr_endline "ocamlc not found; aborting";
exit 1
let bad_version1 = Str.regexp "^[0123]\\..*"
let bad_version2 = Str.regexp "^4.0[012]\\..*"
let check_ocaml_version() =
let ch = Unix.open_process_in "ocamlc -version" in
let line = input_line ch in
let status = Unix.close_process_in ch in
if status <> Unix.WEXITED 0 then
failwith "Cannot run: ocamlc -version";
if Str.string_match bad_version1 line 0 || Str.string_match bad_version2 line 0 then
failwith "The ocaml version is too old. Need at least 4.03";
()
let gnu_re1 = Str.regexp "--\\([-A-Za-z0-9]+\\)=\\(.*\\)$"
let gnu_re2 = Str.regexp "--\\([-A-Za-z0-9]+\\)$"
let gnu_options argv =
let argv = Array.to_list argv in
let argv =
List.mapi
(fun i arg ->
if i > 0 && Str.string_match gnu_re1 arg 0 then
["-" ^ Str.matched_group 1 arg; Str.matched_group 2 arg]
else
if i > 0 && Str.string_match gnu_re2 arg 0 then
["-" ^ Str.matched_group 1 arg ]
else
[arg]
)
argv in
Array.of_list (List.flatten argv)
let main() =
let no_readline = ref false in
let no_ncurses = ref false in
let no_fam = ref false in
Arg.parse_argv
(gnu_options Sys.argv)
[ "-prefix", Arg.Set_string prefix,
"<dir> Install prefix";
"-disable-readline", Arg.Set no_readline,
" Disable readline support";
"-disable-ncurses", Arg.Set no_ncurses,
" Disable ncurses support";
"-disable-fam", Arg.Set no_fam,
" Disable FAM support";
]
(fun s ->
raise(Arg.Bad ("Unexpected: " ^ s))
)
"usage: configure [options]";
check_ocaml_version();
let f = open_out ".preconfig" in
fprintf f "public.PREFIX = %s\n\n" !prefix;
List.iter
(fun (disabled, name) ->
fprintf f "# %s: %s\n" name (if disabled then "disabled" else "auto");
fprintf f "%spublic.%s = false\n\n" (if disabled then "" else "#") name;
)
[ !no_readline, "READLINE_ENABLED";
!no_ncurses, "NCURSES_ENABLED";
!no_fam, "FAM_ENABLED";
];
close_out f;
printf "Wrote .preconfig\n%!";
(try Sys.remove ".config"
with Sys_error _ -> ()
)
let () =
try main()
with
| Failure msg
| Arg.Bad msg
| Arg.Help msg
| Sys_error msg ->
flush stdout;
prerr_endline msg;
flush stderr;
exit 1