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) {
108 #if($ARGV[0] =~ "--prefix=(.*)") {
111 #if($ARGV[1] =~ "--without-python") {
115 my $src="$prefix/share/$project";
117 ######################################################################
119 ######################################################################
122 ######################################################################
124 ######################################################################
125 #BEGIN { die "need Perl 5 or greater" if $] < 5 ; }
128 sub pr2
{ print STDERR
"@_\n" }
133 while(<TMP
>) { push @list, "$_"; }
137 sub mapf
{ my ($f, $xs) = @_; [ map { &$f($_) } @
{$xs} ] }
138 sub plural
{ my ($e) = @_; if ($e > 1) { "s" } else { "" } }
140 sub check_config
{ my ($command, $expect, $msggood, $msgbad) = @_;
143 my $full = cat
($command);
144 my $res = join(" ", @
{$full});
146 if(notb
($res =~ $expect)) { $error++; pr2
"!!!! $msgbad !!!!"; }
147 else { pr2
$msggood }
151 ######################################################################
153 ######################################################################
154 pr2
"Checking your configuration.\n";
158 #---------------------------------------------------------------------
159 # Compilers and runtimes
160 #---------------------------------------------------------------------
163 check_config
("echo \"1;;\\n\" | ocaml |",
164 "Objective(.*) 3.\(09|1[0-9]\)",
165 "OCaml (the wonderful language) is present.",
166 "The program ocaml is missing or is not a good version. We need at least 3.09",
169 unless ($noocamlscripting) {
170 $noocamlscripting = check_config
("echo \"1;;\\n\" | ocaml |",
171 "Objective(.*) 3.1[1-9]",
172 "OCaml >= 3.11 is present. OCaml scripting activated.",
173 "OCaml scripting disabled. We need at least OCaml 3.11",
176 my $ocamlprefix = $noocamlscripting ?
"no" : "yes";
178 if ($opt eq ".opt") {
179 my $opt_check1 = `ocamlc.opt -version 2>/dev/null`;
180 if($opt_check1 =~ /[0-9\.]+/) {
181 pr2
"ocamlc.opt is present.";
185 pr2
"ocamlc.opt not found";
188 my $opt_check2 = `ocamlopt.opt -version 2>/dev/null`;
189 if($opt_check2 =~ /[0-9\.]+/) {
190 pr2
"ocamlopt.opt is present.";
194 pr2
"ocamlopt.opt not found";
197 my $opt_check3 = `ocamldep.opt -version 2>/dev/null`;
198 if($opt_check3 =~ /[0-9\.]+/) {
199 pr2
"ocamldep.opt is present.";
203 pr2
"ocamldep.opt not found";
206 my $opt_check4 = `ocamllex.opt -version 2>/dev/null`;
207 if($opt_check4 =~ /[0-9\.]+/) {
208 pr2
"ocamllex.opt is present.";
212 pr2
"ocamllex.opt not found";
216 pr2
"At least one native OCaml tool have not been found.";
217 pr2
"Desactivation of all native OCaml tools for compilation.";
221 #we have cached the result of menhir in the tgz we build.
224 # check_config("menhir --version |",
225 # "menhir, version 20071212",
226 ## "menhir, version 2006.*",
227 # "Menhir (the parser generator) is present.",
228 # "The program menhir is missing or is not a good version.",
232 #---------------------------------------------------------------
234 #---------------------------------------------------------------
238 $error += check_config
(
239 "make -v 2>&1 |grep Make|",
240 "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
241 "make (gnu version) is present.",
242 "The program gnu make is missing or is not a good version.
246 #---------------------------------------------------------------------
247 # More developers tools
248 #---------------------------------------------------------------------
250 #---------------------------------------------------------------------
252 #---------------------------------------------------------------------
258 "$python_cmd --version 2>&1 |",
260 "$python_cmd is present",
261 "$python_cmd is missing or is not a good version."
267 my $PY_PREFIX = `$python_cmd pycaml/getprefix.py | tr -d '\n'`;
268 $PY_VERSION = `$python_cmd pycaml/getversion.py | tr -d '\n'`;
269 my $python_hdr = "$PY_PREFIX/include/python$PY_VERSION/Python.h";
271 "ls $python_hdr 2> /dev/null | ",
274 "Python.h missing - You need to install python-dev"
282 my $ocamlfind=!check_config
(
283 "ocamlfind ocamlc -version 2> /dev/null | ",
285 "ocamlfind is present",
286 "ocamlfind is missing -- Switch to local library copies."
289 # pycaml. Binding between Python and OCaml
290 my $syspydir=`ocamlfind query pycaml 2> /dev/null | xargs echo -n`;
293 pr2
"'pycaml' library is present in $syspydir";
294 if ($libs{'pycaml'} > 1) {
295 pr2
"... but a local copy of 'pycaml' will be used.";
301 pr2
"'pycaml' library is not present. A local copy will be used.";
304 # menhirLib. Runtime system for the parsers generated with menhir
305 my $sysmenhirdir=`ocamlfind query menhirLib 2> /dev/null | xargs echo -n`;
308 $menhirdir=$sysmenhirdir;
309 pr2
"'menhirLib' library is present in $menhirdir";
311 pr2
"'menhirLib' library is not present. A local copy will be used.";
315 my $syssexpdir=`ocamlfind query sexplib 2> /dev/null | xargs echo -n`;
318 $sexpdir=$syssexpdir;
319 pr2
"'sexplib' library is present in $sexpdir";
321 pr2
"'sexplib' library is not present. A local copy will be used.";
324 # Check if libpcre-ocaml is available
325 # when pcre feature is enabled.
328 $pcredir=`ocamlfind query pcre 2> /dev/null | xargs echo -n `;
330 "echo -n $pcredir | ",
332 "'pcre-ocaml' library is present in $pcredir",
333 "'pcre-ocaml' library is not present - You need to install libpcre-ocaml-dev"
340 ######################################################################
341 # Printing of library selection
342 ######################################################################
345 pr2
"----------------------------------------------------------------------";
346 pr2
"Library configuration:";
349 foreach my $lib (keys %libs) {
350 my $isSelected = $libs{$lib};
352 my $libdir = `ocamlfind query $lib 2> /dev/null | xargs echo -n`;
353 if ($libdir && $libs{$lib} <= 1) {
355 $libPaths{$lib} = $libdir;
358 if (-d
$lib) { # test if local directory exists
359 $libs{$lib} = 2; # use local version
360 $libPaths{$lib} = $lib;
362 $libs{$lib} = 0; # disable the feature
363 $libPaths{$lib} = "";
368 my $choice = $libs{$lib};
370 pr2
"$lib: disabled";
371 } elsif ($choice == 1) {
372 pr2
"$lib: global version in $libPaths{$lib}";
374 pr2
"$lib: local version selected";
378 ######################################################################
379 # Generate config files (platform/portability issues)
380 ######################################################################
383 ######################################################################
384 # Generate globals files (features issues)
385 ######################################################################
387 ######################################################################
389 ######################################################################
393 ----------------------------------------------------------------------
394 !!!! There seems to have problem, we have found $error missing package" .
396 " . (($error > 1) ?
"Some of those packages" : "This package") .
397 " may be installed by picking " . ($error > 1 ?
"them" : "it") .
398 " in $project-dependencies.tgz available
399 on the $project website. !!!!
400 ----------------------------------------------------------------------
405 "----------------------------------------------------------------------
407 All seems fine for $project.
409 To compile $project type:
413 Or alternatively, for the optimized version:
415 If you want both, you could use:
422 Then, to test $project simply type:
429 "To use the python SmPL feature you may have to set some environment variables.
430 However, they are automatically set by the front-end installed in $prefix/bin.
432 export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
433 export PYTHONPATH=\$PYTHONPATH:$src/python"
436 pr2
"----------------------------------------------------------------------";
439 ######################################################################
440 # Generating the configuration
441 ######################################################################
443 pr2
" Compilation configuration\n";
445 pr2
"$project target prefix: $prefix (you can use --prefix to override it)";
446 pr2
"Generating Makefile.config";
447 open(CONFIG
, ">Makefile.config");
448 print CONFIG
"# autogenerated by configure
451 INSTALL_PROGRAM?=install -c -m 755
452 INSTALL_LIB?= install -c -m 755
453 INSTALL_DATA?= install -c -m 644
455 # Where to install the binary
458 # Where to install the man pages
461 # Where to install the lib
464 # Where to install the configuration files
467 BASH_COMPLETION_DIR=/etc/bash_completion.d
470 FEATURE_PYTHON=$python
471 FEATURE_TARZAN=$tarzan
475 print CONFIG
"PYVER=$PY_VERSION\n";
476 print CONFIG
"PYCMD=$python_cmd\n";
490 # The OPTBIN variable is here to allow to use ocamlc.opt instead of
491 # ocaml, when it is available, which speeds up compilation. So
492 # if you want the fast version of the ocaml chain tools, set this var
493 # or setenv it to \".opt\" in your startup script.
498 # Generate variables for handling the ocaml libraries
509 my @featurelibs = ();
513 return "\$(" . $_[0] . "_" . $_[1] . ")";
516 foreach $lib (keys %libs) {
517 my $sel = $libs{$lib};
518 my $path = $libPaths{$lib};
519 my $pathvar = strVar
("PATH", $lib);
521 if ($sel == 1) { # global version
522 push(@lnklibs, strVar
("GLOBAL", $lib));
523 push(@optlnklibs, strVar
("GLOBALOPT", $lib));
524 } elsif ($sel > 1) { # local version
525 push(@lnklibs, strVar
("LOCAL", $lib));
526 push(@optlnklibs, strVar
("LOCALOPT", $lib));
527 if (-e
"$path/Makefile") { # does it have a Makefile?
528 push(@makelibs, $pathvar);
529 push(@cleanlibs, $pathvar);
530 push(@deplibs, $pathvar);
534 if ($sel >= 1) { # indifferent of global/local
535 push(@sellibs, $lib);
536 push(@inclibs, $pathvar);
537 push(@flagslibs, strVar
("FLAGS", $lib));
539 push(@featurelibs, "FEATURE_$lib=1");
540 push(@pathlibs, "PATH_$lib=$path");
544 my $strSellibs = join(" ", @sellibs);
545 my $strMakelibs = join(" ", @makelibs);
546 my $strCleanlibs = join(" ", @cleanlibs);
547 my $strDeplibs = join(" ", @deplibs);
548 my $strLnklibs = join(" ", @lnklibs);
549 my $strOptlnklibs = join(" ", @optlnklibs);
550 my $strInclibs = join(" ", @inclibs);
551 my $strFlagslibs = join(" ", @flagslibs);
552 my $strFeatures = join("\n", @featurelibs);
553 my $strPaths = join("\n", @pathlibs);
562 # collected config vars
564 MAKELIBS=$strMakelibs
565 CLEANLIBS=$strCleanlibs
568 OPTLNKLIBS=$strOptlnklibs
570 FLAGSLIBS=$strFlagslibs
572 # selected ocaml modules
579 my $val = ucfirst($_[3]);
580 my $cmd = "sed -e 's|${key}|${val}|g' ${src} > ${dest}";
587 my $pythonprefix = $python ?
"yes" : "no";
588 pr2
"Support for python scripting: $pythonprefix";
589 repl
('python/pycocci.ml.in', 'python/pycocci.ml', '@PYCOCCI_FILE@', "${pythonprefix}_pycocci");
590 print CONFIG
"PYCOCCI_FILE=${pythonprefix}_pycocci.ml\n";
591 # `cd python; ln -sf ${pythonprefix}_pycocci.ml pycocci.ml; `;
592 `cd python; make depend`;
594 pr2
"Support for ocaml scripting: $ocamlprefix";
595 repl
('ocaml/prepare_ocamlcocci.ml.in', 'ocaml/prepare_ocamlcocci.ml', '@OCAMLCOCCI_FILE@', "${ocamlprefix}_prepare_ocamlcocci");
596 print CONFIG
"OCAMLCOCCI_FILE=${ocamlprefix}_prepare_ocamlcocci.ml\n";
597 # `cd ocaml; ln -sf ${ocamlprefix}_prepare_ocamlcocci.ml prepare_ocamlcocci.ml;`;
598 `cd ocaml; make depend`;
600 my $pcresuffix = $pcre ?
"pcre" : "str";
601 pr2
"Support for regexp: $pcresuffix";
602 repl
('globals/regexp.ml.in', 'globals/regexp.ml', '@REGEXP_FILE@', "Regexp_${pcresuffix}");
603 print CONFIG
"REGEXP_FILE=regexp_${pcresuffix}.ml";
604 # `cd globals; ln -sf regexp_${pcresuffix}.ml regexp.ml; touch regexp.ml;`;
605 `cd globals; make depend`;
607 pr2
"Modifying globals/config.ml";
608 my $version = `cat ./version | tr -d '\n'`;
609 `echo -n "$version" > ./version`; # make sure that there are no newlines after version
610 my $command1 = "sed -i -e 's|^let version = \".*\"\$|let version = \"$version\"|g' globals/config.ml.in"; # substitute version
611 my $command2 = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";
615 pr2
"----------------------------------------------------------------------";
616 pr2
" Runtime dependency\n";
619 pr2
"Support for external ocaml library in ocaml scripting: yes (ocamlfind found)";
622 pr2
"Support for external ocaml library in ocaml scripting: no";
623 pr2
"!!!!!!! WARNING !!!!!!! ocamlfind may be required at runtime";