bd012c0600dcc6deb5bc466c65c99f532cf087f2
[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\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
39 #if($ARGV[0] =~ "--prefix=(.*)") {
40 # $prefix = $1;
41 #}
42 #if($ARGV[1] =~ "--without-python") {
43 # $python = 0;
44 #}
45
46 my $src="$prefix/share/$project";
47
48 ######################################################################
49 # Side effects
50 ######################################################################
51
52
53 ######################################################################
54 # Helpers
55 ######################################################################
56 #BEGIN { die "need Perl 5 or greater" if $] < 5 ; }
57
58 #use Common;
59 sub pr2 { print STDERR "@_\n" }
60 sub cat {
61 my ($what) = @_;
62 my @list;
63 open(TMP, $what);
64 while(<TMP>) { push @list, "$_"; }
65 \@list;
66 }
67 sub notb { !$_[0] }
68 sub mapf { my ($f, $xs) = @_; [ map { &$f($_) } @{$xs} ] }
69 sub plural { my ($e) = @_; if ($e > 1) { "s" } else { "" } }
70
71 sub check_config { my ($command, $expect, $msggood, $msgbad) = @_;
72 my $error = 0;
73
74 my $full = cat($command);
75 my $res = join(" ", @{$full});
76 # pr2 $res;
77 if(notb($res =~ $expect)) { $error++; pr2 "!!!! $msgbad !!!!"; }
78 else { pr2 $msggood }
79 return $error;
80 }
81
82 ######################################################################
83 # Let's go
84 ######################################################################
85 pr2 "Checking your configuration.\n";
86
87 my $error = 0;
88
89 #---------------------------------------------------------------------
90 # Compilers and runtimes
91 #---------------------------------------------------------------------
92 $error +=
93 check_config("echo \"1;;\\n\" | ocaml |",
94 # "Objective(.*) 3.0[9]",
95 "Objective(.*) 3.",
96 "OCaml (the wonderful language) is present.",
97 "The program ocaml is missing or is not a good version. We need at least 3.09",
98 );
99
100 if ($opt eq ".opt") {
101 my $opt_check = `which ocamlc.opt 2>&1 | cut -d' ' -f2`;
102 if($opt_check =~ "no") {
103 $opt="";
104 pr2 "Native version of OCaml not found";
105 }
106 else {
107 pr2 "Native version of OCaml is present.";
108 }
109 }
110
111 #we have cached the result of menhir in the tgz we build.
112
113 #$error +=
114 # check_config("menhir --version |",
115 # "menhir, version 20071212",
116 ## "menhir, version 2006.*",
117 # "Menhir (the parser generator) is present.",
118 # "The program menhir is missing or is not a good version.",
119 # );
120
121
122 #---------------------------------------------------------------
123 # Developers tools
124 #---------------------------------------------------------------
125
126 pr2 "";
127
128 $error += check_config(
129 "make -v 2>&1 |grep Make|",
130 "GNU Make 3\.[0-9]+", #version 3.81
131 "make (gnu version) is present.",
132 "The program gnu make is missing or is not a good version.
133 We need 3.XX",
134 );
135
136
137 #---------------------------------------------------------------------
138 # More developers tools
139 #---------------------------------------------------------------------
140
141 #---------------------------------------------------------------------
142 # Librairies
143 #---------------------------------------------------------------------
144
145 ######################################################################
146 # Generate config files (platform/portability issues)
147 ######################################################################
148
149
150 ######################################################################
151 # Generate globals files (features issues)
152 ######################################################################
153
154 ######################################################################
155 # Diagnostic
156 ######################################################################
157
158
159 if($error) {
160 pr2 "
161 ----------------------------------------------------------------------
162 !!!! There seems to have problem, we have found $error missing package" .
163 plural($error) . ".
164 " . (($error > 1) ? "Some of those packages" : "This package") .
165 " may be installed by picking " . ($error > 1 ? "them" : "it") .
166 " in $project-dependencies.tgz available
167 on the $project website. !!!!
168 ----------------------------------------------------------------------
169 ";
170 } else {
171
172 pr2 "
173
174 ----------------------------------------------------------------------
175
176 All seems fine for $project.
177
178 To compile $project type:
179 make depend; make
180
181 To install type:
182 make install
183
184 Then, to test $project simply type:
185 $projectcmdline
186
187 ";
188
189 if($python) {
190 pr2
191 "To use the python SmPL feature you may have to set some environment variables.
192 For bash do:
193 export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
194 export PYTHONPATH=\$PYTHONPATH:$src/python
195 "
196 }
197 pr2 "
198 ----------------------------------------------------------------------
199 ";
200 }
201
202
203
204 ######################################################################
205 # Generating the configuration
206 ######################################################################
207
208 pr2 "$project target prefix: $prefix (you can use --prefix to override it)";
209 pr2 "Generating Makefile.config";
210 open(CONFIG, ">Makefile.config");
211 print CONFIG "# autogenerated by configure
212
213 # Where to install the binary
214 BINDIR=$prefix/bin
215
216 # Where to install the man pages
217 MANDIR=$prefix/man
218
219 # Where to install the lib
220 LIBDIR=$prefix/lib
221
222 # Where to install the configuration files
223 SHAREDIR=$src
224
225 # Features
226 FEATURE_PYTHON=$python
227
228 # The OPTBIN variable is here to allow to use ocamlc.opt instead of
229 # ocaml, when it is available, which speeds up compilation. So
230 # if you want the fast version of the ocaml chain tools, set this var
231 # or setenv it to \".opt\" in your startup script.
232 OPTBIN=$opt
233 ";
234
235 pr2 "Modifying globals/config.ml";
236 pr2 "Generating appropriate links in python/ (python=$python)";
237 my $pythonprefix = $python ? "yes_" : "no_";
238 `cd python; rm -f pycocci.ml pycocci_aux.ml;`;
239 `cd python; ln -s ${pythonprefix}pycocci.ml pycocci.ml; `;
240 `cd python; ln -s ${pythonprefix}pycocci_aux.ml pycocci_aux.ml;`;
241 `cd python; make depend`;
242
243 my $command = "perl -p -i -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml";
244 `$command`;
245
246 #
247 # Configuration of python with or without trac
248 #
249 `cd python/coccilib; ln -sf output_base.py output.py;`;
250 if($trac) {
251 # Switch between implementation
252 # in python/coccilib
253 pr2 "Selecting python trac extension";
254 `cd python/coccilib; ln -sf output_trac.py output.py;`;
255 }
256
257
258
259