Release coccinelle-0.2.3rc4
[bpt/coccinelle.git] / configure
1 #!/usr/bin/perl
2
3 # Author: Yoann Padioleau
4
5 ######################################################################
6 # Prelude
7 ######################################################################
8
9 # Yes I know about autoconf ... and autoconf sux.
10
11 # assume standard: diff
12 # assume standard: perl
13
14 #TODO check python 2.5 ?
15
16 # need latex and hevea if want to compile the documentation
17
18 #old: --with-menhir=/path/to/menhirLib or `ocamlfind query menhirLib`
19
20 my $project =
21 "coccinelle";
22 my $projectcmdline =
23 "spatch -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c";
24
25 ######################################################################
26 # Options
27 ######################################################################
28
29 my $prefix="/usr/local";
30 my $python=1;
31 my $noocamlscripting=0;
32 my $opt=".opt";
33 my $tarzan=1;
34 my $pydir="pycaml";
35 my $menhirdir="menhirlib";
36 my $sexpdir="ocamlsexp";
37
38 local $_ = join ' ', @ARGV;
39
40 # Parse options
41 /-h/ || /--help/ and die "usage: $0 [--prefix=path] [--without-python] [--no-opt]\n\n\t--no-opt\tDo not use the optimimized version of OCaml\n\t--opt\tUse the optimimized version of OCaml\n\n";
42 /--prefix=([^ ]*)/ and $prefix = $1;
43 /--without-python/ and $python = 0;
44 /--no-opt/ and $opt = "";
45 /--opt/ and $opt = ".opt";
46
47 #tarzan by default (used by score file parsing and now also for sexp_ast_c.ml)
48
49
50 #if($ARGV[0] =~ "--prefix=(.*)") {
51 # $prefix = $1;
52 #}
53 #if($ARGV[1] =~ "--without-python") {
54 # $python = 0;
55 #}
56
57 my $src="$prefix/share/$project";
58
59 ######################################################################
60 # Side effects
61 ######################################################################
62
63
64 ######################################################################
65 # Helpers
66 ######################################################################
67 #BEGIN { die "need Perl 5 or greater" if $] < 5 ; }
68
69 #use Common;
70 sub pr2 { print STDERR "@_\n" }
71 sub cat {
72 my ($what) = @_;
73 my @list;
74 open(TMP, $what);
75 while(<TMP>) { push @list, "$_"; }
76 \@list;
77 }
78 sub notb { !$_[0] }
79 sub mapf { my ($f, $xs) = @_; [ map { &$f($_) } @{$xs} ] }
80 sub plural { my ($e) = @_; if ($e > 1) { "s" } else { "" } }
81
82 sub check_config { my ($command, $expect, $msggood, $msgbad) = @_;
83 my $error = 0;
84
85 my $full = cat($command);
86 my $res = join(" ", @{$full});
87 # pr2 $res;
88 if(notb($res =~ $expect)) { $error++; pr2 "!!!! $msgbad !!!!"; }
89 else { pr2 $msggood }
90 return $error;
91 }
92
93 ######################################################################
94 # Let's go
95 ######################################################################
96 pr2 "Checking your configuration.\n";
97
98 my $error = 0;
99
100 #---------------------------------------------------------------------
101 # Compilers and runtimes
102 #---------------------------------------------------------------------
103
104 $error +=
105 check_config("echo \"1;;\\n\" | ocaml |",
106 "Objective(.*) 3.\(09|1[0-9]\)",
107 "OCaml (the wonderful language) is present.",
108 "The program ocaml is missing or is not a good version. We need at least 3.09",
109 );
110
111 $noocamlscripting = check_config("echo \"1;;\\n\" | ocaml |",
112 "Objective(.*) 3.1[1-9]",
113 "OCaml >= 3.11 is present. OCaml scripting activated.",
114 "OCaml scripting disabled. We need at least OCaml 3.11",
115 );
116
117 if ($opt eq ".opt") {
118 my $opt_check = `which ocamlc.opt 2> /dev/null`;
119 if($opt_check =~ "/ocamlc.opt\$") {
120 pr2 "ocamlc.opt is present.";
121 }
122 else {
123 $opt="";
124 pr2 "ocamlc.opt not found";
125 }
126
127 my $opt_check = `which ocamlopt.opt 2> /dev/null`;
128 if($opt_check =~ "/ocamlopt.opt\$") {
129 pr2 "ocamlopt.opt is present.";
130 }
131 else {
132 $opt="";
133 pr2 "ocamlopt.opt not found";
134 }
135
136 my $opt_check = `which ocamldep.opt 2> /dev/null`;
137 if($opt_check =~ "/ocamldep.opt\$") {
138 pr2 "ocamldep.opt is present.";
139 }
140 else {
141 $opt="";
142 pr2 "ocamldep.opt not found";
143 }
144
145 my $opt_check = `which ocamllex.opt 2> /dev/null`;
146 if($opt_check =~ "/ocamllex.opt\$") {
147 pr2 "ocamllex.opt is present.";
148 }
149 else {
150 $opt="";
151 pr2 "ocamllex.opt not found";
152 }
153
154 if($opt eq "") {
155 pr2 "At least one native OCaml tool have not been found.";
156 pr2 "Desactivation of all native OCaml tools for compilation.";
157 }
158 }
159
160 #we have cached the result of menhir in the tgz we build.
161
162 #$error +=
163 # check_config("menhir --version |",
164 # "menhir, version 20071212",
165 ## "menhir, version 2006.*",
166 # "Menhir (the parser generator) is present.",
167 # "The program menhir is missing or is not a good version.",
168 # );
169
170
171 #---------------------------------------------------------------
172 # Developers tools
173 #---------------------------------------------------------------
174
175 pr2 "";
176
177 $error += check_config(
178 "make -v 2>&1 |grep Make|",
179 "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
180 "make (gnu version) is present.",
181 "The program gnu make is missing or is not a good version.
182 We need 3.XX",
183 );
184
185
186 #---------------------------------------------------------------------
187 # More developers tools
188 #---------------------------------------------------------------------
189
190 #---------------------------------------------------------------------
191 # Librairies
192 #---------------------------------------------------------------------
193
194 # pycaml. Binding between Python and OCaml
195 my $syspydir=`ocamlfind query pycaml 2> /dev/null | xargs echo -n`;
196
197 if($syspydir) {
198 $pydir=$syspydir;
199 pr2 "'pycaml' library is present in $pydir";
200 } else {
201 pr2 "'pycaml' library is not present. A local copy will be used.";
202 }
203
204 # menhirLib. Runtime system for the parsers generated with menhir
205 my $sysmenhirdir=`ocamlfind query menhirLib 2> /dev/null | xargs echo -n`;
206
207 if($sysmenhirdir) {
208 $menhirdir=$sysmenhirdir;
209 pr2 "'menhirLib' library is present in $menhirdir";
210 } else {
211 pr2 "'menhirLib' library is not present. A local copy will be used..";
212 }
213
214 # sexplib. Runtime system for the parsers generated with menhir
215 my $syssexpdir=`ocamlfind query sexplib 2> /dev/null | xargs echo -n`;
216
217 if($syssexpdir) {
218 $sexpdir=$syssexpdir;
219 pr2 "'sexplib' library is present in $sexpdir";
220 } else {
221 pr2 "'sexplib' library is not present. A local copy will be used..";
222 }
223
224 ######################################################################
225 # Generate config files (platform/portability issues)
226 ######################################################################
227
228
229 ######################################################################
230 # Generate globals files (features issues)
231 ######################################################################
232
233 ######################################################################
234 # Diagnostic
235 ######################################################################
236
237
238 if($error) {
239 pr2 "
240 ----------------------------------------------------------------------
241 !!!! There seems to have problem, we have found $error missing package" .
242 plural($error) . ".
243 " . (($error > 1) ? "Some of those packages" : "This package") .
244 " may be installed by picking " . ($error > 1 ? "them" : "it") .
245 " in $project-dependencies.tgz available
246 on the $project website. !!!!
247 ----------------------------------------------------------------------
248 ";
249 } else {
250
251 pr2
252 "----------------------------------------------------------------------
253
254 All seems fine for $project.
255
256 To compile $project type:
257 \$ make depend
258 \$ make all
259
260 Or alternatively, for the optimized version:
261 \$ make all.opt
262 If you want both, you could use:
263 \$ make world
264
265
266 To install type:
267 \$ make install
268
269 Then, to test $project simply type:
270 \$ $projectcmdline
271
272 ";
273
274 if($python) {
275 pr2
276 "To use the python SmPL feature you may have to set some environment variables.
277 However, they are automatically set by the front-end installed in $prefix/bin.
278 For bash do:
279 export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
280 export PYTHONPATH=\$PYTHONPATH:$src/python"
281 }
282 pr2 "----------------------------------------------------------------------";
283 }
284
285 ######################################################################
286 # Generating the configuration
287 ######################################################################
288
289 pr2 "$project target prefix: $prefix (you can use --prefix to override it)";
290 pr2 "Generating Makefile.config";
291 open(CONFIG, ">Makefile.config");
292 print CONFIG "# autogenerated by configure
293
294 #
295 INSTALL_PROGRAM?=install -c -m 755
296 INSTALL_LIB?= install -c -m 755
297 INSTALL_DATA?= install -c -m 644
298
299 # Where to install the binary
300 BINDIR=$prefix/bin
301
302 # Where to install the man pages
303 MANDIR=$prefix/man
304
305 # Where to install the lib
306 LIBDIR=$prefix/lib
307
308 # Where to install the configuration files
309 SHAREDIR=$src
310
311 BASH_COMPLETION_DIR=/etc/bash_completion.d
312
313 # Features
314 FEATURE_PYTHON=$python
315 FEATURE_TARZAN=$tarzan
316
317 PYCAMLDIR=$pydir
318 MENHIRDIR=$menhirdir
319 SEXPDIR=$sexpdir
320
321 # The OPTBIN variable is here to allow to use ocamlc.opt instead of
322 # ocaml, when it is available, which speeds up compilation. So
323 # if you want the fast version of the ocaml chain tools, set this var
324 # or setenv it to \".opt\" in your startup script.
325 OPTBIN=$opt
326 ";
327
328
329 my $pythonprefix = $python ? "yes" : "no";
330 pr2 "Support for python scripting : $pythonprefix";
331 `cd python; ln -sf ${pythonprefix}_pycocci.ml pycocci.ml; `;
332 `cd python; ln -sf ${pythonprefix}_pycocci_aux.ml pycocci_aux.ml;`;
333 `cd python; make depend`;
334
335 my $ocamlprefix = $noocamlscripting ? "no" : "yes";
336 pr2 "Support for ocaml scripting : $ocamlprefix";
337 `cd ocaml; ln -sf ${ocamlprefix}_prepare_ocamlcocci.ml prepare_ocamlcocci.ml;`;
338 `cd ocaml; make depend`;
339
340 pr2 "Modifying globals/config.ml";
341 my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";
342 `$command`;
343