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