/[svn]/configure.ml
ViewVC logotype

Contents of /configure.ml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1220 - (show annotations)
Tue Jul 10 18:32:18 2007 UTC (5 years, 10 months ago) by abate
File size: 7426 byte(s)
[r2004-07-05 14:15:03 by afrisch] auto find compiler-lib (e.g. for GODI)

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

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