Release coccinelle-0.2.2-rc1
[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;
0708f913 31my $opt=".opt";
978fd7e5 32my $tarzan=1;
34e49164
C
33
34local $_ = join ' ', @ARGV;
35
36# Parse options
ae4735db 37/-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
38/--prefix=([^ ]*)/ and $prefix = $1;
39/--without-python/ and $python = 0;
0708f913 40/--no-opt/ and $opt = "";
8ba84ae2 41/--opt/ and $opt = ".opt";
34e49164 42
978fd7e5
C
43#tarzan by default (used by score file parsing and now also for sexp_ast_c.ml)
44
45
34e49164
C
46#if($ARGV[0] =~ "--prefix=(.*)") {
47# $prefix = $1;
48#}
49#if($ARGV[1] =~ "--without-python") {
50# $python = 0;
51#}
52
53my $src="$prefix/share/$project";
54
55######################################################################
56# Side effects
57######################################################################
58
59
60######################################################################
61# Helpers
62######################################################################
63#BEGIN { die "need Perl 5 or greater" if $] < 5 ; }
64
65#use Common;
66sub pr2 { print STDERR "@_\n" }
0708f913 67sub cat {
34e49164
C
68 my ($what) = @_;
69 my @list;
70 open(TMP, $what);
71 while(<TMP>) { push @list, "$_"; }
72 \@list;
73}
74sub notb { !$_[0] }
75sub mapf { my ($f, $xs) = @_; [ map { &$f($_) } @{$xs} ] }
76sub plural { my ($e) = @_; if ($e > 1) { "s" } else { "" } }
77
78sub check_config { my ($command, $expect, $msggood, $msgbad) = @_;
79 my $error = 0;
0708f913 80
34e49164
C
81 my $full = cat($command);
82 my $res = join(" ", @{$full});
83# pr2 $res;
84 if(notb($res =~ $expect)) { $error++; pr2 "!!!! $msgbad !!!!"; }
85 else { pr2 $msggood }
86 return $error;
87}
88
89######################################################################
90# Let's go
91######################################################################
92pr2 "Checking your configuration.\n";
93
94my $error = 0;
95
34e49164
C
96#---------------------------------------------------------------------
97# Compilers and runtimes
98#---------------------------------------------------------------------
0708f913 99$error +=
34e49164
C
100 check_config("echo \"1;;\\n\" | ocaml |",
101# "Objective(.*) 3.0[9]",
102 "Objective(.*) 3.",
103 "OCaml (the wonderful language) is present.",
104 "The program ocaml is missing or is not a good version. We need at least 3.09",
105 );
106
0708f913 107if ($opt eq ".opt") {
8ba84ae2
C
108 my $opt_check = `which ocamlc.opt 2> /dev/null`;
109 if($opt_check =~ "/ocamlc.opt\$") {
110 pr2 "ocamlc.opt is present.";
111 }
112 else {
113 $opt="";
114 pr2 "ocamlc.opt not found";
115 }
116
117 my $opt_check = `which ocamlopt.opt 2> /dev/null`;
118 if($opt_check =~ "/ocamlopt.opt\$") {
119 pr2 "ocamlopt.opt is present.";
120 }
121 else {
122 $opt="";
123 pr2 "ocamlopt.opt not found";
124 }
125
126 my $opt_check = `which ocamldep.opt 2> /dev/null`;
127 if($opt_check =~ "/ocamldep.opt\$") {
128 pr2 "ocamldep.opt is present.";
129 }
130 else {
0708f913 131 $opt="";
8ba84ae2
C
132 pr2 "ocamldep.opt not found";
133 }
134
135 my $opt_check = `which ocamllex.opt 2> /dev/null`;
136 if($opt_check =~ "/ocamllex.opt\$") {
137 pr2 "ocamllex.opt is present.";
0708f913
C
138 }
139 else {
8ba84ae2
C
140 $opt="";
141 pr2 "ocamllex.opt not found";
142 }
143
144 if($opt eq "") {
145 pr2 "At least one native OCaml tool have not been found.";
146 pr2 "Desactivation of all native OCaml tools for compilation.";
0708f913
C
147 }
148}
149
34e49164
C
150#we have cached the result of menhir in the tgz we build.
151
0708f913 152#$error +=
34e49164
C
153# check_config("menhir --version |",
154# "menhir, version 20071212",
155## "menhir, version 2006.*",
156# "Menhir (the parser generator) is present.",
157# "The program menhir is missing or is not a good version.",
158# );
159
160
161#---------------------------------------------------------------
162# Developers tools
163#---------------------------------------------------------------
164
165pr2 "";
166
167$error += check_config(
168 "make -v 2>&1 |grep Make|",
708f4980 169 "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
34e49164
C
170 "make (gnu version) is present.",
171 "The program gnu make is missing or is not a good version.
172We need 3.XX",
173);
174
175
176#---------------------------------------------------------------------
177# More developers tools
178#---------------------------------------------------------------------
179
180#---------------------------------------------------------------------
181# Librairies
182#---------------------------------------------------------------------
183
184######################################################################
185# Generate config files (platform/portability issues)
186######################################################################
187
188
189######################################################################
190# Generate globals files (features issues)
191######################################################################
192
193######################################################################
0708f913 194# Diagnostic
34e49164
C
195######################################################################
196
197
0708f913 198if($error) {
34e49164
C
199 pr2 "
200----------------------------------------------------------------------
0708f913 201!!!! There seems to have problem, we have found $error missing package" .
34e49164 202plural($error) . ".
0708f913
C
203" . (($error > 1) ? "Some of those packages" : "This package") .
204 " may be installed by picking " . ($error > 1 ? "them" : "it") .
34e49164
C
205 " in $project-dependencies.tgz available
206on the $project website. !!!!
207----------------------------------------------------------------------
208";
0708f913 209} else {
34e49164 210
708f4980
C
211#pad: before the message was saying (make depend); make all
212# I found this confusing so I removed it.
213
34e49164 214 pr2 "
0708f913 215
34e49164
C
216----------------------------------------------------------------------
217
218All seems fine for $project.
219
220To compile $project type:
708f4980
C
221 \$ make depend
222 \$ make all
223
224Or alternatively, for the optimized version:
225 \$ make all.opt
b1b2de81 226If you want both, you could use:
708f4980
C
227 \$ make world
228
34e49164
C
229
230To install type:
708f4980 231 \$ make install
34e49164
C
232
233Then, to test $project simply type:
708f4980 234 \$ $projectcmdline
34e49164
C
235
236";
237
0708f913
C
238if($python) {
239 pr2
34e49164
C
240"To use the python SmPL feature you may have to set some environment variables.
241For bash do:
242export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
243export PYTHONPATH=\$PYTHONPATH:$src/python
244"
245 }
246 pr2 "
247----------------------------------------------------------------------
248";
249}
250
251
252
253######################################################################
254# Generating the configuration
255######################################################################
256
257pr2 "$project target prefix: $prefix (you can use --prefix to override it)";
258pr2 "Generating Makefile.config";
259open(CONFIG, ">Makefile.config");
260print CONFIG "# autogenerated by configure
261
8ba84ae2
C
262#
263INSTALL_PROGRAM?=install -c -m 755
264INSTALL_LIB?= install -c -m 755
265INSTALL_DATA?= install -c -m 644
266
34e49164
C
267# Where to install the binary
268BINDIR=$prefix/bin
269
270# Where to install the man pages
271MANDIR=$prefix/man
272
273# Where to install the lib
274LIBDIR=$prefix/lib
275
276# Where to install the configuration files
277SHAREDIR=$src
278
279# Features
280FEATURE_PYTHON=$python
978fd7e5 281FEATURE_TARZAN=$tarzan
0708f913
C
282
283# The OPTBIN variable is here to allow to use ocamlc.opt instead of
284# ocaml, when it is available, which speeds up compilation. So
285# if you want the fast version of the ocaml chain tools, set this var
286# or setenv it to \".opt\" in your startup script.
287OPTBIN=$opt
34e49164
C
288";
289
290pr2 "Modifying globals/config.ml";
291pr2 "Generating appropriate links in python/ (python=$python)";
292my $pythonprefix = $python ? "yes_" : "no_";
293`cd python; rm -f pycocci.ml pycocci_aux.ml;`;
294`cd python; ln -s ${pythonprefix}pycocci.ml pycocci.ml; `;
295`cd python; ln -s ${pythonprefix}pycocci_aux.ml pycocci_aux.ml;`;
296`cd python; make depend`;
297
b1b2de81 298my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";
34e49164
C
299`$command`;
300