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