/[svn]/configure.ml
ViewVC logotype

Contents of /configure.ml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1119 - (show annotations)
Tue Jul 10 18:24:00 2007 UTC (5 years, 10 months ago) by abate
File size: 7886 byte(s)
[r2004-06-19 22:56:22 by beppe] Added godo default installation directory of ocaml sources

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

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