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