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";
39 local $_ = join ' ', @ARGV;
42 /-h/ || /--help/ and die "usage: $0 [--prefix=path] [--without-FEATURE] [--no-opt]\n
43 \t--without-python\tDisable scripting in Python
44 \t--without-ocaml\t\tDisable scripting in Ocaml
45 \t--without-pcre\t\tDisable regexp with PCRE
46 \t--no-opt\t\tDo not use the optimimized version of OCaml
47 \t--opt\t\t\tUse the optimimized version of OCaml\n\n";
48 /--prefix=([^ ]*)/ and $prefix = $1;
49 /--without-pcre/ and $pcre = 0;
50 /--without-python/ and $python = 0;
51 /--without-ocaml/ and $noocamlscripting = 1;
52 /--no-opt/ and $opt = "";
53 /--opt/ and $opt = ".opt";
55 #tarzan by default (used by score file parsing and now also for sexp_ast_c.ml)
58 #if($ARGV[0] =~ "--prefix=(.*)") {
61 #if($ARGV[1] =~ "--without-python") {
65 my $src="$prefix/share/$project";
67 ######################################################################
69 ######################################################################
72 ######################################################################
74 ######################################################################
75 #BEGIN { die "need Perl 5 or greater" if $] < 5 ; }
78 sub pr2
{ print STDERR
"@_\n" }
83 while(<TMP
>) { push @list, "$_"; }
87 sub mapf
{ my ($f, $xs) = @_; [ map { &$f($_) } @
{$xs} ] }
88 sub plural
{ my ($e) = @_; if ($e > 1) { "s" } else { "" } }
90 sub check_config
{ my ($command, $expect, $msggood, $msgbad) = @_;
93 my $full = cat
($command);
94 my $res = join(" ", @
{$full});
96 if(notb
($res =~ $expect)) { $error++; pr2
"!!!! $msgbad !!!!"; }
101 ######################################################################
103 ######################################################################
104 pr2
"Checking your configuration.\n";
108 #---------------------------------------------------------------------
109 # Compilers and runtimes
110 #---------------------------------------------------------------------
113 check_config
("echo \"1;;\\n\" | ocaml |",
114 "Objective(.*) 3.\(09|1[0-9]\)",
115 "OCaml (the wonderful language) is present.",
116 "The program ocaml is missing or is not a good version. We need at least 3.09",
119 unless ($noocamlscripting) {
120 $noocamlscripting = check_config
("echo \"1;;\\n\" | ocaml |",
121 "Objective(.*) 3.1[1-9]",
122 "OCaml >= 3.11 is present. OCaml scripting activated.",
123 "OCaml scripting disabled. We need at least OCaml 3.11",
126 my $ocamlprefix = $noocamlscripting ?
"no" : "yes";
128 if ($opt eq ".opt") {
129 my $opt_check = `which ocamlc.opt 2> /dev/null`;
130 if($opt_check =~ "/ocamlc.opt\$") {
131 pr2
"ocamlc.opt is present.";
135 pr2
"ocamlc.opt not found";
138 my $opt_check = `which ocamlopt.opt 2> /dev/null`;
139 if($opt_check =~ "/ocamlopt.opt\$") {
140 pr2
"ocamlopt.opt is present.";
144 pr2
"ocamlopt.opt not found";
147 my $opt_check = `which ocamldep.opt 2> /dev/null`;
148 if($opt_check =~ "/ocamldep.opt\$") {
149 pr2
"ocamldep.opt is present.";
153 pr2
"ocamldep.opt not found";
156 my $opt_check = `which ocamllex.opt 2> /dev/null`;
157 if($opt_check =~ "/ocamllex.opt\$") {
158 pr2
"ocamllex.opt is present.";
162 pr2
"ocamllex.opt not found";
166 pr2
"At least one native OCaml tool have not been found.";
167 pr2
"Desactivation of all native OCaml tools for compilation.";
171 #we have cached the result of menhir in the tgz we build.
174 # check_config("menhir --version |",
175 # "menhir, version 20071212",
176 ## "menhir, version 2006.*",
177 # "Menhir (the parser generator) is present.",
178 # "The program menhir is missing or is not a good version.",
182 #---------------------------------------------------------------
184 #---------------------------------------------------------------
188 $error += check_config
(
189 "make -v 2>&1 |grep Make|",
190 "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
191 "make (gnu version) is present.",
192 "The program gnu make is missing or is not a good version.
196 #---------------------------------------------------------------------
197 # More developers tools
198 #---------------------------------------------------------------------
200 #---------------------------------------------------------------------
202 #---------------------------------------------------------------------
208 "python --version 2>&1 |",
209 '^Python 2\.([4567]|[4567]\.\S*)$',
211 "python is missing or is not a good version."
217 my $PY_PREFIX = `python pycaml/getprefix.py | tr -d '\n'`;
218 $PY_VERSION = `python pycaml/getversion.py | tr -d '\n'`;
219 my $python_hdr = "$PY_PREFIX/include/python$PY_VERSION/Python.h";
221 "ls $python_hdr 2> /dev/null | ",
224 "Python.h missing - You need to install python-dev"
232 my $ocamlfind=!check_config
(
233 "which ocamlfind 2> /dev/null |",
235 "ocamlfind is present",
236 "ocamlfind is missing -- Switch to local library copies."
239 # pycaml. Binding between Python and OCaml
240 my $syspydir=`ocamlfind query pycaml 2> /dev/null | xargs echo -n`;
244 pr2
"'pycaml' library is present in $pydir";
246 pr2
"'pycaml' library is not present. A local copy will be used.";
249 # menhirLib. Runtime system for the parsers generated with menhir
250 my $sysmenhirdir=`ocamlfind query menhirLib 2> /dev/null | xargs echo -n`;
253 $menhirdir=$sysmenhirdir;
254 pr2
"'menhirLib' library is present in $menhirdir";
256 pr2
"'menhirLib' library is not present. A local copy will be used.";
259 # sexplib. Runtime system for the parsers generated with menhir
260 my $syssexpdir=`ocamlfind query sexplib 2> /dev/null | xargs echo -n`;
263 $sexpdir=$syssexpdir;
264 pr2
"'sexplib' library is present in $sexpdir";
266 pr2
"'sexplib' library is not present. A local copy will be used.";
269 # Check if libpcre-ocaml is available
270 # when pcre feature is enabled.
273 $pcredir=`ocamlfind query pcre 2> /dev/null | xargs echo -n `;
275 "echo -n $pcredir | ",
277 "'pcre-ocaml' library is present in $pcredir",
278 "'pcre-ocaml' library is not present - You need to install libpcre-ocaml-dev"
285 ######################################################################
286 # Generate config files (platform/portability issues)
287 ######################################################################
290 ######################################################################
291 # Generate globals files (features issues)
292 ######################################################################
294 ######################################################################
296 ######################################################################
301 ----------------------------------------------------------------------
302 !!!! There seems to have problem, we have found $error missing package" .
304 " . (($error > 1) ?
"Some of those packages" : "This package") .
305 " may be installed by picking " . ($error > 1 ?
"them" : "it") .
306 " in $project-dependencies.tgz available
307 on the $project website. !!!!
308 ----------------------------------------------------------------------
313 "----------------------------------------------------------------------
315 All seems fine for $project.
317 To compile $project type:
321 Or alternatively, for the optimized version:
323 If you want both, you could use:
330 Then, to test $project simply type:
337 "To use the python SmPL feature you may have to set some environment variables.
338 However, they are automatically set by the front-end installed in $prefix/bin.
340 export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
341 export PYTHONPATH=\$PYTHONPATH:$src/python"
344 pr2
"----------------------------------------------------------------------";
347 ######################################################################
348 # Generating the configuration
349 ######################################################################
351 pr2
" Compilation configuration\n";
353 pr2
"$project target prefix: $prefix (you can use --prefix to override it)";
354 pr2
"Generating Makefile.config";
355 open(CONFIG
, ">Makefile.config");
356 print CONFIG
"# autogenerated by configure
359 INSTALL_PROGRAM?=install -c -m 755
360 INSTALL_LIB?= install -c -m 755
361 INSTALL_DATA?= install -c -m 644
363 # Where to install the binary
366 # Where to install the man pages
369 # Where to install the lib
372 # Where to install the configuration files
375 BASH_COMPLETION_DIR=/etc/bash_completion.d
378 FEATURE_PYTHON=$python
379 FEATURE_TARZAN=$tarzan
383 print CONFIG
"PYVER=$PY_VERSION";
397 # The OPTBIN variable is here to allow to use ocamlc.opt instead of
398 # ocaml, when it is available, which speeds up compilation. So
399 # if you want the fast version of the ocaml chain tools, set this var
400 # or setenv it to \".opt\" in your startup script.
405 my $pythonprefix = $python ?
"yes" : "no";
406 pr2
"Support for python scripting: $pythonprefix";
407 `cd python; ln -sf ${pythonprefix}_pycocci.ml pycocci.ml; `;
408 `cd python; make depend`;
410 pr2
"Support for ocaml scripting: $ocamlprefix";
411 `cd ocaml; ln -sf ${ocamlprefix}_prepare_ocamlcocci.ml prepare_ocamlcocci.ml;`;
412 `cd ocaml; make depend`;
414 my $pcresuffix = $pcre ?
"pcre" : "str";
415 pr2
"Support for regexp: $pcresuffix";
416 `cd globals; ln -sf regexp_${pcresuffix}.ml regexp.ml; touch regexp.ml;`;
417 `cd globals; make depend`;
419 pr2
"Modifying globals/config.ml";
420 my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";
423 pr2
"----------------------------------------------------------------------";
424 pr2
" Runtime dependency\n";
427 pr2
"Support for external ocaml library in ocaml scripting: yes (ocamlfind found)";
430 pr2
"Support for external ocaml library in ocaml scripting: no";
431 pr2
"!!!!!!! WARNING !!!!!!! ocamlfind may be required at runtime";