forked from coccinelle/coccinelle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·434 lines (347 loc) · 11.7 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#!/usr/bin/perl
# Author: Yoann Padioleau
######################################################################
# Prelude
######################################################################
# Yes I know about autoconf ... and autoconf sux.
# assume standard: diff
# assume standard: perl
#TODO check python 2.5 ?
# need latex and hevea if want to compile the documentation
#old: --with-menhir=/path/to/menhirLib or `ocamlfind query menhirLib`
my $project =
"coccinelle";
my $projectcmdline =
"spatch -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c";
######################################################################
# Options
######################################################################
my $prefix="/usr/local";
my $python=1;
my $pcre=1;
my $noocamlscripting=0;
my $opt=".opt";
my $tarzan=1;
my $pydir="pycaml";
my $menhirdir="menhirlib";
my $sexpdir="ocamlsexp";
local $_ = join ' ', @ARGV;
# Parse options
/-h/ || /--help/ and die "usage: $0 [--prefix=path] [--without-FEATURE] [--no-opt]\n
\t--without-python\tDisable scripting in Python
\t--without-ocaml\t\tDisable scripting in Ocaml
\t--without-pcre\t\tDisable regexp with PCRE
\t--no-opt\t\tDo not use the optimimized version of OCaml
\t--opt\t\t\tUse the optimimized version of OCaml\n\n";
/--prefix=([^ ]*)/ and $prefix = $1;
/--without-pcre/ and $pcre = 0;
/--without-python/ and $python = 0;
/--without-ocaml/ and $noocamlscripting = 1;
/--no-opt/ and $opt = "";
/--opt/ and $opt = ".opt";
#tarzan by default (used by score file parsing and now also for sexp_ast_c.ml)
#if($ARGV[0] =~ "--prefix=(.*)") {
# $prefix = $1;
#}
#if($ARGV[1] =~ "--without-python") {
# $python = 0;
#}
my $src="$prefix/share/$project";
######################################################################
# Side effects
######################################################################
######################################################################
# Helpers
######################################################################
#BEGIN { die "need Perl 5 or greater" if $] < 5 ; }
#use Common;
sub pr2 { print STDERR "@_\n" }
sub cat {
my ($what) = @_;
my @list;
open(TMP, $what);
while(<TMP>) { push @list, "$_"; }
\@list;
}
sub notb { !$_[0] }
sub mapf { my ($f, $xs) = @_; [ map { &$f($_) } @{$xs} ] }
sub plural { my ($e) = @_; if ($e > 1) { "s" } else { "" } }
sub check_config { my ($command, $expect, $msggood, $msgbad) = @_;
my $error = 0;
my $full = cat($command);
my $res = join(" ", @{$full});
# pr2 $res;
if(notb($res =~ $expect)) { $error++; pr2 "!!!! $msgbad !!!!"; }
else { pr2 $msggood }
return $error;
}
######################################################################
# Let's go
######################################################################
pr2 "Checking your configuration.\n";
my $error = 0;
#---------------------------------------------------------------------
# Compilers and runtimes
#---------------------------------------------------------------------
$error +=
check_config("echo \"1;;\\n\" | ocaml |",
"Objective(.*) 3.\(09|1[0-9]\)",
"OCaml (the wonderful language) is present.",
"The program ocaml is missing or is not a good version. We need at least 3.09",
);
unless ($noocamlscripting) {
$noocamlscripting = check_config("echo \"1;;\\n\" | ocaml |",
"Objective(.*) 3.1[1-9]",
"OCaml >= 3.11 is present. OCaml scripting activated.",
"OCaml scripting disabled. We need at least OCaml 3.11",
);
}
my $ocamlprefix = $noocamlscripting ? "no" : "yes";
if ($opt eq ".opt") {
my $opt_check = `which ocamlc.opt 2> /dev/null`;
if($opt_check =~ "/ocamlc.opt\$") {
pr2 "ocamlc.opt is present.";
}
else {
$opt="";
pr2 "ocamlc.opt not found";
}
my $opt_check = `which ocamlopt.opt 2> /dev/null`;
if($opt_check =~ "/ocamlopt.opt\$") {
pr2 "ocamlopt.opt is present.";
}
else {
$opt="";
pr2 "ocamlopt.opt not found";
}
my $opt_check = `which ocamldep.opt 2> /dev/null`;
if($opt_check =~ "/ocamldep.opt\$") {
pr2 "ocamldep.opt is present.";
}
else {
$opt="";
pr2 "ocamldep.opt not found";
}
my $opt_check = `which ocamllex.opt 2> /dev/null`;
if($opt_check =~ "/ocamllex.opt\$") {
pr2 "ocamllex.opt is present.";
}
else {
$opt="";
pr2 "ocamllex.opt not found";
}
if($opt eq "") {
pr2 "At least one native OCaml tool have not been found.";
pr2 "Desactivation of all native OCaml tools for compilation.";
}
}
#we have cached the result of menhir in the tgz we build.
#$error +=
# check_config("menhir --version |",
# "menhir, version 20071212",
## "menhir, version 2006.*",
# "Menhir (the parser generator) is present.",
# "The program menhir is missing or is not a good version.",
# );
#---------------------------------------------------------------
# Developers tools
#---------------------------------------------------------------
pr2 "";
$error += check_config(
"make -v 2>&1 |grep Make|",
"GNU Make [^0-9]*3\.[0-9]+.*", #version 3.79.1, 3.81
"make (gnu version) is present.",
"The program gnu make is missing or is not a good version.
We need 3.XX",
);
#---------------------------------------------------------------------
# More developers tools
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Librairies
#---------------------------------------------------------------------
# Python dev
my $PY_VERSION;
if($python) {
if(check_config(
"python --version 2>&1 |",
'^Python 2\.([4567]|[4567]\.\S*)$',
"python is present",
"python is missing or is not a good version."
))
{
$python=0;
}
if($python) {
my $PY_PREFIX = `python pycaml/getprefix.py | tr -d '\n'`;
$PY_VERSION = `python pycaml/getversion.py | tr -d '\n'`;
my $python_hdr = "$PY_PREFIX/include/python$PY_VERSION/Python.h";
if(check_config(
"ls $python_hdr 2> /dev/null | ",
$python_hdr,
"Python.h found",
"Python.h missing - You need to install python-dev"
))
{
$python=0
}
}
}
my $ocamlfind=!check_config(
"which ocamlfind 2> /dev/null |",
'/ocamlfind$',
"ocamlfind is present",
"ocamlfind is missing -- Switch to local library copies."
);
# pycaml. Binding between Python and OCaml
my $syspydir=`ocamlfind query pycaml 2> /dev/null | xargs echo -n`;
if($syspydir) {
$pydir=$syspydir;
pr2 "'pycaml' library is present in $pydir";
} else {
pr2 "'pycaml' library is not present. A local copy will be used.";
}
# menhirLib. Runtime system for the parsers generated with menhir
my $sysmenhirdir=`ocamlfind query menhirLib 2> /dev/null | xargs echo -n`;
if($sysmenhirdir) {
$menhirdir=$sysmenhirdir;
pr2 "'menhirLib' library is present in $menhirdir";
} else {
pr2 "'menhirLib' library is not present. A local copy will be used.";
}
# sexplib. Runtime system for the parsers generated with menhir
my $syssexpdir=`ocamlfind query sexplib 2> /dev/null | xargs echo -n`;
if($syssexpdir) {
$sexpdir=$syssexpdir;
pr2 "'sexplib' library is present in $sexpdir";
} else {
pr2 "'sexplib' library is not present. A local copy will be used.";
}
# Check if libpcre-ocaml is available
# when pcre feature is enabled.
my $pcredir="";
if($pcre) {
$pcredir=`ocamlfind query pcre 2> /dev/null | xargs echo -n `;
if(check_config(
"echo -n $pcredir | ",
'^/.*$',
"'pcre-ocaml' library is present in $pcredir",
"'pcre-ocaml' library is not present - You need to install libpcre-ocaml-dev"
))
{
$pcre=0
}
}
######################################################################
# Generate config files (platform/portability issues)
######################################################################
######################################################################
# Generate globals files (features issues)
######################################################################
######################################################################
# Diagnostic
######################################################################
if($error) {
pr2 "
----------------------------------------------------------------------
!!!! There seems to have problem, we have found $error missing package" .
plural($error) . ".
" . (($error > 1) ? "Some of those packages" : "This package") .
" may be installed by picking " . ($error > 1 ? "them" : "it") .
" in $project-dependencies.tgz available
on the $project website. !!!!
----------------------------------------------------------------------
";
} else {
pr2
"----------------------------------------------------------------------
All seems fine for $project.
To compile $project type:
\$ make depend
\$ make all
Or alternatively, for the optimized version:
\$ make all.opt
If you want both, you could use:
\$ make world
To install type:
\$ make install
Then, to test $project simply type:
\$ $projectcmdline
";
if($python) {
pr2
"To use the python SmPL feature you may have to set some environment variables.
However, they are automatically set by the front-end installed in $prefix/bin.
For bash do:
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
export PYTHONPATH=\$PYTHONPATH:$src/python"
}
pr2 "----------------------------------------------------------------------";
}
######################################################################
# Generating the configuration
######################################################################
pr2 " Compilation configuration\n";
pr2 "$project target prefix: $prefix (you can use --prefix to override it)";
pr2 "Generating Makefile.config";
open(CONFIG, ">Makefile.config");
print CONFIG "# autogenerated by configure
#
INSTALL_PROGRAM?=install -c -m 755
INSTALL_LIB?= install -c -m 755
INSTALL_DATA?= install -c -m 644
# Where to install the binary
BINDIR=$prefix/bin
# Where to install the man pages
MANDIR=$prefix/man
# Where to install the lib
LIBDIR=$prefix/lib
# Where to install the configuration files
SHAREDIR=$src
BASH_COMPLETION_DIR=/etc/bash_completion.d
# Features
FEATURE_PYTHON=$python
FEATURE_TARZAN=$tarzan
";
if ($python) {
print CONFIG "PYVER=$PY_VERSION";
}
if($pcre) {
print CONFIG "
PCREDIR=$pcredir"
}
print CONFIG "
PYCAMLDIR=$pydir
MENHIRDIR=$menhirdir
SEXPDIR=$sexpdir
DYNLINK=$ocamlprefix
# The OPTBIN variable is here to allow to use ocamlc.opt instead of
# ocaml, when it is available, which speeds up compilation. So
# if you want the fast version of the ocaml chain tools, set this var
# or setenv it to \".opt\" in your startup script.
OPTBIN=$opt
";
my $pythonprefix = $python ? "yes" : "no";
pr2 "Support for python scripting: $pythonprefix";
`cd python; ln -sf ${pythonprefix}_pycocci.ml pycocci.ml; `;
`cd python; make depend`;
pr2 "Support for ocaml scripting: $ocamlprefix";
`cd ocaml; ln -sf ${ocamlprefix}_prepare_ocamlcocci.ml prepare_ocamlcocci.ml;`;
`cd ocaml; make depend`;
my $pcresuffix = $pcre ? "pcre" : "str";
pr2 "Support for regexp: $pcresuffix";
`cd globals; ln -sf regexp_${pcresuffix}.ml regexp.ml; touch regexp.ml;`;
`cd globals; make depend`;
pr2 "Modifying globals/config.ml";
my $command = "perl -p -e 's#Not_found.\*#Not_found->\\\"$src\\\"#' globals/config.ml.in > globals/config.ml";
`$command`;
pr2 "----------------------------------------------------------------------";
pr2 " Runtime dependency\n";
if ($ocamlfind) {
pr2 "Support for external ocaml library in ocaml scripting: yes (ocamlfind found)";
}
else {
pr2 "Support for external ocaml library in ocaml scripting: no";
pr2 "!!!!!!! WARNING !!!!!!! ocamlfind may be required at runtime";
}
pr2 "";