/[svn]/configure.ml
ViewVC logotype

Contents of /configure.ml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1570 - (show annotations)
Tue Jul 10 19:03:49 2007 UTC (5 years, 10 months ago) by abate
File size: 8342 byte(s)
[r2005-03-22 15:26:33 by afrisch] Empty log message

Original author: afrisch
Date: 2005-03-22 15:26:33+00:00
1 (*
2 #use "topfind";;
3 #require "findlib";;
4 *)
5
6 open Printf
7
8 let not_distrib = Sys.file_exists "Makefile.distrib"
9
10 let usage () =
11 print_string "\
12 Configuration of CDuce.
13
14 Usage: ./configure [OPTION]...
15
16 Defaults for the options are specified in brackets.
17
18 Options:
19 --help display this help and exit
20
21 Optional features:
22 --with-FEATURE force support for FEATURE [default: autodetect]
23 --without-FEATURE disable support for FEATURE [default: autodetect]
24
25 Available features:
26 ocamlopt use ocamlopt instead of ocamlc to build CDuce
27 pxp_wlex use wlexers for parsing utf8 with PXP [default: false]
28 pxp support for the PXP XML parser
29 expat support for the expat XML parser
30 curl support for the libcurl library
31 netclient support for the netclient library
32
33 OCaml/CDuce interface:
34 --mliface=DIR build the interface with the OCaml sources in DIR
35
36 Installation directories:
37 --prefix=PREFIX install files in PREFIX [/usr/local]
38 --bindir=DIR install user executables in DIR [PREFIX/bin]
39 --mandir=DIR install man documentation in DIR [PREFIX/man]
40 --docdir=DIR install the rest of the doc in DIR [PREFIX/doc/cduce]
41 ";
42 if not_distrib then print_string "
43 --wprefix=WPREFIX root directory of the web-server [/var/www]
44 --cgidir=DIR install the cgi-bin interpreter in DIR [WPREFIX/cgi-bin]
45 --htmldir=DIR install the website in DIR [WPREFIX/html]
46 --sessiondir=DIR store the open sessions of the cgi-bin in DIR
47 [/tmp/cduce_sessions]
48 "
49
50 let features =
51 [ "ocamlopt", ref `auto;
52 "mliface", ref `auto;
53 "pxp", ref `auto;
54 "expat", ref `auto;
55 "curl", ref `auto;
56 "netclient", ref `auto;
57 "pxp_wlex", ref `no ]
58
59 let vars =
60 [ "prefix", ref "/usr/local";
61 "bindir", ref "";
62 "mandir", ref "";
63 "docdir", ref "";
64
65 "wprefix", ref "/var/www";
66 "cgidir", ref "";
67 "htmldir", ref "";
68
69 "sessiondir", ref "/tmp/cduce_sessions";
70 "mliface", ref ""
71 ]
72
73
74 let src_dirs = ["/usr/src"; "/usr/local/src"; "/tmp"]
75
76 let fatal s = printf "*** Fatal error: %s\n" s; exit 1
77 let warning s = printf "* Warning: %s\n" s
78
79 let log s =
80 let oc = open_out_gen [ Open_append; Open_creat ] 0o600 "configure.log" in
81 output_string oc s;
82 output_char oc '\n';
83 close_out oc;
84 flush stdout
85
86 let command s =
87 log ("==> " ^ s);
88 Sys.command (sprintf "%s 2>> configure.log" s) = 0
89
90 let start_with s p =
91 let ls = String.length s and lp = String.length p in
92 if (ls >= lp) && (String.sub s 0 lp = p)
93 then Some (String.sub s lp (ls - lp)) else None
94
95 let parse_arg s =
96 if s = "--help" then (usage (); exit 0)
97 else
98 match start_with s "--with-" with
99 | Some f -> (List.assoc f features) := `yes
100 | None ->
101 match start_with s "--without-" with
102 | Some f -> (List.assoc f features) := `no
103 | None ->
104 let i = String.index s '=' in
105 if i < 2 then raise Not_found;
106 let n = String.sub s 2 (i - 2) in
107 let v = String.sub s (succ i) (String.length s - i - 1) in
108 (List.assoc n vars) := v
109
110 let () =
111 print_endline "Configuring CDuce for compilation...\n";
112 (try for i = 1 to Array.length Sys.argv - 1 do parse_arg Sys.argv.(i) done
113 with Not_found -> usage (); fatal "Incorrect command line");
114 (try Sys.remove "configure.log" with Sys_error _ -> ());
115 ignore (Sys.command "uname -a >> configure.log")
116
117 let print s = print_string s; flush stdout
118
119 let check_feature f p =
120 printf "%s: " f;
121 match !(List.assoc f features) with
122 | `no ->
123 print "disabled\n"; false
124 | `yes ->
125 print "checking... ";
126 if p ()
127 then (print "ok\n"; true)
128 else (print "failed !\n"; fatal "Required feature is not available")
129 | `auto ->
130 print "autodetecting... ";
131 if p ()
132 then (print "enabled\n"; true)
133 else (print "disabled\n"; false)
134
135 let native =
136 check_feature "ocamlopt" (fun () -> command "ocamlfind ocamlopt")
137
138 let check_pkg p () =
139 try
140 (* ignore (Findlib.package_property
141 [ (if native then "native" else "bytecode") ]
142 p "archive"); *)
143 command
144 (sprintf
145 "ocamlfind ocaml%s -package %s -linkpkg -o configure.try && rm -f configure.try"
146 (if native then "opt" else "c")
147 p)
148 with Not_found -> false
149
150 let need_pkg p =
151 printf "Checking for package %s... " p; flush stdout;
152 if not (check_pkg p ())
153 then (print "failed !\n"; fatal "Required package is not available")
154 else (print "ok\n")
155
156 let dir ?def d =
157 let s = !(List.assoc d vars) in
158 if s <> "" then s
159 else match def with
160 | Some x -> x
161 | None -> fatal (sprintf "%s cannot be empty" d)
162
163
164 let exe = match Sys.os_type with
165 | "Cygwin" ->
166 print "Cygwin detected... executable will have .exe extension"; ".exe"
167 | _ -> ""
168
169 let check_mliface dir =
170 log ("Looking for ocaml modules in " ^ dir);
171 let file = if native then "types.cmx" else "types.cmo" in
172 if Sys.file_exists (Filename.concat dir file)
173 then `flat
174 else
175 if Sys.file_exists
176 (Filename.concat (Filename.concat dir "typing") file) then
177 `tree
178 else
179 `not_found
180
181 let ocaml_stdlib () =
182 if (Sys.command "ocamlc -where > ocaml_stdlib" <> 0) then
183 fatal "Can't run ocamlc to get OCaml standard library path";
184 let ic = open_in "ocaml_stdlib" in
185 let s = input_line ic in
186 close_in ic;
187 Sys.remove "ocaml_stdlib";
188 s
189
190 let ml_interface =
191 let dir1 = !(List.assoc "mliface" vars) in
192 let dirs =
193 let std = ocaml_stdlib () in
194 Filename.concat (Filename.chop_suffix std "std-lib") "compiler-lib" ::
195 (* GODI *)
196 Filename.concat std "compiler-libs" :: (* Debian *)
197 src_dirs in
198 let dirs = if dir1 = "" then dirs else dir1 :: dirs in
199 print "Looking for ocaml compiler modules ...";
200 let rec loop = function
201 | [] ->
202 print "not found\n";
203 `no
204 | d::dirs ->
205 match check_mliface d with
206 | `flat -> print ("flat model: " ^ d ^ "\n"); `flat d
207 | `tree -> print ("tree model: " ^ d ^ "\n"); `tree d
208 | `not_found -> loop dirs
209 in
210 loop dirs
211
212
213 let pxp = check_feature "pxp" (check_pkg "pxp")
214 let expat = check_feature "expat" (check_pkg "expat")
215 let curl = check_feature "curl" (check_pkg "curl")
216 let netclient = check_feature "netclient" (check_pkg "netclient")
217 let pxp_wlex = check_feature "pxp_wlex" (check_pkg "pxp-wlex-utf8")
218 let prefix = dir "prefix"
219 let bindir = dir ~def:(prefix^"/bin") "bindir"
220 let mandir = dir ~def:(prefix^"/man") "mandir"
221 let docdir = dir ~def:(prefix^"/doc/cduce") "docdir"
222 let wprefix = dir "wprefix"
223 let cgidir = dir ~def:(wprefix^"/cgi-bin") "cgidir"
224 let htmldir = dir ~def:(wprefix^"/html") "htmldir"
225 let sessiondir = dir "sessiondir"
226
227 let curl,netclient =
228 match curl,netclient with
229 | true,true ->
230 warning "Both netclient and curl are available. Will use curl.";
231 true,false
232 | false,false ->
233 warning "No package for loading external URLs.";
234 false,false
235 | c,n -> c,n
236
237 let pxp,expat =
238 match pxp,expat with
239 | true,true ->
240 warning "Both PXP and expat are available. Will build both and use expat by default.";
241 true,true
242 | false,false ->
243 warning "No package for parsing XML documents.";
244 false,false
245 | c,n -> c,n
246
247 let required_packages = ["camlp4"; "num"; "pcre"; "ulex"; "cgi"; "netstring"]
248
249 let () =
250 List.iter need_pkg required_packages;
251 if pxp then (
252 need_pkg "pxp-engine";
253 need_pkg "pxp-lex-iso88591";
254 if not pxp_wlex then need_pkg "pxp-lex-utf8";
255 );
256
257 print "Creating Makefile.conf...\n";
258
259 let out = open_out "Makefile.conf" in
260 fprintf out "# This file has been generated by the configure script\n";
261 fprintf out "NATIVE=%b\n" native;
262 (match ml_interface with
263 | `no -> fprintf out "ML_INTERFACE=false\n"
264 | `flat d -> fprintf out "ML_INTERFACE=flat\nML_MODULES=%s\n" d
265 | `tree d -> fprintf out "ML_INTERFACE=tree\nML_MODULES=%s\n" d);
266 fprintf out "PXP=%b\n" pxp;
267 fprintf out "EXPAT=%b\n" expat;
268 fprintf out "CURL=%b\n" curl;
269 fprintf out "NETCLIENT=%b\n" netclient;
270 fprintf out "PXP_WLEX=%b\n" pxp_wlex;
271 fprintf out "BINDIR=%s\n" bindir;
272 fprintf out "MANDIR=%s\n" mandir;
273 fprintf out "DOCDIR=%s\n" docdir;
274 fprintf out "CGI_DIR=%s\n" cgidir;
275 fprintf out "HTML_DIR=%s\n" htmldir;
276 fprintf out "SESSION_DIR=%s\n" sessiondir;
277 fprintf out "EXE=%s\n" exe;
278 fprintf out "PROFILE=false\n";
279 close_out out

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5