Release coccinelle-0.2.0
[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 $trac=0;
32 my $opt=".opt";
33 my $tarzan=1;
34
35 local $_ = join ' ', @ARGV;
36
37 # Parse options
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";
39 /--prefix=([^ ]*)/ and $prefix = $1;
40 /--without-python/ and $python = 0;
41 /--without-trac/ and $trac = 0;
42 /--with-trac/ and $trac = 1;
43 /--no-opt/ and $opt = "";
44 /--opt/ and $opt = ".opt";
45
46 #tarzan by default (used by score file parsing and now also for sexp_ast_c.ml)
47
48
49 #if($ARGV[0] =~ "--prefix=(.*)") {
50 # $prefix = $1;
51 #}
52 #if($ARGV[1] =~ "--without-python") {
53 # $python = 0;
54 #}
55
56 my $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;
69 sub pr2 { print STDERR "@_\n" }
70 sub cat {
71 my ($what) = @_;
72 my @list;
73 open(TMP, $what);
74 while(<TMP>) { push @list, "$_"; }
75 \@list;
76 }
77 sub notb { !$_[0] }
78 sub mapf { my ($f, $xs) = @_; [ map { &$f($_) } @{$xs} ] }
79 sub plural { my ($e) = @_; if ($e > 1) { "s" } else { "" } }
80
81 sub check_config { my ($command, $expect, $msggood, $msgbad) = @_;
82 my $error = 0;
83
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 ######################################################################
95 pr2 "Checking your configuration.\n";
96
97 my $error = 0;
98
99 #---------------------------------------------------------------------
100 # Compilers and runtimes
101 #---------------------------------------------------------------------
102 $error +=
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
110 if ($opt eq ".opt") {
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 {
134 $opt="";
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.";
141 }
142 else {
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.";
150 }
151 }
152
153 #we have cached the result of menhir in the tgz we build.
154
155 #$error +=
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
168 pr2 "";
169
170 $error += check_config(
171 "make -v 2>&1 |grep Make|",
172 "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
173 "make (gnu version) is present.",
174 "The program gnu make is missing or is not a good version.
175 We 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 ######################################################################
197 # Diagnostic
198 ######################################################################
199
200
201 if($error) {
202 pr2 "
203 ----------------------------------------------------------------------
204 !!!! There seems to have problem, we have found $error missing package" .
205 plural($error) . ".
206 " . (($error > 1) ? "Some of those packages" : "This package") .
207 " may be installed by picking " . ($error > 1 ? "them" : "it") .
208 " in $project-dependencies.tgz available
209 on the $project website. !!!!
210 ----------------------------------------------------------------------
211 ";
212 } else {
213
214 #pad: before the message was saying (make depend); make all
215 # I found this confusing so I removed it.
216
217 pr2 "
218
219 ----------------------------------------------------------------------
220
221 All seems fine for $project.
222
223 To compile $project type:
224 \$ make depend
225 \$ make all
226
227 Or alternatively, for the optimized version:
228 \$ make all.opt
229 If you want both, you could use:
230 \$ make world
231
232
233 To install type:
234 \$ make install
235
236 Then, to test $project simply type:
237 \$ $projectcmdline
238
239 ";
240
241 if($python) {
242 pr2
243 "To use the python SmPL feature you may have to set some environment variables.
244 For bash do:
245 export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
246 export PYTHONPATH=\$PYTHONPATH:$src/python
247 "
248 }
249 pr2 "
250 ----------------------------------------------------------------------
251 ";
252 }
253
254
255
256 ######################################################################
257 # Generating the configuration
258 ######################################################################
259
260 pr2 "$project target prefix: $prefix (you can use --prefix to override it)";
261 pr2 "Generating Makefile.config";
262 open(CONFIG, ">Makefile.config");
263 print CONFIG "# autogenerated by configure
264
265 #
266 INSTALL_PROGRAM?=install -c -m 755
267 INSTALL_LIB?= install -c -m 755
268 INSTALL_DATA?= install -c -m 644
269
270 # Where to install the binary
271 BINDIR=$prefix/bin
272
273 # Where to install the man pages
274 MANDIR=$prefix/man
275
276 # Where to install the lib
277 LIBDIR=$prefix/lib
278
279 # Where to install the configuration files
280 SHAREDIR=$src
281
282 # Features
283 FEATURE_PYTHON=$python
284 FEATURE_TARZAN=$tarzan
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.
290 OPTBIN=$opt
291 ";
292
293 pr2 "Modifying globals/config.ml";
294 pr2 "Generating appropriate links in python/ (python=$python)";
295 my $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
301 my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";
302 `$command`;
303
304 #
305 # Configuration of python with or without trac
306 #
307 `cd python/coccilib; ln -sf output_base.py output.py;`;
308 if($trac) {
309 # Switch between implementation
310 # in python/coccilib
311 pr2 "Selecting python trac extension";
312 `cd python/coccilib; ln -sf output_trac.py output.py;`;
313 }
314
315
316
317