Release of coccinelle 1.0.0-rc9
[bpt/coccinelle.git] / configure
CommitLineData
34e49164 1#!/usr/bin/perl
708f4980 2
fc1ad971 3# Author: Yoann Padioleau
708f4980 4
34e49164
C
5######################################################################
6# Prelude
7######################################################################
8
9# Yes I know about autoconf ... and autoconf sux.
10
11# assume standard: diff
12# assume standard: perl
13
708f4980 14#TODO check python 2.5 ?
34e49164 15
978fd7e5
C
16# need latex and hevea if want to compile the documentation
17
34e49164
C
18#old: --with-menhir=/path/to/menhirLib or `ocamlfind query menhirLib`
19
0708f913 20my $project =
34e49164 21 "coccinelle";
0708f913 22my $projectcmdline =
978fd7e5 23 "spatch -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c";
34e49164 24
34e49164
C
25######################################################################
26# Options
27######################################################################
28
29my $prefix="/usr/local";
30my $python=1;
993936c0 31my $pcre=1;
174d1640 32my $noocamlscripting=0;
0708f913 33my $opt=".opt";
978fd7e5 34my $tarzan=1;
90aeb998
C
35my $pydir="pycaml";
36my $menhirdir="menhirlib";
37my $sexpdir="ocamlsexp";
97111a47
C
38my $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
42my %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)
54my %deps=
55 ( # "pycaml" => ["str"] # example
56 # "sexplib" => ["unix", "bigarray", "num"]
57 );
34e49164
C
58
59local $_ = join ' ', @ARGV;
60
61# Parse options
993936c0
C
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
97111a47 66\t--with-pyton=PATH\t\tSpecify path to python executable
993936c0
C
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";
34e49164 69/--prefix=([^ ]*)/ and $prefix = $1;
993936c0 70/--without-pcre/ and $pcre = 0;
34e49164 71/--without-python/ and $python = 0;
c491d8ee 72/--without-ocaml/ and $noocamlscripting = 1;
0708f913 73/--no-opt/ and $opt = "";
8ba84ae2 74/--opt/ and $opt = ".opt";
97111a47
C
75/--with-python=([^ ]*)/ and $python_cmd = $1;
76
77# todo: also print these options as part of the help message...
78foreach 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}
34e49164 83
978fd7e5
C
84#tarzan by default (used by score file parsing and now also for sexp_ast_c.ml)
85
86
97111a47
C
87# extend the feature set based on their dependencies
88my $changedLibs = 1;
89while($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
34e49164
C
104#if($ARGV[0] =~ "--prefix=(.*)") {
105# $prefix = $1;
106#}
107#if($ARGV[1] =~ "--without-python") {
108# $python = 0;
109#}
110
111my $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;
124sub pr2 { print STDERR "@_\n" }
0708f913 125sub cat {
34e49164
C
126 my ($what) = @_;
127 my @list;
128 open(TMP, $what);
129 while(<TMP>) { push @list, "$_"; }
130 \@list;
131}
132sub notb { !$_[0] }
133sub mapf { my ($f, $xs) = @_; [ map { &$f($_) } @{$xs} ] }
134sub plural { my ($e) = @_; if ($e > 1) { "s" } else { "" } }
135
136sub check_config { my ($command, $expect, $msggood, $msgbad) = @_;
137 my $error = 0;
0708f913 138
34e49164
C
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######################################################################
150pr2 "Checking your configuration.\n";
151
152my $error = 0;
153
34e49164
C
154#---------------------------------------------------------------------
155# Compilers and runtimes
156#---------------------------------------------------------------------
174d1640 157
0708f913 158$error +=
34e49164 159 check_config("echo \"1;;\\n\" | ocaml |",
174d1640 160 "Objective(.*) 3.\(09|1[0-9]\)",
34e49164
C
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
3a314143 165unless ($noocamlscripting) {
174d1640
C
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 );
c491d8ee 171}
88e71198 172my $ocamlprefix = $noocamlscripting ? "no" : "yes";
174d1640 173
0708f913 174if ($opt eq ".opt") {
8ba84ae2
C
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 {
0708f913 198 $opt="";
8ba84ae2
C
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.";
0708f913
C
205 }
206 else {
8ba84ae2
C
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.";
0708f913
C
214 }
215}
216
34e49164
C
217#we have cached the result of menhir in the tgz we build.
218
0708f913 219#$error +=
34e49164
C
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
232pr2 "";
233
234$error += check_config(
235 "make -v 2>&1 |grep Make|",
708f4980 236 "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
34e49164
C
237 "make (gnu version) is present.",
238 "The program gnu make is missing or is not a good version.
239We need 3.XX",
240);
241
34e49164
C
242#---------------------------------------------------------------------
243# More developers tools
244#---------------------------------------------------------------------
245
246#---------------------------------------------------------------------
247# Librairies
248#---------------------------------------------------------------------
249
3a314143 250# Python dev
b23ff9c7 251my $PY_VERSION;
3a314143
C
252if($python) {
253 if(check_config(
97111a47
C
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."
3a314143
C
258 ))
259 {
260 $python=0;
261 }
262 if($python) {
97111a47
C
263 my $PY_PREFIX = `$python_cmd pycaml/getprefix.py | tr -d '\n'`;
264 $PY_VERSION = `$python_cmd pycaml/getversion.py | tr -d '\n'`;
3a314143
C
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
ca417fcf
C
278my $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
90aeb998
C
285# pycaml. Binding between Python and OCaml
286my $syspydir=`ocamlfind query pycaml 2> /dev/null | xargs echo -n`;
287
288if($syspydir) {
97111a47
C
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 }
174d1640
C
296} else {
297 pr2 "'pycaml' library is not present. A local copy will be used.";
90aeb998
C
298}
299
300# menhirLib. Runtime system for the parsers generated with menhir
301my $sysmenhirdir=`ocamlfind query menhirLib 2> /dev/null | xargs echo -n`;
302
303if($sysmenhirdir) {
304 $menhirdir=$sysmenhirdir;
174d1640
C
305 pr2 "'menhirLib' library is present in $menhirdir";
306} else {
993936c0 307 pr2 "'menhirLib' library is not present. A local copy will be used.";
90aeb998
C
308}
309
97111a47 310# sexplib.
90aeb998
C
311my $syssexpdir=`ocamlfind query sexplib 2> /dev/null | xargs echo -n`;
312
313if($syssexpdir) {
314 $sexpdir=$syssexpdir;
174d1640
C
315 pr2 "'sexplib' library is present in $sexpdir";
316} else {
993936c0
C
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.
322my $pcredir="";
323if($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 }
90aeb998
C
334}
335
97111a47
C
336######################################################################
337# Printing of library selection
338######################################################################
339
340
341pr2 "----------------------------------------------------------------------";
342pr2 "Library configuration:";
343
344my %libPaths = {};
345foreach 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
34e49164
C
374######################################################################
375# Generate config files (platform/portability issues)
376######################################################################
377
378
379######################################################################
380# Generate globals files (features issues)
381######################################################################
382
383######################################################################
0708f913 384# Diagnostic
34e49164
C
385######################################################################
386
0708f913 387if($error) {
34e49164
C
388 pr2 "
389----------------------------------------------------------------------
0708f913 390!!!! There seems to have problem, we have found $error missing package" .
34e49164 391plural($error) . ".
0708f913
C
392" . (($error > 1) ? "Some of those packages" : "This package") .
393 " may be installed by picking " . ($error > 1 ? "them" : "it") .
34e49164
C
394 " in $project-dependencies.tgz available
395on the $project website. !!!!
396----------------------------------------------------------------------
397";
0708f913 398} else {
34e49164 399
174d1640
C
400 pr2
401"----------------------------------------------------------------------
34e49164
C
402
403All seems fine for $project.
404
405To compile $project type:
708f4980
C
406 \$ make depend
407 \$ make all
408
409Or alternatively, for the optimized version:
410 \$ make all.opt
b1b2de81 411If you want both, you could use:
708f4980
C
412 \$ make world
413
34e49164
C
414
415To install type:
708f4980 416 \$ make install
34e49164
C
417
418Then, to test $project simply type:
708f4980 419 \$ $projectcmdline
34e49164
C
420
421";
422
ca417fcf
C
423 if($python) {
424 pr2
34e49164 425"To use the python SmPL feature you may have to set some environment variables.
174d1640 426However, they are automatically set by the front-end installed in $prefix/bin.
34e49164
C
427For bash do:
428export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
174d1640 429export PYTHONPATH=\$PYTHONPATH:$src/python"
34e49164 430 }
ca417fcf 431
174d1640 432 pr2 "----------------------------------------------------------------------";
34e49164
C
433}
434
34e49164
C
435######################################################################
436# Generating the configuration
437######################################################################
438
ca417fcf
C
439pr2 " Compilation configuration\n";
440
34e49164
C
441pr2 "$project target prefix: $prefix (you can use --prefix to override it)";
442pr2 "Generating Makefile.config";
443open(CONFIG, ">Makefile.config");
444print CONFIG "# autogenerated by configure
445
8ba84ae2
C
446#
447INSTALL_PROGRAM?=install -c -m 755
448INSTALL_LIB?= install -c -m 755
449INSTALL_DATA?= install -c -m 644
450
34e49164
C
451# Where to install the binary
452BINDIR=$prefix/bin
453
454# Where to install the man pages
455MANDIR=$prefix/man
456
457# Where to install the lib
458LIBDIR=$prefix/lib
459
460# Where to install the configuration files
461SHAREDIR=$src
462
174d1640
C
463BASH_COMPLETION_DIR=/etc/bash_completion.d
464
34e49164
C
465# Features
466FEATURE_PYTHON=$python
978fd7e5 467FEATURE_TARZAN=$tarzan
b23ff9c7
C
468";
469
470if ($python) {
97111a47
C
471print CONFIG "PYVER=$PY_VERSION\n";
472print CONFIG "PYCMD=$python_cmd\n";
b23ff9c7 473}
0708f913 474
993936c0
C
475if($pcre) {
476print CONFIG "
477PCREDIR=$pcredir"
478}
479
b23ff9c7 480print CONFIG "
90aeb998
C
481PYCAMLDIR=$pydir
482MENHIRDIR=$menhirdir
483SEXPDIR=$sexpdir
88e71198 484DYNLINK=$ocamlprefix
90aeb998 485
0708f913
C
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.
490OPTBIN=$opt
34e49164
C
491";
492
97111a47
C
493#
494# Generate variables for handling the ocaml libraries
495#
496
497my @sellibs = ();
498my @makelibs = ();
499my @cleanlibs = ();
500my @deplibs = ();
501my @lnklibs = ();
502my @optlnklibs = ();
503my @inclibs = ();
504my @flagslibs = ();
505my @featurelibs = ();
506my @pathlibs = ();
507
508sub strVar {
509 return "\$(" . $_[0] . "_" . $_[1] . ")";
510}
511
512foreach $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
540my $strSellibs = join(" ", @sellibs);
541my $strMakelibs = join(" ", @makelibs);
542my $strCleanlibs = join(" ", @cleanlibs);
543my $strDeplibs = join(" ", @deplibs);
544my $strLnklibs = join(" ", @lnklibs);
545my $strOptlnklibs = join(" ", @optlnklibs);
546my $strInclibs = join(" ", @inclibs);
547my $strFlagslibs = join(" ", @flagslibs);
548my $strFeatures = join("\n", @featurelibs);
549my $strPaths = join("\n", @pathlibs);
550
551print CONFIG "
552# selected libraries
553$strFeatures
554
555# library paths
556$strPaths
557
558# collected config vars
559SELLIBS=$strSellibs
560MAKELIBS=$strMakelibs
561CLEANLIBS=$strCleanlibs
562DEPLIBS=$strDeplibs
563LNKLIBS=$strLnklibs
564OPTLNKLIBS=$strOptlnklibs
565INCLIBS=$strInclibs
566FLAGSLIBS=$strFlagslibs
567";
568
174d1640
C
569
570my $pythonprefix = $python ? "yes" : "no";
ca417fcf 571pr2 "Support for python scripting: $pythonprefix";
174d1640 572`cd python; ln -sf ${pythonprefix}_pycocci.ml pycocci.ml; `;
34e49164
C
573`cd python; make depend`;
574
ca417fcf 575pr2 "Support for ocaml scripting: $ocamlprefix";
174d1640
C
576`cd ocaml; ln -sf ${ocamlprefix}_prepare_ocamlcocci.ml prepare_ocamlcocci.ml;`;
577`cd ocaml; make depend`;
578
993936c0
C
579my $pcresuffix = $pcre ? "pcre" : "str";
580pr2 "Support for regexp: $pcresuffix";
581`cd globals; ln -sf regexp_${pcresuffix}.ml regexp.ml; touch regexp.ml;`;
582`cd globals; make depend`;
583
174d1640 584pr2 "Modifying globals/config.ml";
b1b2de81 585my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";
34e49164
C
586`$command`;
587
ca417fcf
C
588pr2 "----------------------------------------------------------------------";
589pr2 " Runtime dependency\n";
590
591if ($ocamlfind) {
592pr2 "Support for external ocaml library in ocaml scripting: yes (ocamlfind found)";
593}
594else {
8babbc8f
C
595pr2 "Support for external ocaml library in ocaml scripting: no";
596pr2 "!!!!!!! WARNING !!!!!!! ocamlfind may be required at runtime";
ca417fcf
C
597}
598
599pr2 "";