coccinelle release 1.0.0-rc6
[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;
993936c0 31my $pcre=1;
174d1640 32my $noocamlscripting=0;
0708f913 33my $opt=".opt";
978fd7e5 34my $tarzan=1;
90aeb998
C
35my $pydir="pycaml";
36my $menhirdir="menhirlib";
37my $sexpdir="ocamlsexp";
34e49164
C
38
39local $_ = join ' ', @ARGV;
40
41# Parse options
993936c0
C
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";
34e49164 48/--prefix=([^ ]*)/ and $prefix = $1;
993936c0 49/--without-pcre/ and $pcre = 0;
34e49164 50/--without-python/ and $python = 0;
c491d8ee 51/--without-ocaml/ and $noocamlscripting = 1;
0708f913 52/--no-opt/ and $opt = "";
8ba84ae2 53/--opt/ and $opt = ".opt";
34e49164 54
978fd7e5
C
55#tarzan by default (used by score file parsing and now also for sexp_ast_c.ml)
56
57
34e49164
C
58#if($ARGV[0] =~ "--prefix=(.*)") {
59# $prefix = $1;
60#}
61#if($ARGV[1] =~ "--without-python") {
62# $python = 0;
63#}
64
65my $src="$prefix/share/$project";
66
67######################################################################
68# Side effects
69######################################################################
70
71
72######################################################################
73# Helpers
74######################################################################
75#BEGIN { die "need Perl 5 or greater" if $] < 5 ; }
76
77#use Common;
78sub pr2 { print STDERR "@_\n" }
0708f913 79sub cat {
34e49164
C
80 my ($what) = @_;
81 my @list;
82 open(TMP, $what);
83 while(<TMP>) { push @list, "$_"; }
84 \@list;
85}
86sub notb { !$_[0] }
87sub mapf { my ($f, $xs) = @_; [ map { &$f($_) } @{$xs} ] }
88sub plural { my ($e) = @_; if ($e > 1) { "s" } else { "" } }
89
90sub check_config { my ($command, $expect, $msggood, $msgbad) = @_;
91 my $error = 0;
0708f913 92
34e49164
C
93 my $full = cat($command);
94 my $res = join(" ", @{$full});
95# pr2 $res;
96 if(notb($res =~ $expect)) { $error++; pr2 "!!!! $msgbad !!!!"; }
97 else { pr2 $msggood }
98 return $error;
99}
100
101######################################################################
102# Let's go
103######################################################################
104pr2 "Checking your configuration.\n";
105
106my $error = 0;
107
34e49164
C
108#---------------------------------------------------------------------
109# Compilers and runtimes
110#---------------------------------------------------------------------
174d1640 111
0708f913 112$error +=
34e49164 113 check_config("echo \"1;;\\n\" | ocaml |",
174d1640 114 "Objective(.*) 3.\(09|1[0-9]\)",
34e49164
C
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",
117 );
118
3a314143 119unless ($noocamlscripting) {
174d1640
C
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",
124 );
c491d8ee 125}
88e71198 126my $ocamlprefix = $noocamlscripting ? "no" : "yes";
174d1640 127
0708f913 128if ($opt eq ".opt") {
8ba84ae2
C
129 my $opt_check = `which ocamlc.opt 2> /dev/null`;
130 if($opt_check =~ "/ocamlc.opt\$") {
131 pr2 "ocamlc.opt is present.";
132 }
133 else {
134 $opt="";
135 pr2 "ocamlc.opt not found";
136 }
137
138 my $opt_check = `which ocamlopt.opt 2> /dev/null`;
139 if($opt_check =~ "/ocamlopt.opt\$") {
140 pr2 "ocamlopt.opt is present.";
141 }
142 else {
143 $opt="";
144 pr2 "ocamlopt.opt not found";
145 }
146
147 my $opt_check = `which ocamldep.opt 2> /dev/null`;
148 if($opt_check =~ "/ocamldep.opt\$") {
149 pr2 "ocamldep.opt is present.";
150 }
151 else {
0708f913 152 $opt="";
8ba84ae2
C
153 pr2 "ocamldep.opt not found";
154 }
155
156 my $opt_check = `which ocamllex.opt 2> /dev/null`;
157 if($opt_check =~ "/ocamllex.opt\$") {
158 pr2 "ocamllex.opt is present.";
0708f913
C
159 }
160 else {
8ba84ae2
C
161 $opt="";
162 pr2 "ocamllex.opt not found";
163 }
164
165 if($opt eq "") {
166 pr2 "At least one native OCaml tool have not been found.";
167 pr2 "Desactivation of all native OCaml tools for compilation.";
0708f913
C
168 }
169}
170
34e49164
C
171#we have cached the result of menhir in the tgz we build.
172
0708f913 173#$error +=
34e49164
C
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.",
179# );
180
181
182#---------------------------------------------------------------
183# Developers tools
184#---------------------------------------------------------------
185
186pr2 "";
187
188$error += check_config(
189 "make -v 2>&1 |grep Make|",
708f4980 190 "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
34e49164
C
191 "make (gnu version) is present.",
192 "The program gnu make is missing or is not a good version.
193We need 3.XX",
194);
195
34e49164
C
196#---------------------------------------------------------------------
197# More developers tools
198#---------------------------------------------------------------------
199
200#---------------------------------------------------------------------
201# Librairies
202#---------------------------------------------------------------------
203
3a314143 204# Python dev
b23ff9c7 205my $PY_VERSION;
3a314143
C
206if($python) {
207 if(check_config(
208 "python --version 2>&1 |",
b23ff9c7 209 '^Python 2\.([4567]|[4567]\.\S*)$',
3a314143
C
210 "python is present",
211 "python is missing or is not a good version."
212 ))
213 {
214 $python=0;
215 }
216 if($python) {
217 my $PY_PREFIX = `python pycaml/getprefix.py | tr -d '\n'`;
b23ff9c7 218 $PY_VERSION = `python pycaml/getversion.py | tr -d '\n'`;
3a314143
C
219 my $python_hdr = "$PY_PREFIX/include/python$PY_VERSION/Python.h";
220 if(check_config(
221 "ls $python_hdr 2> /dev/null | ",
222 $python_hdr,
223 "Python.h found",
224 "Python.h missing - You need to install python-dev"
225 ))
226 {
227 $python=0
228 }
229 }
230}
231
ca417fcf
C
232my $ocamlfind=!check_config(
233 "which ocamlfind 2> /dev/null |",
234 '/ocamlfind$',
235 "ocamlfind is present",
236 "ocamlfind is missing -- Switch to local library copies."
237 );
238
90aeb998
C
239# pycaml. Binding between Python and OCaml
240my $syspydir=`ocamlfind query pycaml 2> /dev/null | xargs echo -n`;
241
242if($syspydir) {
243 $pydir=$syspydir;
174d1640
C
244 pr2 "'pycaml' library is present in $pydir";
245} else {
246 pr2 "'pycaml' library is not present. A local copy will be used.";
90aeb998
C
247}
248
249# menhirLib. Runtime system for the parsers generated with menhir
250my $sysmenhirdir=`ocamlfind query menhirLib 2> /dev/null | xargs echo -n`;
251
252if($sysmenhirdir) {
253 $menhirdir=$sysmenhirdir;
174d1640
C
254 pr2 "'menhirLib' library is present in $menhirdir";
255} else {
993936c0 256 pr2 "'menhirLib' library is not present. A local copy will be used.";
90aeb998
C
257}
258
259# sexplib. Runtime system for the parsers generated with menhir
260my $syssexpdir=`ocamlfind query sexplib 2> /dev/null | xargs echo -n`;
261
262if($syssexpdir) {
263 $sexpdir=$syssexpdir;
174d1640
C
264 pr2 "'sexplib' library is present in $sexpdir";
265} else {
993936c0
C
266 pr2 "'sexplib' library is not present. A local copy will be used.";
267}
268
269# Check if libpcre-ocaml is available
270# when pcre feature is enabled.
271my $pcredir="";
272if($pcre) {
273 $pcredir=`ocamlfind query pcre 2> /dev/null | xargs echo -n `;
274 if(check_config(
275 "echo -n $pcredir | ",
276 '^/.*$',
277 "'pcre-ocaml' library is present in $pcredir",
278 "'pcre-ocaml' library is not present - You need to install libpcre-ocaml-dev"
279 ))
280 {
281 $pcre=0
282 }
90aeb998
C
283}
284
34e49164
C
285######################################################################
286# Generate config files (platform/portability issues)
287######################################################################
288
289
290######################################################################
291# Generate globals files (features issues)
292######################################################################
293
294######################################################################
0708f913 295# Diagnostic
34e49164
C
296######################################################################
297
298
0708f913 299if($error) {
34e49164
C
300 pr2 "
301----------------------------------------------------------------------
0708f913 302!!!! There seems to have problem, we have found $error missing package" .
34e49164 303plural($error) . ".
0708f913
C
304" . (($error > 1) ? "Some of those packages" : "This package") .
305 " may be installed by picking " . ($error > 1 ? "them" : "it") .
34e49164
C
306 " in $project-dependencies.tgz available
307on the $project website. !!!!
308----------------------------------------------------------------------
309";
0708f913 310} else {
34e49164 311
174d1640
C
312 pr2
313"----------------------------------------------------------------------
34e49164
C
314
315All seems fine for $project.
316
317To compile $project type:
708f4980
C
318 \$ make depend
319 \$ make all
320
321Or alternatively, for the optimized version:
322 \$ make all.opt
b1b2de81 323If you want both, you could use:
708f4980
C
324 \$ make world
325
34e49164
C
326
327To install type:
708f4980 328 \$ make install
34e49164
C
329
330Then, to test $project simply type:
708f4980 331 \$ $projectcmdline
34e49164
C
332
333";
334
ca417fcf
C
335 if($python) {
336 pr2
34e49164 337"To use the python SmPL feature you may have to set some environment variables.
174d1640 338However, they are automatically set by the front-end installed in $prefix/bin.
34e49164
C
339For bash do:
340export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
174d1640 341export PYTHONPATH=\$PYTHONPATH:$src/python"
34e49164 342 }
ca417fcf 343
174d1640 344 pr2 "----------------------------------------------------------------------";
34e49164
C
345}
346
34e49164
C
347######################################################################
348# Generating the configuration
349######################################################################
350
ca417fcf
C
351pr2 " Compilation configuration\n";
352
34e49164
C
353pr2 "$project target prefix: $prefix (you can use --prefix to override it)";
354pr2 "Generating Makefile.config";
355open(CONFIG, ">Makefile.config");
356print CONFIG "# autogenerated by configure
357
8ba84ae2
C
358#
359INSTALL_PROGRAM?=install -c -m 755
360INSTALL_LIB?= install -c -m 755
361INSTALL_DATA?= install -c -m 644
362
34e49164
C
363# Where to install the binary
364BINDIR=$prefix/bin
365
366# Where to install the man pages
367MANDIR=$prefix/man
368
369# Where to install the lib
370LIBDIR=$prefix/lib
371
372# Where to install the configuration files
373SHAREDIR=$src
374
174d1640
C
375BASH_COMPLETION_DIR=/etc/bash_completion.d
376
34e49164
C
377# Features
378FEATURE_PYTHON=$python
978fd7e5 379FEATURE_TARZAN=$tarzan
b23ff9c7
C
380";
381
382if ($python) {
383print CONFIG "PYVER=$PY_VERSION";
384}
0708f913 385
993936c0
C
386if($pcre) {
387print CONFIG "
388PCREDIR=$pcredir"
389}
390
b23ff9c7 391print CONFIG "
90aeb998
C
392PYCAMLDIR=$pydir
393MENHIRDIR=$menhirdir
394SEXPDIR=$sexpdir
88e71198 395DYNLINK=$ocamlprefix
90aeb998 396
0708f913
C
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.
401OPTBIN=$opt
34e49164
C
402";
403
174d1640
C
404
405my $pythonprefix = $python ? "yes" : "no";
ca417fcf 406pr2 "Support for python scripting: $pythonprefix";
174d1640 407`cd python; ln -sf ${pythonprefix}_pycocci.ml pycocci.ml; `;
34e49164
C
408`cd python; make depend`;
409
ca417fcf 410pr2 "Support for ocaml scripting: $ocamlprefix";
174d1640
C
411`cd ocaml; ln -sf ${ocamlprefix}_prepare_ocamlcocci.ml prepare_ocamlcocci.ml;`;
412`cd ocaml; make depend`;
413
993936c0
C
414my $pcresuffix = $pcre ? "pcre" : "str";
415pr2 "Support for regexp: $pcresuffix";
416`cd globals; ln -sf regexp_${pcresuffix}.ml regexp.ml; touch regexp.ml;`;
417`cd globals; make depend`;
418
174d1640 419pr2 "Modifying globals/config.ml";
b1b2de81 420my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";
34e49164
C
421`$command`;
422
ca417fcf
C
423pr2 "----------------------------------------------------------------------";
424pr2 " Runtime dependency\n";
425
426if ($ocamlfind) {
427pr2 "Support for external ocaml library in ocaml scripting: yes (ocamlfind found)";
428}
429else {
8babbc8f
C
430pr2 "Support for external ocaml library in ocaml scripting: no";
431pr2 "!!!!!!! WARNING !!!!!!! ocamlfind may be required at runtime";
ca417fcf
C
432}
433
434pr2 "";