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