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