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

Contents of /cduce/trunk/configure.ml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3939 - (show annotations)
Mon Jan 21 15:51:42 2008 UTC (5 years, 4 months ago) by karoline
File size: 8754 byte(s)
Add icon to cduce exe file in Cygwin/MinGW
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 | "Win32" ->
166 print "Win32 detected... executable will have .exe extension\n"; ".exe"
167 | "Cygwin" ->
168 print "Cygwin detected... executable will have .exe extension\n"; ".exe"
169 | _ -> ""
170
171 let add_icon = match Sys.os_type with
172 | "Win32" | "Cygwin" -> true
173 | _ -> false
174
175 let check_mliface dir =
176 (* Sys.file_exists (Filename.concat dir "typing/types.ml") *)
177 Sys.file_exists (Filename.concat dir "typing/types.ml")
178
179 let ocaml_stdlib () =
180 if (Sys.command "ocamlc -where > ocaml_stdlib" <> 0) then
181 fatal "Can't run ocamlc to get OCaml standard library path";
182 let ic = open_in "ocaml_stdlib" in
183 let s = input_line ic in
184 close_in ic;
185 Sys.remove "ocaml_stdlib";
186 s
187
188 let make_absolute dir =
189 if Filename.is_relative dir
190 then Filename.concat (Sys.getcwd ()) dir
191 else dir
192
193 let ml_interface =
194 let dir1 = !(List.assoc "mliface" vars) in
195 let dirs = if dir1 = "" then [] else [ make_absolute dir1 ] in
196 print "ocaml sources... ";
197 let rec loop = function
198 | [] ->
199 print "not found (the interface will not be built)\n";
200 None
201 | d::dirs ->
202 if check_mliface d then
203 (print ("found: " ^ d ^ "\n"); Some d)
204 else loop dirs
205 in
206 loop dirs
207
208 let pxp = check_feature "pxp" (check_pkg "pxp")
209 let expat = check_feature "expat" (check_pkg "expat")
210 let curl = check_feature "curl" (check_pkg "curl")
211 let netclient = check_feature "netclient" (check_pkg "netclient")
212 let pxp_wlex = check_feature "pxp_wlex" (check_pkg "pxp-wlex-utf8")
213 let prefix = dir "prefix"
214 let bindir = dir ~def:(prefix^"/bin") "bindir"
215 let mandir = dir ~def:(prefix^"/man") "mandir"
216 let docdir = dir ~def:(prefix^"/doc/cduce") "docdir"
217 let wprefix = dir "wprefix"
218 let cgidir = dir ~def:(wprefix^"/cgi-bin") "cgidir"
219 let htmldir = dir ~def:(wprefix^"/html") "htmldir"
220 let sessiondir = dir "sessiondir"
221
222 let curl,netclient =
223 match curl,netclient with
224 | true,true ->
225 warning "Both netclient and curl are available. Will use curl.";
226 true,false
227 | false,false ->
228 warning "No package for loading external URLs.";
229 false,false
230 | c,n -> c,n
231
232 let pxp,expat =
233 match pxp,expat with
234 | true,true ->
235 warning "Both PXP and expat are available. Will build both and use expat by default.";
236 true,true
237 | false,false ->
238 warning "No package for parsing XML documents.";
239 false,false
240 | c,n -> c,n
241
242 let required_packages = ["camlp4"; "num"; "pcre"; "ulex"; "cgi"; "netstring"]
243
244 let has_forpack =
245 print "testing for -for-pack option: ";
246 let comm =
247 match Sys.os_type with
248 | "Win32" -> "ocamlc -for-pack foo"
249 | _ -> "ocamlc -for-pack foo 2> /dev/null" in
250 if Sys.command comm = 0 then
251 (print "available\n"; true)
252 else
253 (print "not available\n"; false)
254
255 let has_natdynlink =
256 print "testing for native dynlink: ";
257 if Sys.command "ocamlopt -o foo dynlink.cmxa && rm -f foo" = 0 then
258 (printf "available\n"; true)
259 else
260 (print "not available\n"; false)
261
262 let () =
263 List.iter need_pkg required_packages;
264 if pxp then (
265 need_pkg "pxp-engine";
266 need_pkg "pxp-lex-iso88591";
267 if not pxp_wlex then need_pkg "pxp-lex-utf8";
268 );
269
270 print "Creating Makefile.conf...\n";
271
272 let out = open_out "Makefile.conf" in
273 fprintf out "# This file has been generated by the configure script\n";
274 fprintf out "NATIVE=%b\n" native;
275 (match ml_interface with
276 | Some d -> fprintf out "ML_INTERFACE=true\nOCAML_SRC=%s\n" d
277 | None -> fprintf out "ML_INTERFACE=false\n");
278 fprintf out "PXP=%b\n" pxp;
279 fprintf out "EXPAT=%b\n" expat;
280 fprintf out "CURL=%b\n" curl;
281 fprintf out "NETCLIENT=%b\n" netclient;
282 fprintf out "PXP_WLEX=%b\n" pxp_wlex;
283 fprintf out "BINDIR=%s\n" bindir;
284 fprintf out "MANDIR=%s\n" mandir;
285 fprintf out "DOCDIR=%s\n" docdir;
286 fprintf out "CGI_DIR=%s\n" cgidir;
287 fprintf out "HTML_DIR=%s\n" htmldir;
288 fprintf out "SESSION_DIR=%s\n" sessiondir;
289 fprintf out "EXE=%s\n" exe;
290 fprintf out "ADDICON=%b\n" add_icon;
291 fprintf out "PROFILE=false\n";
292 fprintf out "FORPACK=%b\n" has_forpack;
293 fprintf out "NATDYNLINK=%b\n" has_natdynlink;
294 close_out out

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