coccinelle release 1.0.0-rc6
[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 # need latex and hevea if want to compile the documentation
17
18 #old: --with-menhir=/path/to/menhirLib or `ocamlfind query menhirLib`
19
20 my $project =
21 "coccinelle";
22 my $projectcmdline =
23 "spatch -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c";
24
25 ######################################################################
26 # Options
27 ######################################################################
28
29 my $prefix="/usr/local";
30 my $python=1;
31 my $pcre=1;
32 my $noocamlscripting=0;
33 my $opt=".opt";
34 my $tarzan=1;
35 my $pydir="pycaml";
36 my $menhirdir="menhirlib";
37 my $sexpdir="ocamlsexp";
38
39 local $_ = join ' ', @ARGV;
40
41 # Parse options
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";
48 /--prefix=([^ ]*)/ and $prefix = $1;
49 /--without-pcre/ and $pcre = 0;
50 /--without-python/ and $python = 0;
51 /--without-ocaml/ and $noocamlscripting = 1;
52 /--no-opt/ and $opt = "";
53 /--opt/ and $opt = ".opt";
54
55 #tarzan by default (used by score file parsing and now also for sexp_ast_c.ml)
56
57
58 #if($ARGV[0] =~ "--prefix=(.*)") {
59 # $prefix = $1;
60 #}
61 #if($ARGV[1] =~ "--without-python") {
62 # $python = 0;
63 #}
64
65 my $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;
78 sub pr2 { print STDERR "@_\n" }
79 sub cat {
80 my ($what) = @_;
81 my @list;
82 open(TMP, $what);
83 while(<TMP>) { push @list, "$_"; }
84 \@list;
85 }
86 sub notb { !$_[0] }
87 sub mapf { my ($f, $xs) = @_; [ map { &$f($_) } @{$xs} ] }
88 sub plural { my ($e) = @_; if ($e > 1) { "s" } else { "" } }
89
90 sub check_config { my ($command, $expect, $msggood, $msgbad) = @_;
91 my $error = 0;
92
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 ######################################################################
104 pr2 "Checking your configuration.\n";
105
106 my $error = 0;
107
108 #---------------------------------------------------------------------
109 # Compilers and runtimes
110 #---------------------------------------------------------------------
111
112 $error +=
113 check_config("echo \"1;;\\n\" | ocaml |",
114 "Objective(.*) 3.\(09|1[0-9]\)",
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
119 unless ($noocamlscripting) {
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 );
125 }
126 my $ocamlprefix = $noocamlscripting ? "no" : "yes";
127
128 if ($opt eq ".opt") {
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 {
152 $opt="";
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.";
159 }
160 else {
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.";
168 }
169 }
170
171 #we have cached the result of menhir in the tgz we build.
172
173 #$error +=
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
186 pr2 "";
187
188 $error += check_config(
189 "make -v 2>&1 |grep Make|",
190 "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
191 "make (gnu version) is present.",
192 "The program gnu make is missing or is not a good version.
193 We need 3.XX",
194 );
195
196 #---------------------------------------------------------------------
197 # More developers tools
198 #---------------------------------------------------------------------
199
200 #---------------------------------------------------------------------
201 # Librairies
202 #---------------------------------------------------------------------
203
204 # Python dev
205 my $PY_VERSION;
206 if($python) {
207 if(check_config(
208 "python --version 2>&1 |",
209 '^Python 2\.([4567]|[4567]\.\S*)$',
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'`;
218 $PY_VERSION = `python pycaml/getversion.py | tr -d '\n'`;
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
232 my $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
239 # pycaml. Binding between Python and OCaml
240 my $syspydir=`ocamlfind query pycaml 2> /dev/null | xargs echo -n`;
241
242 if($syspydir) {
243 $pydir=$syspydir;
244 pr2 "'pycaml' library is present in $pydir";
245 } else {
246 pr2 "'pycaml' library is not present. A local copy will be used.";
247 }
248
249 # menhirLib. Runtime system for the parsers generated with menhir
250 my $sysmenhirdir=`ocamlfind query menhirLib 2> /dev/null | xargs echo -n`;
251
252 if($sysmenhirdir) {
253 $menhirdir=$sysmenhirdir;
254 pr2 "'menhirLib' library is present in $menhirdir";
255 } else {
256 pr2 "'menhirLib' library is not present. A local copy will be used.";
257 }
258
259 # sexplib. Runtime system for the parsers generated with menhir
260 my $syssexpdir=`ocamlfind query sexplib 2> /dev/null | xargs echo -n`;
261
262 if($syssexpdir) {
263 $sexpdir=$syssexpdir;
264 pr2 "'sexplib' library is present in $sexpdir";
265 } else {
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.
271 my $pcredir="";
272 if($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 }
283 }
284
285 ######################################################################
286 # Generate config files (platform/portability issues)
287 ######################################################################
288
289
290 ######################################################################
291 # Generate globals files (features issues)
292 ######################################################################
293
294 ######################################################################
295 # Diagnostic
296 ######################################################################
297
298
299 if($error) {
300 pr2 "
301 ----------------------------------------------------------------------
302 !!!! There seems to have problem, we have found $error missing package" .
303 plural($error) . ".
304 " . (($error > 1) ? "Some of those packages" : "This package") .
305 " may be installed by picking " . ($error > 1 ? "them" : "it") .
306 " in $project-dependencies.tgz available
307 on the $project website. !!!!
308 ----------------------------------------------------------------------
309 ";
310 } else {
311
312 pr2
313 "----------------------------------------------------------------------
314
315 All seems fine for $project.
316
317 To compile $project type:
318 \$ make depend
319 \$ make all
320
321 Or alternatively, for the optimized version:
322 \$ make all.opt
323 If you want both, you could use:
324 \$ make world
325
326
327 To install type:
328 \$ make install
329
330 Then, to test $project simply type:
331 \$ $projectcmdline
332
333 ";
334
335 if($python) {
336 pr2
337 "To use the python SmPL feature you may have to set some environment variables.
338 However, they are automatically set by the front-end installed in $prefix/bin.
339 For bash do:
340 export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
341 export PYTHONPATH=\$PYTHONPATH:$src/python"
342 }
343
344 pr2 "----------------------------------------------------------------------";
345 }
346
347 ######################################################################
348 # Generating the configuration
349 ######################################################################
350
351 pr2 " Compilation configuration\n";
352
353 pr2 "$project target prefix: $prefix (you can use --prefix to override it)";
354 pr2 "Generating Makefile.config";
355 open(CONFIG, ">Makefile.config");
356 print CONFIG "# autogenerated by configure
357
358 #
359 INSTALL_PROGRAM?=install -c -m 755
360 INSTALL_LIB?= install -c -m 755
361 INSTALL_DATA?= install -c -m 644
362
363 # Where to install the binary
364 BINDIR=$prefix/bin
365
366 # Where to install the man pages
367 MANDIR=$prefix/man
368
369 # Where to install the lib
370 LIBDIR=$prefix/lib
371
372 # Where to install the configuration files
373 SHAREDIR=$src
374
375 BASH_COMPLETION_DIR=/etc/bash_completion.d
376
377 # Features
378 FEATURE_PYTHON=$python
379 FEATURE_TARZAN=$tarzan
380 ";
381
382 if ($python) {
383 print CONFIG "PYVER=$PY_VERSION";
384 }
385
386 if($pcre) {
387 print CONFIG "
388 PCREDIR=$pcredir"
389 }
390
391 print CONFIG "
392 PYCAMLDIR=$pydir
393 MENHIRDIR=$menhirdir
394 SEXPDIR=$sexpdir
395 DYNLINK=$ocamlprefix
396
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.
401 OPTBIN=$opt
402 ";
403
404
405 my $pythonprefix = $python ? "yes" : "no";
406 pr2 "Support for python scripting: $pythonprefix";
407 `cd python; ln -sf ${pythonprefix}_pycocci.ml pycocci.ml; `;
408 `cd python; make depend`;
409
410 pr2 "Support for ocaml scripting: $ocamlprefix";
411 `cd ocaml; ln -sf ${ocamlprefix}_prepare_ocamlcocci.ml prepare_ocamlcocci.ml;`;
412 `cd ocaml; make depend`;
413
414 my $pcresuffix = $pcre ? "pcre" : "str";
415 pr2 "Support for regexp: $pcresuffix";
416 `cd globals; ln -sf regexp_${pcresuffix}.ml regexp.ml; touch regexp.ml;`;
417 `cd globals; make depend`;
418
419 pr2 "Modifying globals/config.ml";
420 my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";
421 `$command`;
422
423 pr2 "----------------------------------------------------------------------";
424 pr2 " Runtime dependency\n";
425
426 if ($ocamlfind) {
427 pr2 "Support for external ocaml library in ocaml scripting: yes (ocamlfind found)";
428 }
429 else {
430 pr2 "Support for external ocaml library in ocaml scripting: no";
431 pr2 "!!!!!!! WARNING !!!!!!! ocamlfind may be required at runtime";
432 }
433
434 pr2 "";