Release coccinelle-0.2.3rc4
[bpt/coccinelle.git] / configure
CommitLineData
34e49164 1#!/usr/bin/perl
708f4980 2
fc1ad971 3# Author: Yoann Padioleau
708f4980 4
34e49164
C
5######################################################################
6# Prelude
7######################################################################
8
9# Yes I know about autoconf ... and autoconf sux.
10
11# assume standard: diff
12# assume standard: perl
13
708f4980 14#TODO check python 2.5 ?
34e49164 15
978fd7e5
C
16# need latex and hevea if want to compile the documentation
17
34e49164
C
18#old: --with-menhir=/path/to/menhirLib or `ocamlfind query menhirLib`
19
0708f913 20my $project =
34e49164 21 "coccinelle";
0708f913 22my $projectcmdline =
978fd7e5 23 "spatch -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c";
34e49164 24
34e49164
C
25######################################################################
26# Options
27######################################################################
28
29my $prefix="/usr/local";
30my $python=1;
174d1640 31my $noocamlscripting=0;
0708f913 32my $opt=".opt";
978fd7e5 33my $tarzan=1;
90aeb998
C
34my $pydir="pycaml";
35my $menhirdir="menhirlib";
36my $sexpdir="ocamlsexp";
34e49164
C
37
38local $_ = join ' ', @ARGV;
39
40# Parse options
ae4735db 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";
34e49164
C
42/--prefix=([^ ]*)/ and $prefix = $1;
43/--without-python/ and $python = 0;
0708f913 44/--no-opt/ and $opt = "";
8ba84ae2 45/--opt/ and $opt = ".opt";
34e49164 46
978fd7e5
C
47#tarzan by default (used by score file parsing and now also for sexp_ast_c.ml)
48
49
34e49164
C
50#if($ARGV[0] =~ "--prefix=(.*)") {
51# $prefix = $1;
52#}
53#if($ARGV[1] =~ "--without-python") {
54# $python = 0;
55#}
56
57my $src="$prefix/share/$project";
58
59######################################################################
60# Side effects
61######################################################################
62
63
64######################################################################
65# Helpers
66######################################################################
67#BEGIN { die "need Perl 5 or greater" if $] < 5 ; }
68
69#use Common;
70sub pr2 { print STDERR "@_\n" }
0708f913 71sub cat {
34e49164
C
72 my ($what) = @_;
73 my @list;
74 open(TMP, $what);
75 while(<TMP>) { push @list, "$_"; }
76 \@list;
77}
78sub notb { !$_[0] }
79sub mapf { my ($f, $xs) = @_; [ map { &$f($_) } @{$xs} ] }
80sub plural { my ($e) = @_; if ($e > 1) { "s" } else { "" } }
81
82sub check_config { my ($command, $expect, $msggood, $msgbad) = @_;
83 my $error = 0;
0708f913 84
34e49164
C
85 my $full = cat($command);
86 my $res = join(" ", @{$full});
87# pr2 $res;
88 if(notb($res =~ $expect)) { $error++; pr2 "!!!! $msgbad !!!!"; }
89 else { pr2 $msggood }
90 return $error;
91}
92
93######################################################################
94# Let's go
95######################################################################
96pr2 "Checking your configuration.\n";
97
98my $error = 0;
99
34e49164
C
100#---------------------------------------------------------------------
101# Compilers and runtimes
102#---------------------------------------------------------------------
174d1640 103
0708f913 104$error +=
34e49164 105 check_config("echo \"1;;\\n\" | ocaml |",
174d1640 106 "Objective(.*) 3.\(09|1[0-9]\)",
34e49164
C
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",
109 );
110
174d1640
C
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",
115 );
116
0708f913 117if ($opt eq ".opt") {
8ba84ae2
C
118 my $opt_check = `which ocamlc.opt 2> /dev/null`;
119 if($opt_check =~ "/ocamlc.opt\$") {
120 pr2 "ocamlc.opt is present.";
121 }
122 else {
123 $opt="";
124 pr2 "ocamlc.opt not found";
125 }
126
127 my $opt_check = `which ocamlopt.opt 2> /dev/null`;
128 if($opt_check =~ "/ocamlopt.opt\$") {
129 pr2 "ocamlopt.opt is present.";
130 }
131 else {
132 $opt="";
133 pr2 "ocamlopt.opt not found";
134 }
135
136 my $opt_check = `which ocamldep.opt 2> /dev/null`;
137 if($opt_check =~ "/ocamldep.opt\$") {
138 pr2 "ocamldep.opt is present.";
139 }
140 else {
0708f913 141 $opt="";
8ba84ae2
C
142 pr2 "ocamldep.opt not found";
143 }
144
145 my $opt_check = `which ocamllex.opt 2> /dev/null`;
146 if($opt_check =~ "/ocamllex.opt\$") {
147 pr2 "ocamllex.opt is present.";
0708f913
C
148 }
149 else {
8ba84ae2
C
150 $opt="";
151 pr2 "ocamllex.opt not found";
152 }
153
154 if($opt eq "") {
155 pr2 "At least one native OCaml tool have not been found.";
156 pr2 "Desactivation of all native OCaml tools for compilation.";
0708f913
C
157 }
158}
159
34e49164
C
160#we have cached the result of menhir in the tgz we build.
161
0708f913 162#$error +=
34e49164
C
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.",
168# );
169
170
171#---------------------------------------------------------------
172# Developers tools
173#---------------------------------------------------------------
174
175pr2 "";
176
177$error += check_config(
178 "make -v 2>&1 |grep Make|",
708f4980 179 "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
34e49164
C
180 "make (gnu version) is present.",
181 "The program gnu make is missing or is not a good version.
182We need 3.XX",
183);
184
185
186#---------------------------------------------------------------------
187# More developers tools
188#---------------------------------------------------------------------
189
190#---------------------------------------------------------------------
191# Librairies
192#---------------------------------------------------------------------
193
90aeb998
C
194# pycaml. Binding between Python and OCaml
195my $syspydir=`ocamlfind query pycaml 2> /dev/null | xargs echo -n`;
196
197if($syspydir) {
198 $pydir=$syspydir;
174d1640
C
199 pr2 "'pycaml' library is present in $pydir";
200} else {
201 pr2 "'pycaml' library is not present. A local copy will be used.";
90aeb998
C
202}
203
204# menhirLib. Runtime system for the parsers generated with menhir
205my $sysmenhirdir=`ocamlfind query menhirLib 2> /dev/null | xargs echo -n`;
206
207if($sysmenhirdir) {
208 $menhirdir=$sysmenhirdir;
174d1640
C
209 pr2 "'menhirLib' library is present in $menhirdir";
210} else {
211 pr2 "'menhirLib' library is not present. A local copy will be used..";
90aeb998
C
212}
213
214# sexplib. Runtime system for the parsers generated with menhir
215my $syssexpdir=`ocamlfind query sexplib 2> /dev/null | xargs echo -n`;
216
217if($syssexpdir) {
218 $sexpdir=$syssexpdir;
174d1640
C
219 pr2 "'sexplib' library is present in $sexpdir";
220} else {
221 pr2 "'sexplib' library is not present. A local copy will be used..";
90aeb998
C
222}
223
34e49164
C
224######################################################################
225# Generate config files (platform/portability issues)
226######################################################################
227
228
229######################################################################
230# Generate globals files (features issues)
231######################################################################
232
233######################################################################
0708f913 234# Diagnostic
34e49164
C
235######################################################################
236
237
0708f913 238if($error) {
34e49164
C
239 pr2 "
240----------------------------------------------------------------------
0708f913 241!!!! There seems to have problem, we have found $error missing package" .
34e49164 242plural($error) . ".
0708f913
C
243" . (($error > 1) ? "Some of those packages" : "This package") .
244 " may be installed by picking " . ($error > 1 ? "them" : "it") .
34e49164
C
245 " in $project-dependencies.tgz available
246on the $project website. !!!!
247----------------------------------------------------------------------
248";
0708f913 249} else {
34e49164 250
174d1640
C
251 pr2
252"----------------------------------------------------------------------
34e49164
C
253
254All seems fine for $project.
255
256To compile $project type:
708f4980
C
257 \$ make depend
258 \$ make all
259
260Or alternatively, for the optimized version:
261 \$ make all.opt
b1b2de81 262If you want both, you could use:
708f4980
C
263 \$ make world
264
34e49164
C
265
266To install type:
708f4980 267 \$ make install
34e49164
C
268
269Then, to test $project simply type:
708f4980 270 \$ $projectcmdline
34e49164
C
271
272";
273
0708f913
C
274if($python) {
275 pr2
34e49164 276"To use the python SmPL feature you may have to set some environment variables.
174d1640 277However, they are automatically set by the front-end installed in $prefix/bin.
34e49164
C
278For bash do:
279export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
174d1640 280export PYTHONPATH=\$PYTHONPATH:$src/python"
34e49164 281 }
174d1640 282 pr2 "----------------------------------------------------------------------";
34e49164
C
283}
284
34e49164
C
285######################################################################
286# Generating the configuration
287######################################################################
288
289pr2 "$project target prefix: $prefix (you can use --prefix to override it)";
290pr2 "Generating Makefile.config";
291open(CONFIG, ">Makefile.config");
292print CONFIG "# autogenerated by configure
293
8ba84ae2
C
294#
295INSTALL_PROGRAM?=install -c -m 755
296INSTALL_LIB?= install -c -m 755
297INSTALL_DATA?= install -c -m 644
298
34e49164
C
299# Where to install the binary
300BINDIR=$prefix/bin
301
302# Where to install the man pages
303MANDIR=$prefix/man
304
305# Where to install the lib
306LIBDIR=$prefix/lib
307
308# Where to install the configuration files
309SHAREDIR=$src
310
174d1640
C
311BASH_COMPLETION_DIR=/etc/bash_completion.d
312
34e49164
C
313# Features
314FEATURE_PYTHON=$python
978fd7e5 315FEATURE_TARZAN=$tarzan
0708f913 316
90aeb998
C
317PYCAMLDIR=$pydir
318MENHIRDIR=$menhirdir
319SEXPDIR=$sexpdir
320
0708f913
C
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.
325OPTBIN=$opt
34e49164
C
326";
327
174d1640
C
328
329my $pythonprefix = $python ? "yes" : "no";
330pr2 "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;`;
34e49164
C
333`cd python; make depend`;
334
174d1640
C
335my $ocamlprefix = $noocamlscripting ? "no" : "yes";
336pr2 "Support for ocaml scripting : $ocamlprefix";
337`cd ocaml; ln -sf ${ocamlprefix}_prepare_ocamlcocci.ml prepare_ocamlcocci.ml;`;
338`cd ocaml; make depend`;
339
340pr2 "Modifying globals/config.ml";
b1b2de81 341my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";
34e49164
C
342`$command`;
343