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