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";
31 my $noocamlscripting=0;
35 my $menhirdir="menhirlib";
36 my $sexpdir="ocamlsexp";
38 local $_ = join ' ', @ARGV;
41 /-h/ || /--help/ and die "usage: $0 [--prefix=path] [--without-python] [--without-ocaml] [--no-opt]\n\n\t--no-opt\tDo not use the optimimized version of OCaml\n\t--opt\tUse the optimimized version of OCaml\n\n";
42 /--prefix=([^ ]*)/ and $prefix = $1;
43 /--without-python/ and $python = 0;
44 /--without-ocaml/ and $noocamlscripting = 1;
45 /--no-opt/ and $opt = "";
46 /--opt/ and $opt = ".opt";
48 #tarzan by default (used by score file parsing and now also for sexp_ast_c.ml)
51 #if($ARGV[0] =~ "--prefix=(.*)") {
54 #if($ARGV[1] =~ "--without-python") {
58 my $src="$prefix/share/$project";
60 ######################################################################
62 ######################################################################
65 ######################################################################
67 ######################################################################
68 #BEGIN { die "need Perl 5 or greater" if $] < 5 ; }
71 sub pr2
{ print STDERR
"@_\n" }
76 while(<TMP
>) { push @list, "$_"; }
80 sub mapf
{ my ($f, $xs) = @_; [ map { &$f($_) } @
{$xs} ] }
81 sub plural
{ my ($e) = @_; if ($e > 1) { "s" } else { "" } }
83 sub check_config
{ my ($command, $expect, $msggood, $msgbad) = @_;
86 my $full = cat
($command);
87 my $res = join(" ", @
{$full});
89 if(notb
($res =~ $expect)) { $error++; pr2
"!!!! $msgbad !!!!"; }
94 ######################################################################
96 ######################################################################
97 pr2
"Checking your configuration.\n";
101 #---------------------------------------------------------------------
102 # Compilers and runtimes
103 #---------------------------------------------------------------------
106 check_config
("echo \"1;;\\n\" | ocaml |",
107 "Objective(.*) 3.\(09|1[0-9]\)",
108 "OCaml (the wonderful language) is present.",
109 "The program ocaml is missing or is not a good version. We need at least 3.09",
112 unless ($noocamlscripting) {
113 $noocamlscripting = check_config
("echo \"1;;\\n\" | ocaml |",
114 "Objective(.*) 3.1[1-9]",
115 "OCaml >= 3.11 is present. OCaml scripting activated.",
116 "OCaml scripting disabled. We need at least OCaml 3.11",
119 my $ocamlprefix = $noocamlscripting ?
"no" : "yes";
121 if ($opt eq ".opt") {
122 my $opt_check = `which ocamlc.opt 2> /dev/null`;
123 if($opt_check =~ "/ocamlc.opt\$") {
124 pr2
"ocamlc.opt is present.";
128 pr2
"ocamlc.opt not found";
131 my $opt_check = `which ocamlopt.opt 2> /dev/null`;
132 if($opt_check =~ "/ocamlopt.opt\$") {
133 pr2
"ocamlopt.opt is present.";
137 pr2
"ocamlopt.opt not found";
140 my $opt_check = `which ocamldep.opt 2> /dev/null`;
141 if($opt_check =~ "/ocamldep.opt\$") {
142 pr2
"ocamldep.opt is present.";
146 pr2
"ocamldep.opt not found";
149 my $opt_check = `which ocamllex.opt 2> /dev/null`;
150 if($opt_check =~ "/ocamllex.opt\$") {
151 pr2
"ocamllex.opt is present.";
155 pr2
"ocamllex.opt not found";
159 pr2
"At least one native OCaml tool have not been found.";
160 pr2
"Desactivation of all native OCaml tools for compilation.";
164 #we have cached the result of menhir in the tgz we build.
167 # check_config("menhir --version |",
168 # "menhir, version 20071212",
169 ## "menhir, version 2006.*",
170 # "Menhir (the parser generator) is present.",
171 # "The program menhir is missing or is not a good version.",
175 #---------------------------------------------------------------
177 #---------------------------------------------------------------
181 $error += check_config
(
182 "make -v 2>&1 |grep Make|",
183 "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
184 "make (gnu version) is present.",
185 "The program gnu make is missing or is not a good version.
189 #---------------------------------------------------------------------
190 # More developers tools
191 #---------------------------------------------------------------------
193 #---------------------------------------------------------------------
195 #---------------------------------------------------------------------
200 "python --version 2>&1 |",
201 '^Python 2\.([567]|[567]\.\S*)$',
203 "python is missing or is not a good version."
209 my $PY_PREFIX = `python pycaml/getprefix.py | tr -d '\n'`;
210 my $PY_VERSION = `python pycaml/getversion.py | tr -d '\n'`;
211 my $python_hdr = "$PY_PREFIX/include/python$PY_VERSION/Python.h";
213 "ls $python_hdr 2> /dev/null | ",
216 "Python.h missing - You need to install python-dev"
224 my $ocamlfind=!check_config
(
225 "which ocamlfind 2> /dev/null |",
227 "ocamlfind is present",
228 "ocamlfind is missing -- Switch to local library copies."
231 # pycaml. Binding between Python and OCaml
232 my $syspydir=`ocamlfind query pycaml 2> /dev/null | xargs echo -n`;
236 pr2
"'pycaml' library is present in $pydir";
238 pr2
"'pycaml' library is not present. A local copy will be used.";
241 # menhirLib. Runtime system for the parsers generated with menhir
242 my $sysmenhirdir=`ocamlfind query menhirLib 2> /dev/null | xargs echo -n`;
245 $menhirdir=$sysmenhirdir;
246 pr2
"'menhirLib' library is present in $menhirdir";
248 pr2
"'menhirLib' library is not present. A local copy will be used..";
251 # sexplib. Runtime system for the parsers generated with menhir
252 my $syssexpdir=`ocamlfind query sexplib 2> /dev/null | xargs echo -n`;
255 $sexpdir=$syssexpdir;
256 pr2
"'sexplib' library is present in $sexpdir";
258 pr2
"'sexplib' library is not present. A local copy will be used..";
261 ######################################################################
262 # Generate config files (platform/portability issues)
263 ######################################################################
266 ######################################################################
267 # Generate globals files (features issues)
268 ######################################################################
270 ######################################################################
272 ######################################################################
277 ----------------------------------------------------------------------
278 !!!! There seems to have problem, we have found $error missing package" .
280 " . (($error > 1) ?
"Some of those packages" : "This package") .
281 " may be installed by picking " . ($error > 1 ?
"them" : "it") .
282 " in $project-dependencies.tgz available
283 on the $project website. !!!!
284 ----------------------------------------------------------------------
289 "----------------------------------------------------------------------
291 All seems fine for $project.
293 To compile $project type:
297 Or alternatively, for the optimized version:
299 If you want both, you could use:
306 Then, to test $project simply type:
313 "To use the python SmPL feature you may have to set some environment variables.
314 However, they are automatically set by the front-end installed in $prefix/bin.
316 export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
317 export PYTHONPATH=\$PYTHONPATH:$src/python"
320 pr2
"----------------------------------------------------------------------";
323 ######################################################################
324 # Generating the configuration
325 ######################################################################
327 pr2
" Compilation configuration\n";
329 pr2
"$project target prefix: $prefix (you can use --prefix to override it)";
330 pr2
"Generating Makefile.config";
331 open(CONFIG
, ">Makefile.config");
332 print CONFIG
"# autogenerated by configure
335 INSTALL_PROGRAM?=install -c -m 755
336 INSTALL_LIB?= install -c -m 755
337 INSTALL_DATA?= install -c -m 644
339 # Where to install the binary
342 # Where to install the man pages
345 # Where to install the lib
348 # Where to install the configuration files
351 BASH_COMPLETION_DIR=/etc/bash_completion.d
354 FEATURE_PYTHON=$python
355 FEATURE_TARZAN=$tarzan
362 # The OPTBIN variable is here to allow to use ocamlc.opt instead of
363 # ocaml, when it is available, which speeds up compilation. So
364 # if you want the fast version of the ocaml chain tools, set this var
365 # or setenv it to \".opt\" in your startup script.
370 my $pythonprefix = $python ?
"yes" : "no";
371 pr2
"Support for python scripting: $pythonprefix";
372 `cd python; ln -sf ${pythonprefix}_pycocci.ml pycocci.ml; `;
373 `cd python; make depend`;
375 pr2
"Support for ocaml scripting: $ocamlprefix";
376 `cd ocaml; ln -sf ${ocamlprefix}_prepare_ocamlcocci.ml prepare_ocamlcocci.ml;`;
377 `cd ocaml; make depend`;
379 pr2
"Modifying globals/config.ml";
380 my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";
383 pr2
"----------------------------------------------------------------------";
384 pr2
" Runtime dependency\n";
387 pr2
"Support for external ocaml library in ocaml scripting: yes (ocamlfind found)";
390 pr2
"Support for external ocaml library in ocaml scripting: no (ocamlfind may be required at runtime)";