/[svn]/cduce/trunk/configure.ml
ViewVC logotype

Contents of /cduce/trunk/configure.ml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3982 - (show annotations)
Tue Feb 19 16:36:04 2008 UTC (5 years, 3 months ago) by abate
File size: 9053 byte(s)
- Rollback --libdir. 
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 cgi support for the cgi library
33
34 OCaml/CDuce interface:
35 --mliface=DIR build the interface with the OCaml sources in DIR
36
37 Installation directories:
38 --prefix=PREFIX install files in PREFIX [/usr/local]
39 --bindir=DIR install user executables in DIR [PREFIX/bin]
40 --mandir=DIR install man documentation in DIR [PREFIX/man]
41 --docdir=DIR install the rest of the doc in DIR [PREFIX/doc/cduce]
42 ";
43 if not_distrib then print_string "
44 --wprefix=WPREFIX root directory of the web-server [/var/www]
45 --cgidir=DIR install the cgi-bin interpreter in DIR [WPREFIX/cgi-bin]
46 --htmldir=DIR install the website in DIR [WPREFIX/html]
47 --sessiondir=DIR store the open sessions of the cgi-bin in DIR
48 [/tmp/cduce_sessions]
49 "
50
51 let features =
52 [ "ocamlopt", ref `auto;
53 "mliface", ref `auto;
54 "pxp", ref `auto;
55 "expat", ref `auto;
56 "curl", ref `auto;
57 "netclient", ref `auto;
58 "cgi", ref `auto;
59 "pxp_wlex", ref `no ]
60
61 let vars =
62 [ "prefix", ref "/usr/local";
63 "bindir", ref "";
64 "mandir", ref "";
65 "docdir", ref "";
66
67 "wprefix", ref "/var/www";
68 "cgidir", ref "";
69 "htmldir", ref "";
70
71 "sessiondir", ref "/tmp/cduce_sessions";
72 "mliface", ref ""
73 ]
74
75
76 let src_dirs = ["/usr/src"; "/usr/local/src"; "/tmp"]
77
78 let fatal s = printf "*** Fatal error: %s\n" s; exit 1
79 let warning s = printf "* Warning: %s\n" s
80
81 let log s =
82 let oc = open_out_gen [ Open_append; Open_creat ] 0o600 "configure.log" in
83 output_string oc s;
84 output_char oc '\n';
85 close_out oc;
86 flush stdout
87
88 let command s =
89 log ("==> " ^ s);
90 Sys.command (sprintf "%s 2>> configure.log" s) = 0
91
92 let start_with s p =
93 let ls = String.length s and lp = String.length p in
94 if (ls >= lp) && (String.sub s 0 lp = p)
95 then Some (String.sub s lp (ls - lp)) else None
96
97 let parse_arg s =
98 if s = "--help" then (usage (); exit 0)
99 else
100 match start_with s "--with-" with
101 | Some f -> (List.assoc f features) := `yes
102 | None ->
103 match start_with s "--without-" with
104 | Some f -> (List.assoc f features) := `no
105 | None ->
106 let i = String.index s '=' in
107 if i < 2 then raise Not_found;
108 let n = String.sub s 2 (i - 2) in
109 let v = String.sub s (succ i) (String.length s - i - 1) in
110 (List.assoc n vars) := v
111
112 let () =
113 print_endline "Configuring CDuce for compilation...\n";
114 (try for i = 1 to Array.length Sys.argv - 1 do parse_arg Sys.argv.(i) done
115 with Not_found -> usage (); fatal "Incorrect command line");
116 (try Sys.remove "configure.log" with Sys_error _ -> ());
117 ignore (Sys.command "uname -a >> configure.log")
118
119 let print s = print_string s; flush stdout
120
121 let check_feature f p =
122 printf "%s: " f;
123 match !(List.assoc f features) with
124 | `no ->
125 print "disabled\n"; false
126 | `yes ->
127 print "checking... ";
128 if p ()
129 then (print "ok\n"; true)
130 else (print "failed !\n"; fatal "Required feature is not available")
131 | `auto ->
132 print "autodetecting... ";
133 if p ()
134 then (print "enabled\n"; true)
135 else (print "disabled\n"; false)
136
137 let native =
138 check_feature "ocamlopt" (fun () -> command "ocamlfind ocamlopt")
139
140 let check_pkg p () =
141 try
142 (* ignore (Findlib.package_property
143 [ (if native then "native" else "bytecode") ]
144 p "archive"); *)
145 command
146 (sprintf
147 "ocamlfind ocaml%s -package %s -linkpkg -o configure.try && rm -f configure.try"
148 (if native then "opt" else "c")
149 p)
150 with Not_found -> false
151
152 let need_pkg p =
153 printf "Checking for package %s... " p; flush stdout;
154 if not (check_pkg p ())
155 then (print "failed !\n"; fatal "Required package is not available")
156 else (print "ok\n")
157
158 let dir ?def d =
159 let s = !(List.assoc d vars) in
160 if s <> "" then s
161 else match def with
162 | Some x -> x
163 | None -> fatal (sprintf "%s cannot be empty" d)
164
165
166 let exe = match Sys.os_type with
167 | "Win32" ->
168 print "Win32 detected... executable will have .exe extension\n"; ".exe"
169 | "Cygwin" ->
170 print "Cygwin detected... executable will have .exe extension\n"; ".exe"
171 | _ -> ""
172
173 let add_icon = match Sys.os_type with
174 | "Win32" | "Cygwin" -> true
175 | _ -> false
176
177 let check_mliface dir =
178 (* Sys.file_exists (Filename.concat dir "typing/types.ml") *)
179 Sys.file_exists (Filename.concat dir "typing/types.ml")
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 make_absolute dir =
191 if Filename.is_relative dir
192 then Filename.concat (Sys.getcwd ()) dir
193 else dir
194
195 let ml_interface =
196 let dir1 = !(List.assoc "mliface" vars) in
197 let dirs = if dir1 = "" then [] else [ make_absolute dir1 ] in
198 print "ocaml sources... ";
199 let rec loop = function
200 | [] ->
201 print "not found (the interface will not be built)\n";
202 None
203 | d::dirs ->
204 if check_mliface d then
205 (print ("found: " ^ d ^ "\n"); Some d)
206 else loop dirs
207 in
208 loop dirs
209
210 let pxp = check_feature "pxp" (check_pkg "pxp")
211 let expat = check_feature "expat" (check_pkg "expat")
212 let curl = check_feature "curl" (check_pkg "curl")
213 let netclient = check_feature "netclient" (check_pkg "netclient")
214 let cgi = check_feature "cgi" (check_pkg "netcgi1")
215 let pxp_wlex = check_feature "pxp_wlex" (check_pkg "pxp-wlex-utf8")
216 let prefix = dir "prefix"
217 let bindir = dir ~def:(prefix^"/bin") "bindir"
218 let mandir = dir ~def:(prefix^"/man") "mandir"
219 let docdir = dir ~def:(prefix^"/doc/cduce") "docdir"
220 let wprefix = dir "wprefix"
221 let cgidir = dir ~def:(wprefix^"/cgi-bin") "cgidir"
222 let htmldir = dir ~def:(wprefix^"/html") "htmldir"
223 let sessiondir = dir "sessiondir"
224
225 let curl,netclient =
226 match curl,netclient with
227 | true,true ->
228 warning "Both netclient and curl are available. Will use curl.";
229 true,false
230 | false,false ->
231 warning "No package for loading external URLs.";
232 false,false
233 | c,n -> c,n
234
235 let pxp,expat =
236 match pxp,expat with
237 | true,true ->
238 warning "Both PXP and expat are available. Will build both and use expat by default.";
239 true,true
240 | false,false ->
241 warning "No package for parsing XML documents.";
242 false,false
243 | c,n -> c,n
244
245 let cgi =
246 if not(cgi) then
247 (warning "No cgi package found: dtd2cduce and the web interface won't be built";
248 false)
249 else true
250
251 let required_packages = ["camlp4"; "num"; "pcre"; "ulex"; "netstring"]
252
253 let has_forpack =
254 print "testing for -for-pack option: ";
255 let comm =
256 match Sys.os_type with
257 | "Win32" -> "ocamlc -for-pack foo"
258 | _ -> "ocamlc -for-pack foo 2> /dev/null" in
259 if Sys.command comm = 0 then
260 (print "available\n"; true)
261 else
262 (print "not available\n"; false)
263
264 let has_natdynlink =
265 print "testing for native dynlink: ";
266 if Sys.command "ocamlopt -o foo dynlink.cmxa && rm -f foo" = 0 then
267 (printf "available\n"; true)
268 else
269 (print "not available\n"; false)
270
271 let () =
272 List.iter need_pkg required_packages;
273 if pxp then (
274 need_pkg "pxp-engine";
275 need_pkg "pxp-lex-iso88591";
276 if not pxp_wlex then need_pkg "pxp-lex-utf8";
277 );
278
279 print "Creating Makefile.conf...\n";
280
281 let out = open_out "Makefile.conf" in
282 fprintf out "# This file has been generated by the configure script\n";
283 fprintf out "NATIVE=%b\n" native;
284 (match ml_interface with
285 | Some d -> fprintf out "ML_INTERFACE=true\nOCAML_SRC=%s\n" d
286 | None -> fprintf out "ML_INTERFACE=false\n");
287 fprintf out "PXP=%b\n" pxp;
288 fprintf out "EXPAT=%b\n" expat;
289 fprintf out "CURL=%b\n" curl;
290 fprintf out "NETCLIENT=%b\n" netclient;
291 fprintf out "CGI=%b\n" cgi;
292 fprintf out "PXP_WLEX=%b\n" pxp_wlex;
293 fprintf out "BINDIR=%s\n" bindir;
294 fprintf out "MANDIR=%s\n" mandir;
295 fprintf out "DOCDIR=%s\n" docdir;
296 fprintf out "CGI_DIR=%s\n" cgidir;
297 fprintf out "HTML_DIR=%s\n" htmldir;
298 fprintf out "SESSION_DIR=%s\n" sessiondir;
299 fprintf out "EXE=%s\n" exe;
300 fprintf out "ADDICON=%b\n" add_icon;
301 fprintf out "PROFILE=false\n";
302 fprintf out "FORPACK=%b\n" has_forpack;
303 fprintf out "NATDYNLINK=%b\n" has_natdynlink;
304 close_out out

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