Commit | Line | Data |
---|---|---|
feec80c3 C |
1 | dnl standard initialization (we only use autoconf not automake) |
2 | AC_INIT([coccinelle], [`cat ./version`], [cocci@diku.dk], [], [http://coccinelle.lip6.fr/]) | |
3 | AC_SUBST([COCCI_VERSION], [$(cat ./version)]) | |
4 | AC_SUBST([COCCI_SRCDIR], [$(pwd)]) | |
5 | AC_MSG_NOTICE([configuring coccinelle $COCCI_VERSION in $COCCI_SRCDIR]) | |
6 | ||
7 | AC_CONFIG_SRCDIR([cocci.ml]) dnl this file must be present in our src directory | |
8 | AC_COCCI_CONFVERSION | |
9 | ||
10 | dnl reminder that this configure depends on macros generated by aclocal | |
11 | AC_MSG_NOTICE([this configure program uses pkg-config m4 macros]) | |
12 | AC_MSG_NOTICE([this configure program uses ocaml m4 macros (see setup/ocaml.m4)]) | |
13 | AC_MSG_NOTICE([this configure program uses custom m4 macros (see setup/cocci.m4)]) | |
14 | AC_MSG_NOTICE([some fake substitutions for required but unavailable programs may be used (see setup/fake*)]) | |
15 | ||
16 | ||
17 | dnl | |
18 | dnl Note: the conditionals in this configure script are tricky. | |
19 | dnl The approach taken here is that many tools can be enabled/disabled | |
20 | dnl and paths can be given explicitly via commandline parameters or | |
21 | dnl environment variables. | |
22 | dnl | |
23 | ||
24 | ||
25 | dnl | |
26 | dnl Basic tools | |
27 | dnl | |
28 | ||
29 | AC_MSG_NOTICE([verifying basic tools]) | |
30 | ||
31 | AC_PROG_INSTALL | |
32 | AC_PROG_MKDIR_P | |
33 | AC_PROG_CPP | |
34 | AC_PATH_PROG([TAR],[tar]) | |
35 | AC_PATH_PROG([PATCH],[patch]) | |
36 | ||
37 | dnl pkg config is required | |
38 | AC_COCCI_TOOL([PKG_CONFIG],[pkg-config],[$COCCI_SRCDIR/setup/fake-subst.sh pkg-config]) | |
39 | AS_IF([test "x$PKG_CONFIG" = xno], | |
40 | [dnl | |
41 | AC_MSG_ERROR([A suitable pkg-config could not be found.]) | |
42 | ]) | |
43 | ||
44 | dnl ocaml compile | |
45 | AC_PROG_OCAML | |
46 | AC_CHECK_OCAMLVERSION([OCAMLATLEAST310],[3.10]) | |
47 | AC_CHECK_OCAMLVERSION([OCAMLATLEAST311],[3.11]) | |
48 | ||
49 | AS_IF([test "x$OCAMLC" = xno -o "x$OCAMLDEP" = xno -o "x$OCAMLDOC" = xno -o "x$OCAMLMKLIB" = xno], | |
50 | [dnl | |
51 | AC_MSG_ERROR([You must install the OCaml compiler]) | |
52 | ]) | |
53 | AS_IF([test "x$OCAMLATLEAST310" = xno],[AC_MSG_NOTICE([a more recent OCaml installation may be required])]) | |
54 | ||
55 | dnl ocaml tools | |
56 | AC_PROG_CAMLP4 | |
57 | AC_COCCI_TOOL([OCAMLLEX],[ocamllex],[]) | |
58 | AC_COCCI_TOOL([OCAMLYACC],[ocamlyacc],[]) | |
59 | AC_COCCI_TOOL([OCAMLFIND],[ocamlfind],[$COCCI_SRCDIR/setup/fake-subst.sh ocamlfind]) | |
60 | ||
61 | dnl enforce ocaml tool requirements | |
62 | AS_IF([test "x$OCAMLLEX" = xno], | |
63 | [dnl | |
64 | AC_MSG_ERROR([the OCaml Lexer needs to be installed (the ocamllex command). It should be part of your OCaml distribution.]) | |
65 | ]) | |
66 | ||
67 | AS_IF([test "x$OCAMLYACC" = xno], | |
68 | [dnl | |
69 | AC_MSG_ERROR([The OCaml parser generated needs to be installed (the ocamlyacc command). It should be part of your OCaml distribution.]) | |
70 | ]) | |
71 | ||
72 | AS_IF([test "x$OCAMLFIND" = xno], | |
73 | [dnl | |
74 | AC_MSG_ERROR([A suitable OCaml findlib (the ocamlfind command) could not be found.]) | |
75 | ]) | |
76 | ||
77 | dnl these variables are substituted for in the code: this guarantees a default for them. | |
78 | AC_COCCI_RUNTIME_CMD([OCAMLFIND],[ocamlfind]) | |
79 | AC_COCCI_RUNTIME_CMD([OCAMLC],[ocamlc]) | |
80 | AC_COCCI_RUNTIME_CMD([OCAMLOPT],[ocamlopt]) | |
81 | AC_COCCI_RUNTIME_CMD([OCAMLDEP],[ocamldep]) | |
82 | AC_COCCI_RUNTIME_CMD([CAMLP4],[camlp4]) | |
83 | AC_COCCI_RUNTIME_CMD([CAMLP4O],[camlp4o]) | |
84 | ||
85 | AC_CACHE_SAVE | |
86 | ||
87 | ||
88 | dnl | |
89 | dnl Basic ocaml modules | |
90 | dnl | |
91 | ||
92 | AC_MSG_NOTICE([verifying basic ocaml modules]) | |
93 | ||
94 | dnl default dir with the bundled ocaml packages | |
95 | AC_COCCI_SET_EXTERNAL_DIR([$COCCI_SRCDIR/bundles]) | |
96 | ||
97 | dnl set some defaults | |
98 | dnl add a line for each package that is | |
99 | dnl configured via AC_CHECK_COCCI_EXTPKG | |
100 | dnl or AC_REQ_COCCI_EXTPKG | |
101 | AC_COCCI_INIT_PKG_EMPTY([sexplib]) | |
102 | AC_COCCI_INIT_PKG_EMPTY([menhirLib]) | |
103 | AC_COCCI_INIT_PKG_EMPTY([extlib]) | |
104 | AC_COCCI_INIT_PKG_EMPTY([dynlink]) | |
105 | AC_COCCI_INIT_PKG_EMPTY([pcre]) | |
106 | AC_COCCI_INIT_PKG_EMPTY([pycaml]) | |
107 | AC_COCCI_INIT_PKG_EMPTY([camlp4]) | |
108 | ||
109 | dnl required ocaml packages | |
110 | AC_MSG_NOTICE([the following OCaml packages should be provided by your ocaml installation]) | |
111 | AC_REQ_COCCI_STDPKG([unix]) | |
112 | AC_REQ_COCCI_STDPKG([bigarray]) | |
113 | AC_REQ_COCCI_STDPKG([num]) | |
114 | AC_REQ_COCCI_STDPKG([str]) | |
115 | AC_REQ_COCCI_STDPKG([threads]) | |
116 | ||
117 | dnl required modules (Some are available locally too) | |
118 | AC_REQ_COCCI_EXTPKG([dynlink]) | |
119 | AC_REQ_COCCI_EXTPKG([camlp4]) | |
120 | AC_REQ_COCCI_EXTPKG([sexplib]) | |
121 | AC_REQ_COCCI_EXTPKG([menhirLib]) | |
122 | AC_REQ_COCCI_EXTPKG([extlib]) | |
123 | ||
124 | ||
125 | AC_CACHE_SAVE | |
126 | ||
127 | ||
128 | dnl | |
129 | dnl Handling of optional features | |
130 | dnl | |
131 | ||
132 | AC_MSG_NOTICE([verifying optional features]) | |
133 | ||
134 | ||
135 | dnl menhir handling | |
136 | dnl variables: | |
137 | dnl with_menhir: whether or not menhir must be used | |
138 | AC_COCCI_TOOL([MENHIR],[menhir],[$COCCI_SRCDIR/setup/fake-menhir.sh menhir]) | |
139 | AS_IF([test "x$SUBSTITUTED_MENHIR" = xyes], | |
140 | [dnl | |
141 | AC_MSG_NOTICE([pregenerated parsers will be required as substitute for Menhir]) | |
142 | ]) | |
143 | ||
144 | ||
145 | dnl ocaml script handling | |
146 | dnl variables: | |
147 | dnl enable_ocaml: whether to enable ocaml scripts | |
148 | AC_ARG_ENABLE([ocaml], AS_HELP_STRING([--enable-ocaml], [enable ocaml scripting (default: auto)])) | |
149 | AS_IF([test "x$OCAML_PKG_dynlink" = xno], | |
150 | [dnl | |
151 | AS_IF([test -z "$enable_ocaml"], | |
152 | [dnl | |
153 | AC_SUBST([enable_ocaml],[no]) | |
154 | AC_MSG_NOTICE([ocaml scripting is disabled because the 'dynlink' package is not installed]) | |
155 | ], [test "x$enable_ocaml" != xno], | |
156 | [dnl | |
157 | AC_MSG_ERROR([the OCaml package dynlink is required for ocaml scripting]) | |
158 | ]) | |
159 | ]) | |
160 | ||
161 | dnl too old ocaml version, disable dynlink by default | |
162 | AS_IF([test "x$OCAMLATLEAST311" = xno], | |
163 | [dnl | |
164 | AC_SUBST([enable_ocaml],[no]) | |
165 | AC_MSG_NOTICE([ocaml scripting has been disabled because your OCaml version may not support dynamic linking properly]) | |
166 | ]) | |
167 | ||
168 | dnl scripting requirement on ocamlfind | |
169 | AS_IF([test -n "$SUBSTITUTED_OCAMLFIND"], | |
170 | [dnl | |
171 | AS_IF([test -z "$enable_ocaml"], | |
172 | [dnl this is perhaps a bit too strict | |
173 | AC_SUBST([enable_ocaml],[no]) | |
174 | AC_MSG_NOTICE([ocaml scripting is disabled because it depends on ocamlfind]) | |
175 | ], [test "x$enable_ocaml" != xno], | |
176 | [dnl | |
177 | AC_MSG_NOTICE([warning: ocamlfind is not found but may be required if ocaml scripts are used]) | |
178 | ]) | |
179 | ]) | |
180 | ||
181 | dnl scripting requirement on camlp4 | |
182 | AS_IF([test "x$CAMLP4" = xno], | |
183 | [dnl | |
184 | AS_IF([test -z "$enable_ocaml"], | |
185 | [dnl this is perhaps a bit too strict | |
186 | AC_SUBST([enable_ocaml],no) | |
187 | AC_MSG_NOTICE([ocaml scripting is disabled because it depends on camlp4]) | |
188 | ], [test "x$enable_ocaml" != xno], | |
189 | [dnl | |
190 | AC_MSG_NOTICE([warning: camlp4 is not found but may be required if ocaml scripts are used]) | |
191 | ]) | |
192 | ]) | |
193 | ||
194 | AS_IF([test "x$enable_ocaml" = xno], | |
195 | [dnl | |
196 | AC_COCCI_INIT_PKG_EMPTY([dynlink]) dnl prevent linking with it | |
197 | AC_SUBST(OCAMLCOCCI_MODULE,[No_prepare_ocamlcocci]) | |
198 | AC_SUBST(OCAMLCOCCI_FILE,[no_prepare_ocamlcocci.ml]) | |
199 | ], | |
200 | [dnl | |
201 | AC_SUBST([enable_ocaml],[yes]) | |
202 | AC_SUBST(OCAMLCOCCI_MODULE,[Yes_prepare_ocamlcocci]) | |
203 | AC_SUBST(OCAMLCOCCI_FILE,[yes_prepare_ocamlcocci.ml]) | |
204 | ]) | |
205 | ||
206 | ||
207 | dnl python handling | |
208 | dnl variables: | |
209 | dnl with_python: whether to enable the python feature (and what version) | |
210 | dnl OCAML_PKG_pycaml: if "local" use local pycaml package | |
211 | AC_ARG_VAR([PYTHON], [path to python when the version is determined automatically]) | |
212 | AC_ARG_ENABLE([python], [AS_HELP_STRING([--enable-python], [enable python scripting (yes/no) (default: auto)])]) | |
213 | AS_IF([test "x$enable_python" != xno], | |
214 | [dnl | |
215 | dnl an explicitly set --with-python disablees by default the global pycaml | |
216 | AS_IF([test -n "$enable_python" -a -z "$enable_pycaml"], | |
217 | [dnl if explicit python given: | |
218 | AC_MSG_NOTICE([skipped the selection of a global pycaml module because --enable-python is given explicitly but --enable-pycaml is not.]) | |
219 | AC_SUBST([enable_pycaml],[no]) | |
220 | ]) | |
221 | ||
222 | dnl sets "$PYVER" if python is available | |
223 | AC_COCCI_PYVER | |
224 | ||
225 | AS_IF([test -z "$PYVER"], | |
226 | [dnl PYVER undetermined | |
227 | AS_IF([test "x$enable_python" = xyes], | |
228 | [dnl | |
229 | AC_MSG_ERROR([python scripting is enabled explicitly but the version of python could not be determined]) | |
230 | ]) | |
231 | ], | |
232 | [dnl | |
233 | PKG_CHECK_MODULES([PYTHON], [python-$PYVER],[AC_SUBST(HAVE_PYTHON,[yes])],[AC_SUBST(HAVE_PYTHON,[no])]) | |
234 | ||
235 | AS_IF([test "x$HAVE_PYTHON" != xyes -a "x$enable_python" != xyes], | |
236 | [dnl fallback if the above failed | |
237 | AC_MSG_NOTICE([trying the default python version as fallback]) | |
238 | PKG_CHECK_MODULES([PYTHON], [python],[AC_SUBST(HAVE_PYTHON,[yes])],[AC_SUBST(HAVE_PYTHON,[no])]) | |
239 | ]) | |
240 | ]) | |
241 | ]) | |
242 | ||
243 | AS_IF([test -z "$enable_python"], | |
244 | [dnl | |
245 | AS_IF([test "x$HAVE_PYTHON" = xyes], | |
246 | [dnl | |
247 | AC_SUBST([enable_python],[yes]) | |
248 | ], | |
249 | [dnl | |
250 | AC_SUBST([enable_python],[no]) | |
251 | ]) | |
252 | ]) | |
253 | ||
254 | AS_IF([test "x$enable_python" != xno], | |
255 | [dnl | |
256 | AS_IF([test "x$HAVE_PYTHON" = xyes], | |
257 | [dnl | |
258 | AC_MSG_NOTICE([support for python scripts is enabled]) | |
259 | ], | |
260 | [dnl | |
261 | AC_MSG_ERROR([the python scripts feature is enabled but the pkg-config python library is not found]) | |
262 | ]) | |
263 | ||
264 | AC_REQ_COCCI_EXTPKG([pycaml]) | |
265 | AC_SUBST([PYCOCCI_MODULE], [Yes_pycocci]) | |
266 | AC_SUBST([PYCOCCI_FILE],[yes_pycocci.ml]) | |
267 | ], | |
268 | [dnl | |
269 | AC_COCCI_INIT_PKG_EMPTY([pycaml]) | |
270 | AC_SUBST([PYCOCCI_MODULE], [No_pycocci]) | |
271 | AC_SUBST([PYCOCCI_FILE],[no_pycocci.ml]) | |
272 | ]) | |
273 | ||
274 | ||
275 | dnl pcre handling | |
276 | dnl variables: | |
277 | dnl enable_pcre: whether to enable the pcre feature | |
278 | dnl OCAML_PKG_pcre: if "local" use str package | |
279 | AC_ARG_ENABLE([pcre-syntax], AS_HELP_STRING([--enable-pcre-syntax], [enable pcre regular expression syntax (default: auto)])) | |
280 | AS_IF([test "x$enable_pcre_syntax" != "xno"], | |
281 | [dnl | |
282 | PKG_CHECK_MODULES([PCRE], [libpcre],[AC_SUBST([HAVE_PCRE],[yes])],[AC_SUBST([HAVE_PCRE],[no])]) | |
283 | AS_IF([test -z "$enable_pcre_syntax" -a "x$HAVE_PCRE" != xyes], | |
284 | [dnl | |
285 | AC_SUBST([enable_pcre_syntax],[no]) | |
286 | ], | |
287 | [dnl | |
288 | AC_CHECK_COCCI_EXTPKG([pcre]) dnl will set $enable_pcre to 'yes', 'no', or 'local' | |
289 | enable_pcre_syntax=$enable_pcre | |
290 | ]) | |
291 | ]) | |
292 | ||
293 | AS_IF([test "x$enable_pcre_syntax" != xno], | |
294 | [dnl | |
295 | AS_IF([test "x$HAVE_PCRE" = xyes], | |
296 | [dnl | |
297 | AC_MSG_NOTICE([support for pcre syntax is enabled]) | |
298 | ], | |
299 | [dnl | |
300 | AC_MSG_ERROR([the pcre feature is enabled but the pkg-config libpcre library is not found]) | |
301 | ]) | |
302 | ||
303 | AC_SUBST([REGEXP_MODULE], [Regexp_pcre]) | |
304 | AC_SUBST([REGEXP_FILE], [regexp_pcre.ml]) | |
305 | ], | |
306 | [dnl | |
307 | AC_COCCI_INIT_PKG_EMPTY([pcre]) | |
308 | AC_SUBST([REGEXP_MODULE], [Regexp_str]) | |
309 | AC_SUBST([REGEXP_FILE], [regexp_str.ml]) | |
310 | ]) | |
311 | ||
312 | ||
313 | AC_CACHE_SAVE | |
314 | ||
315 | ||
316 | dnl obtain the value of $prefix | |
317 | AS_IF([test "$prefix" = "NONE"],[prefix=$ac_default_prefix]) | |
318 | ||
319 | ||
320 | dnl | |
321 | dnl backwards compatibility | |
322 | dnl | |
323 | ||
324 | dnl defines some variables needed by the Make infrastructure | |
325 | AC_SUBST(SHAREDIR,["${prefix}/share/coccinelle"]) | |
326 | ||
327 | AS_IF([test "x$enable_python" != xno], | |
328 | [dnl | |
329 | AC_SUBST(FEATURE_PYTHON,[1]) | |
330 | ], | |
331 | [dnl | |
332 | AC_SUBST(FEATURE_PYTHON,[0]) | |
333 | ]) | |
334 | ||
335 | AS_IF([test "x$enable_ocaml" != xno], | |
336 | [dnl | |
337 | AC_SUBST(FEATURE_OCAML,[1]) | |
338 | ], | |
339 | [dnl | |
340 | AC_SUBST(FEATURE_OCAML,[0]) | |
341 | ]) | |
342 | ||
343 | dnl dynlink stuff depending on the OCaml version and whether it is enabled | |
344 | AS_IF([test "x$OCAMLATLEAST311" = xyes -a "x$enable_ocaml" = xyes], | |
345 | [dnl | |
346 | AC_SUBST([DYNLINK_IS_NATIVE],[Dynlink.is_native]) | |
347 | ], | |
348 | [dnl | |
349 | AC_SUBST([DYNLINK_IS_NATIVE],[false]) | |
350 | ]) | |
351 | ||
352 | dnl in case of the compilation of the manual | |
353 | AC_COCCI_TOOL([PDFLATEX],[pdflatex],[$COCCI_SRCDIR/setup/fake-pdflatex.sh pdflatex]) | |
354 | ||
355 | ||
356 | dnl | |
357 | dnl determine the default make target | |
358 | dnl if ocamlopt is availabe, the default is both | |
359 | dnl the bytecode version and the optimized version | |
360 | dnl of coccinelle. | |
361 | dnl | |
362 | ||
363 | AC_ARG_ENABLE([release], [AS_HELP_STRING([--enable-release], [build with a release configuration (yes,no, default: no)])]) | |
364 | ||
365 | AS_IF([test "x$OCAMLOPT" = xno], | |
366 | [dnl | |
367 | AS_IF([test "x$enable_release" = xyes], | |
368 | [dnl | |
369 | AC_MSG_ERROR([a release build is requested, but ocamlopt is not available]) | |
370 | ]) | |
371 | ||
372 | AC_SUBST([enable_release],[no]) | |
373 | ]) | |
374 | ||
375 | AS_IF([test "x$OCAMLVERSION" = x3.11.2 -a "x$enable_release" != xyes], | |
376 | [dnl the optimized version may not be buildable with ocaml 3.11.2 (know bug), hence disable it by default | |
377 | AC_MSG_NOTICE([the optimized version of coccinelle will not be build by default due to OCaml version $OCAMLVERSION and --enable-build-all is not given to override this decision]) | |
378 | AC_SUBST([enable_release],[no]) | |
379 | ]) | |
380 | ||
381 | AS_IF([test -z "$enable_release"], | |
382 | [dnl | |
383 | AC_MSG_NOTICE([choosing the development Makefile configuration because the release configuration is not explicitly requested.]) | |
384 | AC_SUBST([enable_release], [no]) | |
385 | ]) | |
386 | ||
387 | AS_IF([test "x$enable_release" = xyes], | |
388 | [dnl include the optimized version by default | |
389 | AC_SUBST([MAKETARGET_ALL], [all-release]) | |
390 | ], [test "x$enable_release" = xno], | |
391 | [dnl otherwise, exclude the optimized version | |
392 | AC_SUBST([MAKETARGET_ALL], [all-dev]) | |
393 | ], | |
394 | [dnl custom target given | |
395 | AC_SUBST([MAKETARGET_ALL], ["$enable_release"]) | |
396 | ]) | |
397 | ||
398 | dnl which spatch will be constructed | |
399 | AS_IF([test "x$enable_release" != xno],[SPATCHNAME=spatch.opt],[SPATCHNAME=spatch]) | |
400 | ||
401 | ||
402 | dnl | |
403 | dnl generating configuration | |
404 | dnl | |
405 | ||
406 | AC_CONFIG_FILES([Makefile.config]) | |
407 | AC_CONFIG_FILES([version.ml]) | |
408 | AC_CONFIG_FILES([commons/commands.ml]) | |
409 | AC_CONFIG_FILES([globals/config.ml]) | |
410 | AC_CONFIG_FILES([globals/regexp.ml]) | |
411 | AC_CONFIG_FILES([python/pycocci.ml]) | |
412 | AC_CONFIG_FILES([ocaml/prepare_ocamlcocci.ml]) | |
413 | AC_CONFIG_FILES([scripts/spatch.sh]) | |
414 | AC_CONFIG_FILES([docs/spatch.1]) | |
415 | ||
416 | AC_OUTPUT | |
417 | ||
418 | AC_MSG_NOTICE([configuration completed]) | |
419 | ||
420 | cat << EOF | |
421 | ------------------------------------------------------------------------------ | |
422 | Summary | |
423 | ||
424 | findlib: $OCAMLFIND | |
425 | menhir: $MENHIR | |
426 | menhirLib module: $OCAML_PKG_menhirLib | |
427 | ||
428 | ocaml scripting: $enable_ocaml | |
429 | python scripting: $enable_python | |
430 | pycaml module: $enable_pycaml | |
431 | ||
432 | pcre regexes: $enable_pcre_syntax | |
433 | pcre module: $enable_pcre | |
434 | pcre library: $HAVE_PCRE | |
435 | ||
436 | release config: $enable_release | |
437 | ||
438 | EOF | |
439 | ||
440 | cat << EOF | |
441 | ------------------------------------------------------------------------------ | |
442 | Coccinelle can now be compiled and installed. | |
443 | ||
444 | ||
445 | If you compile coccinelle again after source code changes or | |
446 | configuration changes, you may need to run first: | |
447 | \$ make clean | |
448 | ||
449 | To compile coccinelle, run: | |
450 | \$ make all | |
451 | ||
452 | To install coccinelle, run: | |
453 | \$ make install | |
454 | ||
455 | Then, to test coccinelle run for example: | |
456 | \$ $SPATCHNAME -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c | |
457 | EOF | |
458 | ||
459 | if test "x$enable_python" != "xno"; then | |
460 | cat << EOF | |
461 | ------------------------------------------------------------------------------ | |
462 | You may need to set some environment variables so that the python | |
463 | libraries are found. The frontend 'spatch' sets the following variables: | |
464 | ||
465 | \$ export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib | |
466 | \$ export PYTHONPATH=\$PYTHONPATH:$prefix/share/coccinelle/python | |
467 | ||
468 | EOF | |
469 | fi | |
470 | ||
471 | cat << EOF | |
472 | ------------------------------------------------------------------------------ | |
473 | EOF |