Release of coccinelle 1.0.0-rc9
[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 $pcre=1;
32 my $noocamlscripting=0;
33 my $opt=".opt";
34 my $tarzan=1;
35 my $pydir="pycaml";
36 my $menhirdir="menhirlib";
37 my $sexpdir="ocamlsexp";
38 my $python_cmd="python";
39
40 # generic ocaml libraries (set entries to 0 to disable by default)
41 # 0: disabled, 1: use global library, >1: use local library
42 my %libs=
43 ( "pycaml" => 1
44 , "menhirLib" => 1
45 , "sexplib" => 1
46 , "pcre" => 1
47 , "dynlink" => 0
48 , "extlib" => 0
49 );
50
51 # add additional dependencies that some of these libraries may have
52 # these will then be added automatically
53 # (we don't really make use of this here)
54 my %deps=
55 ( # "pycaml" => ["str"] # example
56 # "sexplib" => ["unix", "bigarray", "num"]
57 );
58
59 local $_ = join ' ', @ARGV;
60
61 # Parse options
62 /-h/ || /--help/ and die "usage: $0 [--prefix=path] [--without-FEATURE] [--no-opt]\n
63 \t--without-python\tDisable scripting in Python
64 \t--without-ocaml\t\tDisable scripting in Ocaml
65 \t--without-pcre\t\tDisable regexp with PCRE
66 \t--with-pyton=PATH\t\tSpecify path to python executable
67 \t--no-opt\t\tDo not use the optimimized version of OCaml
68 \t--opt\t\t\tUse the optimimized version of OCaml\n\n";
69 /--prefix=([^ ]*)/ and $prefix = $1;
70 /--without-pcre/ and $pcre = 0;
71 /--without-python/ and $python = 0;
72 /--without-ocaml/ and $noocamlscripting = 1;
73 /--no-opt/ and $opt = "";
74 /--opt/ and $opt = ".opt";
75 /--with-python=([^ ]*)/ and $python_cmd = $1;
76
77 # todo: also print these options as part of the help message...
78 foreach my $lib (keys %libs) {
79 /--with-$lib/ and $libs{$lib} = 1;
80 /--with-local-$lib/ and $libs{$lib} = 2;
81 /--without-$lib/ and $libs{$lib} = 0;
82 }
83
84 #tarzan by default (used by score file parsing and now also for sexp_ast_c.ml)
85
86
87 # extend the feature set based on their dependencies
88 my $changedLibs = 1;
89 while($changedLibs) {
90 $changedLibs = 0;
91 foreach $dep (keys %deps) {
92 if ($libs{$dep}) {
93 my $reqs = $deps{$dep};
94 foreach $req (@$reqs) {
95 if (!$libs{$req}) {
96 $libs{$req} = 1;
97 $changedLibs = 1;
98 }
99 }
100 }
101 }
102 }
103
104 #if($ARGV[0] =~ "--prefix=(.*)") {
105 # $prefix = $1;
106 #}
107 #if($ARGV[1] =~ "--without-python") {
108 # $python = 0;
109 #}
110
111 my $src="$prefix/share/$project";
112
113 ######################################################################
114 # Side effects
115 ######################################################################
116
117
118 ######################################################################
119 # Helpers
120 ######################################################################
121 #BEGIN { die "need Perl 5 or greater" if $] < 5 ; }
122
123 #use Common;
124 sub pr2 { print STDERR "@_\n" }
125 sub cat {
126 my ($what) = @_;
127 my @list;
128 open(TMP, $what);
129 while(<TMP>) { push @list, "$_"; }
130 \@list;
131 }
132 sub notb { !$_[0] }
133 sub mapf { my ($f, $xs) = @_; [ map { &$f($_) } @{$xs} ] }
134 sub plural { my ($e) = @_; if ($e > 1) { "s" } else { "" } }
135
136 sub check_config { my ($command, $expect, $msggood, $msgbad) = @_;
137 my $error = 0;
138
139 my $full = cat($command);
140 my $res = join(" ", @{$full});
141 # pr2 $res;
142 if(notb($res =~ $expect)) { $error++; pr2 "!!!! $msgbad !!!!"; }
143 else { pr2 $msggood }
144 return $error;
145 }
146
147 ######################################################################
148 # Let's go
149 ######################################################################
150 pr2 "Checking your configuration.\n";
151
152 my $error = 0;
153
154 #---------------------------------------------------------------------
155 # Compilers and runtimes
156 #---------------------------------------------------------------------
157
158 $error +=
159 check_config("echo \"1;;\\n\" | ocaml |",
160 "Objective(.*) 3.\(09|1[0-9]\)",
161 "OCaml (the wonderful language) is present.",
162 "The program ocaml is missing or is not a good version. We need at least 3.09",
163 );
164
165 unless ($noocamlscripting) {
166 $noocamlscripting = check_config("echo \"1;;\\n\" | ocaml |",
167 "Objective(.*) 3.1[1-9]",
168 "OCaml >= 3.11 is present. OCaml scripting activated.",
169 "OCaml scripting disabled. We need at least OCaml 3.11",
170 );
171 }
172 my $ocamlprefix = $noocamlscripting ? "no" : "yes";
173
174 if ($opt eq ".opt") {
175 my $opt_check = `which ocamlc.opt 2> /dev/null`;
176 if($opt_check =~ "/ocamlc.opt\$") {
177 pr2 "ocamlc.opt is present.";
178 }
179 else {
180 $opt="";
181 pr2 "ocamlc.opt not found";
182 }
183
184 my $opt_check = `which ocamlopt.opt 2> /dev/null`;
185 if($opt_check =~ "/ocamlopt.opt\$") {
186 pr2 "ocamlopt.opt is present.";
187 }
188 else {
189 $opt="";
190 pr2 "ocamlopt.opt not found";
191 }
192
193 my $opt_check = `which ocamldep.opt 2> /dev/null`;
194 if($opt_check =~ "/ocamldep.opt\$") {
195 pr2 "ocamldep.opt is present.";
196 }
197 else {
198 $opt="";
199 pr2 "ocamldep.opt not found";
200 }
201
202 my $opt_check = `which ocamllex.opt 2> /dev/null`;
203 if($opt_check =~ "/ocamllex.opt\$") {
204 pr2 "ocamllex.opt is present.";
205 }
206 else {
207 $opt="";
208 pr2 "ocamllex.opt not found";
209 }
210
211 if($opt eq "") {
212 pr2 "At least one native OCaml tool have not been found.";
213 pr2 "Desactivation of all native OCaml tools for compilation.";
214 }
215 }
216
217 #we have cached the result of menhir in the tgz we build.
218
219 #$error +=
220 # check_config("menhir --version |",
221 # "menhir, version 20071212",
222 ## "menhir, version 2006.*",
223 # "Menhir (the parser generator) is present.",
224 # "The program menhir is missing or is not a good version.",
225 # );
226
227
228 #---------------------------------------------------------------
229 # Developers tools
230 #---------------------------------------------------------------
231
232 pr2 "";
233
234 $error += check_config(
235 "make -v 2>&1 |grep Make|",
236 "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
237 "make (gnu version) is present.",
238 "The program gnu make is missing or is not a good version.
239 We need 3.XX",
240 );
241
242 #---------------------------------------------------------------------
243 # More developers tools
244 #---------------------------------------------------------------------
245
246 #---------------------------------------------------------------------
247 # Librairies
248 #---------------------------------------------------------------------
249
250 # Python dev
251 my $PY_VERSION;
252 if($python) {
253 if(check_config(
254 "$python_cmd --version 2>&1 |",
255 '^Python [23]\.',
256 "$python_cmd is present",
257 "$python_cmd is missing or is not a good version."
258 ))
259 {
260 $python=0;
261 }
262 if($python) {
263 my $PY_PREFIX = `$python_cmd pycaml/getprefix.py | tr -d '\n'`;
264 $PY_VERSION = `$python_cmd pycaml/getversion.py | tr -d '\n'`;
265 my $python_hdr = "$PY_PREFIX/include/python$PY_VERSION/Python.h";
266 if(check_config(
267 "ls $python_hdr 2> /dev/null | ",
268 $python_hdr,
269 "Python.h found",
270 "Python.h missing - You need to install python-dev"
271 ))
272 {
273 $python=0
274 }
275 }
276 }
277
278 my $ocamlfind=!check_config(
279 "which ocamlfind 2> /dev/null |",
280 '/ocamlfind$',
281 "ocamlfind is present",
282 "ocamlfind is missing -- Switch to local library copies."
283 );
284
285 # pycaml. Binding between Python and OCaml
286 my $syspydir=`ocamlfind query pycaml 2> /dev/null | xargs echo -n`;
287
288 if($syspydir) {
289 pr2 "'pycaml' library is present in $syspydir";
290 if ($libs{'pycaml'} > 1) {
291 pr2 "... but a local copy of 'pycaml' will be used.";
292 }
293 else {
294 $pydir=$syspydir;
295 }
296 } else {
297 pr2 "'pycaml' library is not present. A local copy will be used.";
298 }
299
300 # menhirLib. Runtime system for the parsers generated with menhir
301 my $sysmenhirdir=`ocamlfind query menhirLib 2> /dev/null | xargs echo -n`;
302
303 if($sysmenhirdir) {
304 $menhirdir=$sysmenhirdir;
305 pr2 "'menhirLib' library is present in $menhirdir";
306 } else {
307 pr2 "'menhirLib' library is not present. A local copy will be used.";
308 }
309
310 # sexplib.
311 my $syssexpdir=`ocamlfind query sexplib 2> /dev/null | xargs echo -n`;
312
313 if($syssexpdir) {
314 $sexpdir=$syssexpdir;
315 pr2 "'sexplib' library is present in $sexpdir";
316 } else {
317 pr2 "'sexplib' library is not present. A local copy will be used.";
318 }
319
320 # Check if libpcre-ocaml is available
321 # when pcre feature is enabled.
322 my $pcredir="";
323 if($pcre) {
324 $pcredir=`ocamlfind query pcre 2> /dev/null | xargs echo -n `;
325 if(check_config(
326 "echo -n $pcredir | ",
327 '^/.*$',
328 "'pcre-ocaml' library is present in $pcredir",
329 "'pcre-ocaml' library is not present - You need to install libpcre-ocaml-dev"
330 ))
331 {
332 $pcre=0
333 }
334 }
335
336 ######################################################################
337 # Printing of library selection
338 ######################################################################
339
340
341 pr2 "----------------------------------------------------------------------";
342 pr2 "Library configuration:";
343
344 my %libPaths = {};
345 foreach my $lib (keys %libs) {
346 my $isSelected = $libs{$lib};
347 if ($isSelected) {
348 my $libdir = `ocamlfind query $lib 2> /dev/null | xargs echo -n`;
349 if ($libdir && $libs{$lib} <= 1) {
350 $libs{$lib} = 1;
351 $libPaths{$lib} = $libdir;
352 }
353 else {
354 if (-d $lib) { # test if local directory exists
355 $libs{$lib} = 2; # use local version
356 $libPaths{$lib} = $lib;
357 } else {
358 $libs{$lib} = 0; # disable the feature
359 $libPaths{$lib} = "";
360 }
361 }
362 }
363
364 my $choice = $libs{$lib};
365 if ($choice == 0) {
366 pr2 "$lib: disabled";
367 } elsif ($choice == 1) {
368 pr2 "$lib: global version in $libPaths{$lib}";
369 } else {
370 pr2 "$lib: local version selected";
371 }
372 }
373
374 ######################################################################
375 # Generate config files (platform/portability issues)
376 ######################################################################
377
378
379 ######################################################################
380 # Generate globals files (features issues)
381 ######################################################################
382
383 ######################################################################
384 # Diagnostic
385 ######################################################################
386
387 if($error) {
388 pr2 "
389 ----------------------------------------------------------------------
390 !!!! There seems to have problem, we have found $error missing package" .
391 plural($error) . ".
392 " . (($error > 1) ? "Some of those packages" : "This package") .
393 " may be installed by picking " . ($error > 1 ? "them" : "it") .
394 " in $project-dependencies.tgz available
395 on the $project website. !!!!
396 ----------------------------------------------------------------------
397 ";
398 } else {
399
400 pr2
401 "----------------------------------------------------------------------
402
403 All seems fine for $project.
404
405 To compile $project type:
406 \$ make depend
407 \$ make all
408
409 Or alternatively, for the optimized version:
410 \$ make all.opt
411 If you want both, you could use:
412 \$ make world
413
414
415 To install type:
416 \$ make install
417
418 Then, to test $project simply type:
419 \$ $projectcmdline
420
421 ";
422
423 if($python) {
424 pr2
425 "To use the python SmPL feature you may have to set some environment variables.
426 However, they are automatically set by the front-end installed in $prefix/bin.
427 For bash do:
428 export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
429 export PYTHONPATH=\$PYTHONPATH:$src/python"
430 }
431
432 pr2 "----------------------------------------------------------------------";
433 }
434
435 ######################################################################
436 # Generating the configuration
437 ######################################################################
438
439 pr2 " Compilation configuration\n";
440
441 pr2 "$project target prefix: $prefix (you can use --prefix to override it)";
442 pr2 "Generating Makefile.config";
443 open(CONFIG, ">Makefile.config");
444 print CONFIG "# autogenerated by configure
445
446 #
447 INSTALL_PROGRAM?=install -c -m 755
448 INSTALL_LIB?= install -c -m 755
449 INSTALL_DATA?= install -c -m 644
450
451 # Where to install the binary
452 BINDIR=$prefix/bin
453
454 # Where to install the man pages
455 MANDIR=$prefix/man
456
457 # Where to install the lib
458 LIBDIR=$prefix/lib
459
460 # Where to install the configuration files
461 SHAREDIR=$src
462
463 BASH_COMPLETION_DIR=/etc/bash_completion.d
464
465 # Features
466 FEATURE_PYTHON=$python
467 FEATURE_TARZAN=$tarzan
468 ";
469
470 if ($python) {
471 print CONFIG "PYVER=$PY_VERSION\n";
472 print CONFIG "PYCMD=$python_cmd\n";
473 }
474
475 if($pcre) {
476 print CONFIG "
477 PCREDIR=$pcredir"
478 }
479
480 print CONFIG "
481 PYCAMLDIR=$pydir
482 MENHIRDIR=$menhirdir
483 SEXPDIR=$sexpdir
484 DYNLINK=$ocamlprefix
485
486 # The OPTBIN variable is here to allow to use ocamlc.opt instead of
487 # ocaml, when it is available, which speeds up compilation. So
488 # if you want the fast version of the ocaml chain tools, set this var
489 # or setenv it to \".opt\" in your startup script.
490 OPTBIN=$opt
491 ";
492
493 #
494 # Generate variables for handling the ocaml libraries
495 #
496
497 my @sellibs = ();
498 my @makelibs = ();
499 my @cleanlibs = ();
500 my @deplibs = ();
501 my @lnklibs = ();
502 my @optlnklibs = ();
503 my @inclibs = ();
504 my @flagslibs = ();
505 my @featurelibs = ();
506 my @pathlibs = ();
507
508 sub strVar {
509 return "\$(" . $_[0] . "_" . $_[1] . ")";
510 }
511
512 foreach $lib (keys %libs) {
513 my $sel = $libs{$lib};
514 my $path = $libPaths{$lib};
515 my $pathvar = strVar("PATH", $lib);
516
517 if ($sel == 1) { # global version
518 push(@lnklibs, strVar("GLOBAL", $lib));
519 push(@optlnklibs, strVar("GLOBALOPT", $lib));
520 } elsif ($sel > 1) { # local version
521 push(@lnklibs, strVar("LOCAL", $lib));
522 push(@optlnklibs, strVar("LOCALOPT", $lib));
523 if (-e "$path/Makefile") { # does it have a Makefile?
524 push(@makelibs, $pathvar);
525 push(@cleanlibs, $pathvar);
526 push(@deplibs, $pathvar);
527 }
528 }
529
530 if ($sel >= 1) { # indifferent of global/local
531 push(@sellibs, $lib);
532 push(@inclibs, $pathvar);
533 push(@flagslibs, strVar("FLAGS", $lib));
534
535 push(@featurelibs, "FEATURE_$lib=1");
536 push(@pathlibs, "PATH_$lib=$path");
537 }
538 }
539
540 my $strSellibs = join(" ", @sellibs);
541 my $strMakelibs = join(" ", @makelibs);
542 my $strCleanlibs = join(" ", @cleanlibs);
543 my $strDeplibs = join(" ", @deplibs);
544 my $strLnklibs = join(" ", @lnklibs);
545 my $strOptlnklibs = join(" ", @optlnklibs);
546 my $strInclibs = join(" ", @inclibs);
547 my $strFlagslibs = join(" ", @flagslibs);
548 my $strFeatures = join("\n", @featurelibs);
549 my $strPaths = join("\n", @pathlibs);
550
551 print CONFIG "
552 # selected libraries
553 $strFeatures
554
555 # library paths
556 $strPaths
557
558 # collected config vars
559 SELLIBS=$strSellibs
560 MAKELIBS=$strMakelibs
561 CLEANLIBS=$strCleanlibs
562 DEPLIBS=$strDeplibs
563 LNKLIBS=$strLnklibs
564 OPTLNKLIBS=$strOptlnklibs
565 INCLIBS=$strInclibs
566 FLAGSLIBS=$strFlagslibs
567 ";
568
569
570 my $pythonprefix = $python ? "yes" : "no";
571 pr2 "Support for python scripting: $pythonprefix";
572 `cd python; ln -sf ${pythonprefix}_pycocci.ml pycocci.ml; `;
573 `cd python; make depend`;
574
575 pr2 "Support for ocaml scripting: $ocamlprefix";
576 `cd ocaml; ln -sf ${ocamlprefix}_prepare_ocamlcocci.ml prepare_ocamlcocci.ml;`;
577 `cd ocaml; make depend`;
578
579 my $pcresuffix = $pcre ? "pcre" : "str";
580 pr2 "Support for regexp: $pcresuffix";
581 `cd globals; ln -sf regexp_${pcresuffix}.ml regexp.ml; touch regexp.ml;`;
582 `cd globals; make depend`;
583
584 pr2 "Modifying globals/config.ml";
585 my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";
586 `$command`;
587
588 pr2 "----------------------------------------------------------------------";
589 pr2 " Runtime dependency\n";
590
591 if ($ocamlfind) {
592 pr2 "Support for external ocaml library in ocaml scripting: yes (ocamlfind found)";
593 }
594 else {
595 pr2 "Support for external ocaml library in ocaml scripting: no";
596 pr2 "!!!!!!! WARNING !!!!!!! ocamlfind may be required at runtime";
597 }
598
599 pr2 "";