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] [--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 /--no-opt/ and $opt = "";
45 /--opt/ and $opt = ".opt";
47 #tarzan by default (used by score file parsing and now also for sexp_ast_c.ml)
50 #if($ARGV[0] =~ "--prefix=(.*)") {
53 #if($ARGV[1] =~ "--without-python") {
57 my $src="$prefix/share/$project";
59 ######################################################################
61 ######################################################################
64 ######################################################################
66 ######################################################################
67 #BEGIN { die "need Perl 5 or greater" if $] < 5 ; }
70 sub pr2
{ print STDERR
"@_\n" }
75 while(<TMP
>) { push @list, "$_"; }
79 sub mapf
{ my ($f, $xs) = @_; [ map { &$f($_) } @
{$xs} ] }
80 sub plural
{ my ($e) = @_; if ($e > 1) { "s" } else { "" } }
82 sub check_config
{ my ($command, $expect, $msggood, $msgbad) = @_;
85 my $full = cat
($command);
86 my $res = join(" ", @
{$full});
88 if(notb
($res =~ $expect)) { $error++; pr2
"!!!! $msgbad !!!!"; }
93 ######################################################################
95 ######################################################################
96 pr2
"Checking your configuration.\n";
100 #---------------------------------------------------------------------
101 # Compilers and runtimes
102 #---------------------------------------------------------------------
105 check_config
("echo \"1;;\\n\" | ocaml |",
106 "Objective(.*) 3.\(09|1[0-9]\)",
107 "OCaml (the wonderful language) is present.",
108 "The program ocaml is missing or is not a good version. We need at least 3.09",
111 $noocamlscripting = check_config
("echo \"1;;\\n\" | ocaml |",
112 "Objective(.*) 3.1[1-9]",
113 "OCaml >= 3.11 is present. OCaml scripting activated.",
114 "OCaml scripting disabled. We need at least OCaml 3.11",
117 if ($opt eq ".opt") {
118 my $opt_check = `which ocamlc.opt 2> /dev/null`;
119 if($opt_check =~ "/ocamlc.opt\$") {
120 pr2
"ocamlc.opt is present.";
124 pr2
"ocamlc.opt not found";
127 my $opt_check = `which ocamlopt.opt 2> /dev/null`;
128 if($opt_check =~ "/ocamlopt.opt\$") {
129 pr2
"ocamlopt.opt is present.";
133 pr2
"ocamlopt.opt not found";
136 my $opt_check = `which ocamldep.opt 2> /dev/null`;
137 if($opt_check =~ "/ocamldep.opt\$") {
138 pr2
"ocamldep.opt is present.";
142 pr2
"ocamldep.opt not found";
145 my $opt_check = `which ocamllex.opt 2> /dev/null`;
146 if($opt_check =~ "/ocamllex.opt\$") {
147 pr2
"ocamllex.opt is present.";
151 pr2
"ocamllex.opt not found";
155 pr2
"At least one native OCaml tool have not been found.";
156 pr2
"Desactivation of all native OCaml tools for compilation.";
160 #we have cached the result of menhir in the tgz we build.
163 # check_config("menhir --version |",
164 # "menhir, version 20071212",
165 ## "menhir, version 2006.*",
166 # "Menhir (the parser generator) is present.",
167 # "The program menhir is missing or is not a good version.",
171 #---------------------------------------------------------------
173 #---------------------------------------------------------------
177 $error += check_config
(
178 "make -v 2>&1 |grep Make|",
179 "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
180 "make (gnu version) is present.",
181 "The program gnu make is missing or is not a good version.
186 #---------------------------------------------------------------------
187 # More developers tools
188 #---------------------------------------------------------------------
190 #---------------------------------------------------------------------
192 #---------------------------------------------------------------------
194 # pycaml. Binding between Python and OCaml
195 my $syspydir=`ocamlfind query pycaml 2> /dev/null | xargs echo -n`;
199 pr2
"'pycaml' library is present in $pydir";
201 pr2
"'pycaml' library is not present. A local copy will be used.";
204 # menhirLib. Runtime system for the parsers generated with menhir
205 my $sysmenhirdir=`ocamlfind query menhirLib 2> /dev/null | xargs echo -n`;
208 $menhirdir=$sysmenhirdir;
209 pr2
"'menhirLib' library is present in $menhirdir";
211 pr2
"'menhirLib' library is not present. A local copy will be used..";
214 # sexplib. Runtime system for the parsers generated with menhir
215 my $syssexpdir=`ocamlfind query sexplib 2> /dev/null | xargs echo -n`;
218 $sexpdir=$syssexpdir;
219 pr2
"'sexplib' library is present in $sexpdir";
221 pr2
"'sexplib' library is not present. A local copy will be used..";
224 ######################################################################
225 # Generate config files (platform/portability issues)
226 ######################################################################
229 ######################################################################
230 # Generate globals files (features issues)
231 ######################################################################
233 ######################################################################
235 ######################################################################
240 ----------------------------------------------------------------------
241 !!!! There seems to have problem, we have found $error missing package" .
243 " . (($error > 1) ?
"Some of those packages" : "This package") .
244 " may be installed by picking " . ($error > 1 ?
"them" : "it") .
245 " in $project-dependencies.tgz available
246 on the $project website. !!!!
247 ----------------------------------------------------------------------
252 "----------------------------------------------------------------------
254 All seems fine for $project.
256 To compile $project type:
260 Or alternatively, for the optimized version:
262 If you want both, you could use:
269 Then, to test $project simply type:
276 "To use the python SmPL feature you may have to set some environment variables.
277 However, they are automatically set by the front-end installed in $prefix/bin.
279 export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
280 export PYTHONPATH=\$PYTHONPATH:$src/python"
282 pr2
"----------------------------------------------------------------------";
285 ######################################################################
286 # Generating the configuration
287 ######################################################################
289 pr2
"$project target prefix: $prefix (you can use --prefix to override it)";
290 pr2
"Generating Makefile.config";
291 open(CONFIG
, ">Makefile.config");
292 print CONFIG
"# autogenerated by configure
295 INSTALL_PROGRAM?=install -c -m 755
296 INSTALL_LIB?= install -c -m 755
297 INSTALL_DATA?= install -c -m 644
299 # Where to install the binary
302 # Where to install the man pages
305 # Where to install the lib
308 # Where to install the configuration files
311 BASH_COMPLETION_DIR=/etc/bash_completion.d
314 FEATURE_PYTHON=$python
315 FEATURE_TARZAN=$tarzan
321 # The OPTBIN variable is here to allow to use ocamlc.opt instead of
322 # ocaml, when it is available, which speeds up compilation. So
323 # if you want the fast version of the ocaml chain tools, set this var
324 # or setenv it to \".opt\" in your startup script.
329 my $pythonprefix = $python ?
"yes" : "no";
330 pr2
"Support for python scripting : $pythonprefix";
331 `cd python; ln -sf ${pythonprefix}_pycocci.ml pycocci.ml; `;
332 `cd python; ln -sf ${pythonprefix}_pycocci_aux.ml pycocci_aux.ml;`;
333 `cd python; make depend`;
335 my $ocamlprefix = $noocamlscripting ?
"no" : "yes";
336 pr2
"Support for ocaml scripting : $ocamlprefix";
337 `cd ocaml; ln -sf ${ocamlprefix}_prepare_ocamlcocci.ml prepare_ocamlcocci.ml;`;
338 `cd ocaml; make depend`;
340 pr2
"Modifying globals/config.ml";
341 my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";