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