Release coccinelle-0.1.8
[bpt/coccinelle.git] / configure
1 #!/usr/bin/perl
2
3 # Author: Yoann Padioleau
4
5 ######################################################################
6 # Prelude
7 ######################################################################
8
9 # Yes I know about autoconf ... and autoconf sux.
10
11 # assume standard: diff
12 # assume standard: perl
13
14 #TODO check python 2.5 ?
15
16 #old: --with-menhir=/path/to/menhirLib or `ocamlfind query menhirLib`
17
18 my $project =
19 "coccinelle";
20 my $projectcmdline =
21 "spatch -sp_file demos/simple.cocci demos/simple.c";
22
23 ######################################################################
24 # Options
25 ######################################################################
26
27 my $prefix="/usr/local";
28 my $python=1;
29 my $trac=0;
30 my $opt=".opt";
31
32 local $_ = join ' ', @ARGV;
33
34 # Parse options
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";
36 /--prefix=([^ ]*)/ and $prefix = $1;
37 /--without-python/ and $python = 0;
38 /--without-trac/ and $trac = 0;
39 /--with-trac/ and $trac = 1;
40 /--no-opt/ and $opt = "";
41 /--opt/ and $opt = ".opt";
42
43 #if($ARGV[0] =~ "--prefix=(.*)") {
44 # $prefix = $1;
45 #}
46 #if($ARGV[1] =~ "--without-python") {
47 # $python = 0;
48 #}
49
50 my $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;
63 sub pr2 { print STDERR "@_\n" }
64 sub cat {
65 my ($what) = @_;
66 my @list;
67 open(TMP, $what);
68 while(<TMP>) { push @list, "$_"; }
69 \@list;
70 }
71 sub notb { !$_[0] }
72 sub mapf { my ($f, $xs) = @_; [ map { &$f($_) } @{$xs} ] }
73 sub plural { my ($e) = @_; if ($e > 1) { "s" } else { "" } }
74
75 sub check_config { my ($command, $expect, $msggood, $msgbad) = @_;
76 my $error = 0;
77
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 ######################################################################
89 pr2 "Checking your configuration.\n";
90
91 my $error = 0;
92
93 #---------------------------------------------------------------------
94 # Compilers and runtimes
95 #---------------------------------------------------------------------
96 $error +=
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
104 if ($opt eq ".opt") {
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 {
128 $opt="";
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.";
135 }
136 else {
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.";
144 }
145 }
146
147 #we have cached the result of menhir in the tgz we build.
148
149 #$error +=
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
162 pr2 "";
163
164 $error += check_config(
165 "make -v 2>&1 |grep Make|",
166 "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
167 "make (gnu version) is present.",
168 "The program gnu make is missing or is not a good version.
169 We 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 ######################################################################
191 # Diagnostic
192 ######################################################################
193
194
195 if($error) {
196 pr2 "
197 ----------------------------------------------------------------------
198 !!!! There seems to have problem, we have found $error missing package" .
199 plural($error) . ".
200 " . (($error > 1) ? "Some of those packages" : "This package") .
201 " may be installed by picking " . ($error > 1 ? "them" : "it") .
202 " in $project-dependencies.tgz available
203 on the $project website. !!!!
204 ----------------------------------------------------------------------
205 ";
206 } else {
207
208 #pad: before the message was saying (make depend); make all
209 # I found this confusing so I removed it.
210
211 pr2 "
212
213 ----------------------------------------------------------------------
214
215 All seems fine for $project.
216
217 To compile $project type:
218 \$ make depend
219 \$ make all
220
221 Or alternatively, for the optimized version:
222 \$ make all.opt
223 If you want both, you could use:
224 \$ make world
225
226
227 To install type:
228 \$ make install
229
230 Then, to test $project simply type:
231 \$ $projectcmdline
232
233 ";
234
235 if($python) {
236 pr2
237 "To use the python SmPL feature you may have to set some environment variables.
238 For bash do:
239 export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
240 export PYTHONPATH=\$PYTHONPATH:$src/python
241 "
242 }
243 pr2 "
244 ----------------------------------------------------------------------
245 ";
246 }
247
248
249
250 ######################################################################
251 # Generating the configuration
252 ######################################################################
253
254 pr2 "$project target prefix: $prefix (you can use --prefix to override it)";
255 pr2 "Generating Makefile.config";
256 open(CONFIG, ">Makefile.config");
257 print CONFIG "# autogenerated by configure
258
259 #
260 INSTALL_PROGRAM?=install -c -m 755
261 INSTALL_LIB?= install -c -m 755
262 INSTALL_DATA?= install -c -m 644
263
264 # Where to install the binary
265 BINDIR=$prefix/bin
266
267 # Where to install the man pages
268 MANDIR=$prefix/man
269
270 # Where to install the lib
271 LIBDIR=$prefix/lib
272
273 # Where to install the configuration files
274 SHAREDIR=$src
275
276 # Features
277 FEATURE_PYTHON=$python
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.
283 OPTBIN=$opt
284 ";
285
286 pr2 "Modifying globals/config.ml";
287 pr2 "Generating appropriate links in python/ (python=$python)";
288 my $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
294 my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";
295 `$command`;
296
297 #
298 # Configuration of python with or without trac
299 #
300 `cd python/coccilib; ln -sf output_base.py output.py;`;
301 if($trac) {
302 # Switch between implementation
303 # in python/coccilib
304 pr2 "Selecting python trac extension";
305 `cd python/coccilib; ln -sf output_trac.py output.py;`;
306 }
307
308
309
310