Commit | Line | Data |
---|---|---|
34e49164 | 1 | #!/usr/bin/perl |
708f4980 | 2 | |
fc1ad971 | 3 | # Author: Yoann Padioleau |
708f4980 | 4 | |
34e49164 C |
5 | ###################################################################### |
6 | # Prelude | |
7 | ###################################################################### | |
8 | ||
9 | # Yes I know about autoconf ... and autoconf sux. | |
10 | ||
11 | # assume standard: diff | |
12 | # assume standard: perl | |
13 | ||
708f4980 | 14 | #TODO check python 2.5 ? |
34e49164 | 15 | |
978fd7e5 C |
16 | # need latex and hevea if want to compile the documentation |
17 | ||
34e49164 C |
18 | #old: --with-menhir=/path/to/menhirLib or `ocamlfind query menhirLib` |
19 | ||
0708f913 | 20 | my $project = |
34e49164 | 21 | "coccinelle"; |
0708f913 | 22 | my $projectcmdline = |
978fd7e5 | 23 | "spatch -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c"; |
34e49164 | 24 | |
34e49164 C |
25 | ###################################################################### |
26 | # Options | |
27 | ###################################################################### | |
28 | ||
29 | my $prefix="/usr/local"; | |
30 | my $python=1; | |
993936c0 | 31 | my $pcre=1; |
174d1640 | 32 | my $noocamlscripting=0; |
0708f913 | 33 | my $opt=".opt"; |
978fd7e5 | 34 | my $tarzan=1; |
90aeb998 C |
35 | my $pydir="pycaml"; |
36 | my $menhirdir="menhirlib"; | |
37 | my $sexpdir="ocamlsexp"; | |
34e49164 C |
38 | |
39 | local $_ = join ' ', @ARGV; | |
40 | ||
41 | # Parse options | |
993936c0 C |
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"; | |
34e49164 | 48 | /--prefix=([^ ]*)/ and $prefix = $1; |
993936c0 | 49 | /--without-pcre/ and $pcre = 0; |
34e49164 | 50 | /--without-python/ and $python = 0; |
c491d8ee | 51 | /--without-ocaml/ and $noocamlscripting = 1; |
0708f913 | 52 | /--no-opt/ and $opt = ""; |
8ba84ae2 | 53 | /--opt/ and $opt = ".opt"; |
34e49164 | 54 | |
978fd7e5 C |
55 | #tarzan by default (used by score file parsing and now also for sexp_ast_c.ml) |
56 | ||
57 | ||
34e49164 C |
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" } | |
0708f913 | 79 | sub cat { |
34e49164 C |
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; | |
0708f913 | 92 | |
34e49164 C |
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 | ||
34e49164 C |
108 | #--------------------------------------------------------------------- |
109 | # Compilers and runtimes | |
110 | #--------------------------------------------------------------------- | |
174d1640 | 111 | |
0708f913 | 112 | $error += |
34e49164 | 113 | check_config("echo \"1;;\\n\" | ocaml |", |
174d1640 | 114 | "Objective(.*) 3.\(09|1[0-9]\)", |
34e49164 C |
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 | ||
3a314143 | 119 | unless ($noocamlscripting) { |
174d1640 C |
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 | ); | |
c491d8ee | 125 | } |
88e71198 | 126 | my $ocamlprefix = $noocamlscripting ? "no" : "yes"; |
174d1640 | 127 | |
0708f913 | 128 | if ($opt eq ".opt") { |
8ba84ae2 C |
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 { | |
0708f913 | 152 | $opt=""; |
8ba84ae2 C |
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."; | |
0708f913 C |
159 | } |
160 | else { | |
8ba84ae2 C |
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."; | |
0708f913 C |
168 | } |
169 | } | |
170 | ||
34e49164 C |
171 | #we have cached the result of menhir in the tgz we build. |
172 | ||
0708f913 | 173 | #$error += |
34e49164 C |
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|", | |
708f4980 | 190 | "GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81 |
34e49164 C |
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 | ||
34e49164 C |
196 | #--------------------------------------------------------------------- |
197 | # More developers tools | |
198 | #--------------------------------------------------------------------- | |
199 | ||
200 | #--------------------------------------------------------------------- | |
201 | # Librairies | |
202 | #--------------------------------------------------------------------- | |
203 | ||
3a314143 | 204 | # Python dev |
b23ff9c7 | 205 | my $PY_VERSION; |
3a314143 C |
206 | if($python) { |
207 | if(check_config( | |
208 | "python --version 2>&1 |", | |
b23ff9c7 | 209 | '^Python 2\.([4567]|[4567]\.\S*)$', |
3a314143 C |
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'`; | |
b23ff9c7 | 218 | $PY_VERSION = `python pycaml/getversion.py | tr -d '\n'`; |
3a314143 C |
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 | ||
ca417fcf C |
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 | ||
90aeb998 C |
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; | |
174d1640 C |
244 | pr2 "'pycaml' library is present in $pydir"; |
245 | } else { | |
246 | pr2 "'pycaml' library is not present. A local copy will be used."; | |
90aeb998 C |
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; | |
174d1640 C |
254 | pr2 "'menhirLib' library is present in $menhirdir"; |
255 | } else { | |
993936c0 | 256 | pr2 "'menhirLib' library is not present. A local copy will be used."; |
90aeb998 C |
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; | |
174d1640 C |
264 | pr2 "'sexplib' library is present in $sexpdir"; |
265 | } else { | |
993936c0 C |
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 | } | |
90aeb998 C |
283 | } |
284 | ||
34e49164 C |
285 | ###################################################################### |
286 | # Generate config files (platform/portability issues) | |
287 | ###################################################################### | |
288 | ||
289 | ||
290 | ###################################################################### | |
291 | # Generate globals files (features issues) | |
292 | ###################################################################### | |
293 | ||
294 | ###################################################################### | |
0708f913 | 295 | # Diagnostic |
34e49164 C |
296 | ###################################################################### |
297 | ||
298 | ||
0708f913 | 299 | if($error) { |
34e49164 C |
300 | pr2 " |
301 | ---------------------------------------------------------------------- | |
0708f913 | 302 | !!!! There seems to have problem, we have found $error missing package" . |
34e49164 | 303 | plural($error) . ". |
0708f913 C |
304 | " . (($error > 1) ? "Some of those packages" : "This package") . |
305 | " may be installed by picking " . ($error > 1 ? "them" : "it") . | |
34e49164 C |
306 | " in $project-dependencies.tgz available |
307 | on the $project website. !!!! | |
308 | ---------------------------------------------------------------------- | |
309 | "; | |
0708f913 | 310 | } else { |
34e49164 | 311 | |
174d1640 C |
312 | pr2 |
313 | "---------------------------------------------------------------------- | |
34e49164 C |
314 | |
315 | All seems fine for $project. | |
316 | ||
317 | To compile $project type: | |
708f4980 C |
318 | \$ make depend |
319 | \$ make all | |
320 | ||
321 | Or alternatively, for the optimized version: | |
322 | \$ make all.opt | |
b1b2de81 | 323 | If you want both, you could use: |
708f4980 C |
324 | \$ make world |
325 | ||
34e49164 C |
326 | |
327 | To install type: | |
708f4980 | 328 | \$ make install |
34e49164 C |
329 | |
330 | Then, to test $project simply type: | |
708f4980 | 331 | \$ $projectcmdline |
34e49164 C |
332 | |
333 | "; | |
334 | ||
ca417fcf C |
335 | if($python) { |
336 | pr2 | |
34e49164 | 337 | "To use the python SmPL feature you may have to set some environment variables. |
174d1640 | 338 | However, they are automatically set by the front-end installed in $prefix/bin. |
34e49164 C |
339 | For bash do: |
340 | export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib | |
174d1640 | 341 | export PYTHONPATH=\$PYTHONPATH:$src/python" |
34e49164 | 342 | } |
ca417fcf | 343 | |
174d1640 | 344 | pr2 "----------------------------------------------------------------------"; |
34e49164 C |
345 | } |
346 | ||
34e49164 C |
347 | ###################################################################### |
348 | # Generating the configuration | |
349 | ###################################################################### | |
350 | ||
ca417fcf C |
351 | pr2 " Compilation configuration\n"; |
352 | ||
34e49164 C |
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 | ||
8ba84ae2 C |
358 | # |
359 | INSTALL_PROGRAM?=install -c -m 755 | |
360 | INSTALL_LIB?= install -c -m 755 | |
361 | INSTALL_DATA?= install -c -m 644 | |
362 | ||
34e49164 C |
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 | ||
174d1640 C |
375 | BASH_COMPLETION_DIR=/etc/bash_completion.d |
376 | ||
34e49164 C |
377 | # Features |
378 | FEATURE_PYTHON=$python | |
978fd7e5 | 379 | FEATURE_TARZAN=$tarzan |
b23ff9c7 C |
380 | "; |
381 | ||
382 | if ($python) { | |
383 | print CONFIG "PYVER=$PY_VERSION"; | |
384 | } | |
0708f913 | 385 | |
993936c0 C |
386 | if($pcre) { |
387 | print CONFIG " | |
388 | PCREDIR=$pcredir" | |
389 | } | |
390 | ||
b23ff9c7 | 391 | print CONFIG " |
90aeb998 C |
392 | PYCAMLDIR=$pydir |
393 | MENHIRDIR=$menhirdir | |
394 | SEXPDIR=$sexpdir | |
88e71198 | 395 | DYNLINK=$ocamlprefix |
90aeb998 | 396 | |
0708f913 C |
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 | |
34e49164 C |
402 | "; |
403 | ||
174d1640 C |
404 | |
405 | my $pythonprefix = $python ? "yes" : "no"; | |
ca417fcf | 406 | pr2 "Support for python scripting: $pythonprefix"; |
174d1640 | 407 | `cd python; ln -sf ${pythonprefix}_pycocci.ml pycocci.ml; `; |
34e49164 C |
408 | `cd python; make depend`; |
409 | ||
ca417fcf | 410 | pr2 "Support for ocaml scripting: $ocamlprefix"; |
174d1640 C |
411 | `cd ocaml; ln -sf ${ocamlprefix}_prepare_ocamlcocci.ml prepare_ocamlcocci.ml;`; |
412 | `cd ocaml; make depend`; | |
413 | ||
993936c0 C |
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 | ||
174d1640 | 419 | pr2 "Modifying globals/config.ml"; |
b1b2de81 | 420 | my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml"; |
34e49164 C |
421 | `$command`; |
422 | ||
ca417fcf C |
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 { | |
8babbc8f C |
430 | pr2 "Support for external ocaml library in ocaml scripting: no"; |
431 | pr2 "!!!!!!! WARNING !!!!!!! ocamlfind may be required at runtime"; | |
ca417fcf C |
432 | } |
433 | ||
434 | pr2 ""; |