3 # Author: Yoann Padioleau
5 ######################################################################
7 ######################################################################
9 # Yes I know about autoconf ... and autoconf sux.
11 # assume standard: diff
12 # assume standard: perl
14 #TODO check python 2.5 ?
16 # need latex and hevea if want to compile the documentation
18 #old: --with-menhir=/path/to/menhirLib or `ocamlfind query menhirLib`
23 "spatch -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c";
25 ######################################################################
27 ######################################################################
29 my $prefix="/usr/local";
32 my $noocamlscripting=0;
36 my $menhirdir="menhirlib";
37 my $sexpdir="ocamlsexp";
38 my $python_cmd="python";
40 # generic ocaml libraries (set entries to 0 to disable by default)
41 # 0: disabled, 1: use global library, >1: use local library
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)
55 ( # "pycaml" => ["str"] # example
56 # "sexplib" => ["unix", "bigarray", "num"]
59 local $_ = join ' ', @ARGV;
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;
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;
84 #tarzan by default (used by score file parsing and now also for sexp_ast_c.ml)
87 # extend the feature set based on their dependencies
91 foreach $dep (keys %deps) {
93 my $reqs = $deps{$dep};
94 foreach $req (@
$reqs) {
104 #if($ARGV[0] =~ "--prefix=(.*)") {
107 #if($ARGV[1] =~ "--without-python") {
111 my $src="$prefix/share/$project";
113 ######################################################################
115 ######################################################################
118 ######################################################################
120 ######################################################################
121 #BEGIN { die "need Perl 5 or greater" if $] < 5 ; }
124 sub pr2
{ print STDERR
"@_\n" }
129 while(<TMP
>) { push @list, "$_"; }
133 sub mapf
{ my ($f, $xs) = @_; [ map { &$f($_) } @
{$xs} ] }
134 sub plural
{ my ($e) = @_; if ($e > 1) { "s" } else { "" } }
136 sub check_config
{ my ($command, $expect, $msggood, $msgbad) = @_;
139 my $full = cat
($command);
140 my $res = join(" ", @
{$full});
142 if(notb
($res =~ $expect)) { $error++; pr2
"!!!! $msgbad !!!!"; }
143 else { pr2
$msggood }
147 ######################################################################
149 ######################################################################
150 pr2
"Checking your configuration.\n";
154 #---------------------------------------------------------------------
155 # Compilers and runtimes
156 #---------------------------------------------------------------------
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",
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",
172 my $ocamlprefix = $noocamlscripting ?
"no" : "yes";
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.";
181 pr2
"ocamlc.opt not found";
184 my $opt_check = `which ocamlopt.opt 2> /dev/null`;
185 if($opt_check =~ "/ocamlopt.opt\$") {
186 pr2
"ocamlopt.opt is present.";
190 pr2
"ocamlopt.opt not found";
193 my $opt_check = `which ocamldep.opt 2> /dev/null`;
194 if($opt_check =~ "/ocamldep.opt\$") {
195 pr2
"ocamldep.opt is present.";
199 pr2
"ocamldep.opt not found";
202 my $opt_check = `which ocamllex.opt 2> /dev/null`;
203 if($opt_check =~ "/ocamllex.opt\$") {
204 pr2
"ocamllex.opt is present.";
208 pr2
"ocamllex.opt not found";
212 pr2
"At least one native OCaml tool have not been found.";
213 pr2
"Desactivation of all native OCaml tools for compilation.";
217 #we have cached the result of menhir in the tgz we build.
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.",
228 #---------------------------------------------------------------
230 #---------------------------------------------------------------
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.
242 #---------------------------------------------------------------------
243 # More developers tools
244 #---------------------------------------------------------------------
246 #---------------------------------------------------------------------
248 #---------------------------------------------------------------------
254 "$python_cmd --version 2>&1 |",
256 "$python_cmd is present",
257 "$python_cmd is missing or is not a good version."
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";
267 "ls $python_hdr 2> /dev/null | ",
270 "Python.h missing - You need to install python-dev"
278 my $ocamlfind=!check_config
(
279 "which ocamlfind 2> /dev/null |",
281 "ocamlfind is present",
282 "ocamlfind is missing -- Switch to local library copies."
285 # pycaml. Binding between Python and OCaml
286 my $syspydir=`ocamlfind query pycaml 2> /dev/null | xargs echo -n`;
289 pr2
"'pycaml' library is present in $syspydir";
290 if ($libs{'pycaml'} > 1) {
291 pr2
"... but a local copy of 'pycaml' will be used.";
297 pr2
"'pycaml' library is not present. A local copy will be used.";
300 # menhirLib. Runtime system for the parsers generated with menhir
301 my $sysmenhirdir=`ocamlfind query menhirLib 2> /dev/null | xargs echo -n`;
304 $menhirdir=$sysmenhirdir;
305 pr2
"'menhirLib' library is present in $menhirdir";
307 pr2
"'menhirLib' library is not present. A local copy will be used.";
311 my $syssexpdir=`ocamlfind query sexplib 2> /dev/null | xargs echo -n`;
314 $sexpdir=$syssexpdir;
315 pr2
"'sexplib' library is present in $sexpdir";
317 pr2
"'sexplib' library is not present. A local copy will be used.";
320 # Check if libpcre-ocaml is available
321 # when pcre feature is enabled.
324 $pcredir=`ocamlfind query pcre 2> /dev/null | xargs echo -n `;
326 "echo -n $pcredir | ",
328 "'pcre-ocaml' library is present in $pcredir",
329 "'pcre-ocaml' library is not present - You need to install libpcre-ocaml-dev"
336 ######################################################################
337 # Printing of library selection
338 ######################################################################
341 pr2
"----------------------------------------------------------------------";
342 pr2
"Library configuration:";
345 foreach my $lib (keys %libs) {
346 my $isSelected = $libs{$lib};
348 my $libdir = `ocamlfind query $lib 2> /dev/null | xargs echo -n`;
349 if ($libdir && $libs{$lib} <= 1) {
351 $libPaths{$lib} = $libdir;
354 if (-d
$lib) { # test if local directory exists
355 $libs{$lib} = 2; # use local version
356 $libPaths{$lib} = $lib;
358 $libs{$lib} = 0; # disable the feature
359 $libPaths{$lib} = "";
364 my $choice = $libs{$lib};
366 pr2
"$lib: disabled";
367 } elsif ($choice == 1) {
368 pr2
"$lib: global version in $libPaths{$lib}";
370 pr2
"$lib: local version selected";
374 ######################################################################
375 # Generate config files (platform/portability issues)
376 ######################################################################
379 ######################################################################
380 # Generate globals files (features issues)
381 ######################################################################
383 ######################################################################
385 ######################################################################
389 ----------------------------------------------------------------------
390 !!!! There seems to have problem, we have found $error missing package" .
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 ----------------------------------------------------------------------
401 "----------------------------------------------------------------------
403 All seems fine for $project.
405 To compile $project type:
409 Or alternatively, for the optimized version:
411 If you want both, you could use:
418 Then, to test $project simply type:
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.
428 export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
429 export PYTHONPATH=\$PYTHONPATH:$src/python"
432 pr2
"----------------------------------------------------------------------";
435 ######################################################################
436 # Generating the configuration
437 ######################################################################
439 pr2
" Compilation configuration\n";
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
447 INSTALL_PROGRAM?=install -c -m 755
448 INSTALL_LIB?= install -c -m 755
449 INSTALL_DATA?= install -c -m 644
451 # Where to install the binary
454 # Where to install the man pages
457 # Where to install the lib
460 # Where to install the configuration files
463 BASH_COMPLETION_DIR=/etc/bash_completion.d
466 FEATURE_PYTHON=$python
467 FEATURE_TARZAN=$tarzan
471 print CONFIG
"PYVER=$PY_VERSION\n";
472 print CONFIG
"PYCMD=$python_cmd\n";
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.
494 # Generate variables for handling the ocaml libraries
505 my @featurelibs = ();
509 return "\$(" . $_[0] . "_" . $_[1] . ")";
512 foreach $lib (keys %libs) {
513 my $sel = $libs{$lib};
514 my $path = $libPaths{$lib};
515 my $pathvar = strVar
("PATH", $lib);
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);
530 if ($sel >= 1) { # indifferent of global/local
531 push(@sellibs, $lib);
532 push(@inclibs, $pathvar);
533 push(@flagslibs, strVar
("FLAGS", $lib));
535 push(@featurelibs, "FEATURE_$lib=1");
536 push(@pathlibs, "PATH_$lib=$path");
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);
558 # collected config vars
560 MAKELIBS=$strMakelibs
561 CLEANLIBS=$strCleanlibs
564 OPTLNKLIBS=$strOptlnklibs
566 FLAGSLIBS=$strFlagslibs
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`;
575 pr2
"Support for ocaml scripting: $ocamlprefix";
576 `cd ocaml; ln -sf ${ocamlprefix}_prepare_ocamlcocci.ml prepare_ocamlcocci.ml;`;
577 `cd ocaml; make depend`;
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`;
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";
588 pr2
"----------------------------------------------------------------------";
589 pr2
" Runtime dependency\n";
592 pr2
"Support for external ocaml library in ocaml scripting: yes (ocamlfind found)";
595 pr2
"Support for external ocaml library in ocaml scripting: no";
596 pr2
"!!!!!!! WARNING !!!!!!! ocamlfind may be required at runtime";