1 dnl run 'autoreconf' to obtain aclocal.m4, and update configure and setup/pkg.m4
2 dnl run 'automake -acf' to update setup/{install-sh,missing}
4 dnl standard initialization (we only use autoconf not automake)
6 AC_INIT([coccinelle], m4_esyscmd([cat ./version | tr -d '\n']), [cocci@diku.dk], [], [http://coccinelle.lip6.fr/])
7 AC_CONFIG_MACRO_DIR([setup])
8 AC_CONFIG_AUX_DIR([setup])
9 AC_SUBST([CONFIGURE_FLAGS], ["$*"])
10 AC_SUBST([COCCI_VERSION], ["$PACKAGE_VERSION"])
11 AC_SUBST([COCCI_SRCDIR], ["$(pwd)"])
12 AC_MSG_NOTICE([configuring coccinelle $COCCI_VERSION in $COCCI_SRCDIR])
15 AC_CONFIG_SRCDIR([cocci.ml]) dnl this file must be present in our src directory
18 dnl reminder that this configure depends on macros generated by aclocal
19 AC_MSG_NOTICE([this configure program uses pkg-config m4 macros])
20 AC_MSG_NOTICE([this configure program uses ocaml m4 macros (see setup/ocaml.m4)])
21 AC_MSG_NOTICE([this configure program uses custom m4 macros (see setup/cocci.m4)])
22 AC_MSG_NOTICE([some fake substitutions for required but unavailable programs may be used (see setup/fake*)])
26 dnl Note: the conditionals in this configure script are tricky.
27 dnl The approach taken here is that many tools can be enabled/disabled
28 dnl and paths can be given explicitly via commandline parameters or
29 dnl environment variables.
37 AC_MSG_NOTICE([verifying basic tools])
42 AC_PATH_PROG([TAR],[tar])
43 AC_PATH_PROG([PATCH],[patch])
45 dnl ensures that INSTALL points to an absolute install-sh when that one is configured.
46 AS_IF([test "$INSTALL" = "setup/install-sh -c" -o "$INSTALL" = "./setup-install-sh -c"],
48 AC_SUBST([INSTALL], ["$COCCI_SRCDIR/$INSTALL"])
51 dnl the same for MKDIR_P
52 AS_IF([test "$MKDIR_P" = "setup/install-sh -c -d" -o "$INSTALL" = "./setup-install-sh -c -d"],
54 AC_SUBST([MKDIR_P], ["$COCCI_SRCDIR/$MKDIR_P"])
57 dnl patchelf is an optional dependency and in principle not used for building coccinelle
58 AC_PATH_PROG([PATCHELF],[patchelf])
60 dnl pkg config is required, but we have an alternative script for it
61 AC_COCCI_TOOL([PKG_CONFIG],[pkg-config])
62 AS_IF([test "x$PKG_CONFIG" = xno],
63 [dnl no specific pkg-config configured
64 AC_SUBST([PKG_CONFIG_ORIG],[pkg-config])
66 [dnl a specific pkg-config configured
67 AC_SUBST([PKG_CONFIG_ORIG],[$PKG_CONFIG])
70 dnl always use the wrapper around pkg-config
71 AC_SUBST([PKG_CONFIG],["$COCCI_SRCDIR/setup/fake-subst.sh $PKG_CONFIG_ORIG"])
74 dnl ocaml compiler configuration
76 AC_CHECK_OCAMLVERSION([OCAMLATLEAST310],[3.10])
77 AC_CHECK_OCAMLVERSION([OCAMLATLEAST311],[3.11])
78 AC_SUBST([OCAMLCORIG],["$OCAMLC"])
80 AS_IF([test "x$OCAMLC" = xno -o "x$OCAMLDEP" = xno -o "x$OCAMLDOC" = xno -o "x$OCAMLMKLIB" = xno],
82 AC_MSG_ERROR([You must install the OCaml compiler])
84 AS_IF([test "x$OCAMLATLEAST310" = xno],[AC_MSG_NOTICE([a more recent OCaml installation may be required])])
88 AC_COCCI_TOOL([OCAMLLEX],[ocamllex],[])
89 AC_COCCI_TOOL([OCAMLYACC],[ocamlyacc],[])
90 AC_COCCI_TOOL([OCAMLFIND],[ocamlfind],[$COCCI_SRCDIR/setup/fake-subst.sh ocamlfind])
91 AC_COCCI_TOOL([OCAMLPROF],[ocamlprof],[])
93 dnl enforce ocaml tool requirements
94 AS_IF([test "x$OCAMLLEX" = xno],
96 AC_MSG_ERROR([the OCaml Lexer needs to be installed (the ocamllex command). It should be part of your OCaml distribution.])
99 AS_IF([test "x$OCAMLYACC" = xno],
101 AC_MSG_ERROR([The OCaml parser generated needs to be installed (the ocamlyacc command). It should be part of your OCaml distribution.])
104 AS_IF([test "x$OCAMLFIND" = xno],
106 AC_MSG_ERROR([A suitable OCaml findlib (the ocamlfind command) could not be found.])
109 dnl these runtime commands can also be passed as runtime flags to spatch.
110 AC_COCCI_RUNTIME_CMD([OCAMLFIND],[ocamlfind])
111 AC_COCCI_RUNTIME_CMD([OCAMLC],[ocamlc])
112 AC_COCCI_RUNTIME_CMD([OCAMLOPT],[ocamlopt])
113 AC_COCCI_RUNTIME_CMD([OCAMLDEP],[ocamldep])
114 AC_COCCI_RUNTIME_CMD([CAMLP4],[camlp4])
115 AC_COCCI_RUNTIME_CMD([CAMLP4O],[camlp4o])
121 dnl Basic ocaml modules
124 AC_MSG_NOTICE([verifying basic ocaml modules])
126 dnl default dir with the bundled ocaml packages
127 AC_COCCI_SET_EXTERNAL_DIR([$COCCI_SRCDIR/bundles])
129 dnl set some defaults
130 dnl add a line for each package that is
131 dnl configured via AC_CHECK_COCCI_EXTPKG
132 dnl or AC_REQ_COCCI_EXTPKG
133 AC_COCCI_INIT_PKG_EMPTY([menhirLib])
134 AC_COCCI_INIT_PKG_EMPTY([dynlink])
135 AC_COCCI_INIT_PKG_EMPTY([pcre])
136 AC_COCCI_INIT_PKG_EMPTY([pycaml])
137 AC_COCCI_INIT_PKG_EMPTY([camlp4])
139 dnl required ocaml packages
140 AC_MSG_NOTICE([the following OCaml packages should be provided by your ocaml installation])
141 AC_REQ_COCCI_STDPKG([unix])
142 AC_REQ_COCCI_STDPKG([bigarray])
143 AC_REQ_COCCI_STDPKG([num])
144 AC_REQ_COCCI_STDPKG([str])
146 dnl required modules (Some are available locally too)
147 AC_REQ_COCCI_EXTPKG([dynlink])
148 AC_REQ_COCCI_EXTPKG([camlp4])
149 AC_REQ_COCCI_EXTPKG([menhirLib])
156 dnl Handling of optional features
159 AC_MSG_NOTICE([verifying optional features])
161 dnl test if the optimized version of dynlink is available
162 AS_IF([test "x$OCAML_PKG_dynlink" != xno -a -f "$PATH_dynlink/dynlink.cmxa"],
164 AC_SUBST([OPTIMIZED_dynlink], [yes])
167 AC_SUBST([OPTIMIZED_dynlink], [no])
173 dnl with_menhir: whether or not menhir must be used
174 AC_COCCI_TOOL([MENHIR],[menhir],[$COCCI_SRCDIR/setup/fake-menhir.sh menhir])
175 AS_IF([test "x$SUBSTITUTED_MENHIR" = xyes],
177 AC_MSG_NOTICE([pregenerated parsers will be required as substitute for Menhir])
181 dnl ocaml script handling
183 dnl enable_ocaml: whether to enable ocaml scripts
184 AC_ARG_ENABLE([ocaml], AS_HELP_STRING([--enable-ocaml], [enable ocaml scripting (default: auto)]))
185 AS_IF([test "x$OCAML_PKG_dynlink" = xno],
187 AS_IF([test -z "$enable_ocaml"],
189 AC_SUBST([enable_ocaml], [no])
190 AC_MSG_NOTICE([ocaml scripting is disabled because the 'dynlink' package is not installed])
191 ], [test "x$enable_ocaml" != xno],
193 AC_MSG_ERROR([the OCaml package dynlink is required for ocaml scripting])
197 dnl too old ocaml version, disable dynlink by default
198 AS_IF([test "x$OCAMLATLEAST311" = xno],
200 AS_IF([test -z "$enable_ocaml"],
202 AC_SUBST([enable_ocaml], [no])
203 AC_MSG_NOTICE([ocaml scripting has been disabled by default because your OCaml version may not support dynamic linking properly])
204 ], [test "x$enable_ocaml" = xyes],
206 AC_MSG_NOTICE([warning: your ocaml version may be too old for dynamic linking, thus ocaml scripting may not work])
210 dnl no optimized version, disable dynlink by default
211 AS_IF([test "x$OPTIMIZED_dynlink" = xno],
213 AS_IF([test -z "$enable_ocaml"],
215 AC_SUBST([enable_ocaml], [no])
216 AC_MSG_NOTICE([ocaml scripting has been disabled by default because the optimized version of dynlink is not available])
217 ], [test "x$enable_ocaml" = xyes],
219 AC_MSG_NOTICE([warning: the optimized version of dynlink is not available, thus ocaml scripting may not work])
223 dnl scripting requirement on ocamlfind
224 AS_IF([test -n "$SUBSTITUTED_OCAMLFIND"],
226 AS_IF([test -z "$enable_ocaml"],
227 [dnl this is perhaps a bit too strict
228 AC_SUBST([enable_ocaml],[no])
229 AC_MSG_NOTICE([ocaml scripting is disabled because it depends on ocamlfind])
230 ], [test "x$enable_ocaml" != xno],
232 AC_MSG_NOTICE([warning: ocamlfind is not found but may be required when ocaml scripts are used])
236 dnl scripting requirement on camlp4
237 AS_IF([test "x$CAMLP4" = xno],
239 AS_IF([test -z "$enable_ocaml"],
240 [dnl this is perhaps a bit too strict
241 AC_SUBST([enable_ocaml],no)
242 AC_MSG_NOTICE([ocaml scripting is disabled because it requires camlp4 which is not available])
243 ], [test "x$enable_ocaml" != xno],
245 AC_MSG_NOTICE([warning: camlp4 is not found but may be required when ocaml scripts are used])
249 AS_IF([test "x$enable_ocaml" = xno],
251 AC_COCCI_INIT_PKG_EMPTY([dynlink]) dnl prevent linking with it
252 AC_SUBST(OCAMLCOCCI_MODULE, [No_prepare_ocamlcocci])
253 AC_SUBST(OCAMLCOCCI_FILE, [no_prepare_ocamlcocci.ml])
256 AC_SUBST([enable_ocaml], [yes])
257 AC_SUBST(OCAMLCOCCI_MODULE, [Yes_prepare_ocamlcocci])
258 AC_SUBST(OCAMLCOCCI_FILE, [yes_prepare_ocamlcocci.ml])
264 dnl with_python: whether to enable the python feature (and what version)
265 dnl OCAML_PKG_pycaml: if "local" use local pycaml package
266 AC_ARG_VAR([PYTHON], [path to python when the version is determined automatically])
267 AC_ARG_ENABLE([python], [AS_HELP_STRING([--enable-python], [enable python scripting (yes/no) (default: auto)])])
268 AS_IF([test "x$enable_python" != xno],
270 dnl an explicitly set --with-python disables the global pycaml by default
271 dnl set --enable-pycaml if it is clear that the installed pycaml library
272 dnl is consistent with the chosen python version
273 AS_IF([test -n "$enable_python" -a -z "$enable_pycaml"],
274 [dnl if explicit python given:
275 AC_MSG_NOTICE([skipped the selection of a global pycaml module because --enable-python is given explicitly but --enable-pycaml is not.])
276 AC_SUBST([enable_pycaml], [no])
279 dnl sets "$PYVER" if python is available
282 AS_IF([test -z "$PYVER"],
283 [dnl PYVER undetermined
284 AS_IF([test "x$enable_python" = xyes],
286 AC_MSG_ERROR([python scripting is enabled explicitly but the version of python could not be determined])
290 AC_MSG_NOTICE([looking for the corresponding python library])
291 PKG_CHECK_MODULES([PYTHON], [python-$PYVER],[AC_SUBST(HAVE_PYTHON,[yes])],[AC_SUBST(HAVE_PYTHON,[no])])
293 AS_IF([test "x$HAVE_PYTHON" != xyes -a "x$enable_python" != xyes],
294 [dnl fallback if the above failed
295 AC_MSG_NOTICE([trying the default python library as fallback])
296 PKG_CHECK_MODULES([PYTHON], [python],[AC_SUBST(HAVE_PYTHON,[yes])],[AC_SUBST(HAVE_PYTHON,[no])])
301 AS_IF([test -z "$enable_python"],
303 AS_IF([test "x$HAVE_PYTHON" = xyes],
305 AC_SUBST([enable_python], [yes])
308 AC_SUBST([enable_python], [no])
312 AS_IF([test "x$enable_python" != xno],
314 AS_IF([test "x$HAVE_PYTHON" = xyes],
316 AC_MSG_NOTICE([support for python scripts is enabled])
319 AC_MSG_ERROR([the python scripts feature is enabled but the pkg-config python library is not found])
322 AC_REQ_COCCI_EXTPKG([pycaml])
323 AC_SUBST([PYCOCCI_MODULE], [Yes_pycocci])
324 AC_SUBST([PYCOCCI_FILE],[yes_pycocci.ml])
327 AC_COCCI_INIT_PKG_EMPTY([pycaml])
328 AC_SUBST([PYCOCCI_MODULE], [No_pycocci])
329 AC_SUBST([PYCOCCI_FILE],[no_pycocci.ml])
335 dnl enable_pcre: whether to enable the pcre feature
336 dnl OCAML_PKG_pcre: if "local" use str package
337 AC_ARG_ENABLE([pcre-syntax], AS_HELP_STRING([--enable-pcre-syntax], [enable pcre regular expression syntax (default: auto)]))
338 AS_IF([test "x$enable_pcre_syntax" != "xno"],
340 PKG_CHECK_MODULES([PCRE], [libpcre],[AC_SUBST([HAVE_PCRE],[yes])],[AC_SUBST([HAVE_PCRE],[no])])
341 AS_IF([test -z "$enable_pcre_syntax" -a "x$HAVE_PCRE" != xyes],
343 AC_SUBST([enable_pcre_syntax], [no])
346 AC_CHECK_COCCI_EXTPKG([pcre]) dnl will set $enable_pcre to 'yes', 'no', or 'local'
347 enable_pcre_syntax=$enable_pcre
351 AS_IF([test "x$enable_pcre_syntax" != xno],
353 AS_IF([test "x$HAVE_PCRE" = xyes],
355 AC_MSG_NOTICE([support for pcre syntax is enabled])
358 AC_MSG_ERROR([the pcre feature is enabled but the pkg-config libpcre library is not found])
361 AC_SUBST([REGEXP_MODULE], [Regexp_pcre])
362 AC_SUBST([REGEXP_FILE], [regexp_pcre.ml])
365 AC_COCCI_INIT_PKG_EMPTY([pcre])
366 AC_SUBST([REGEXP_MODULE], [Regexp_str])
367 AC_SUBST([REGEXP_FILE], [regexp_str.ml])
374 dnl obtain the value of $prefix
375 AS_IF([test "$prefix" = "NONE"],[prefix=$ac_default_prefix])
379 dnl backwards compatibility
382 dnl defines some variables needed by the Make infrastructure
383 AC_SUBST(SHAREDIR,["${prefix}/share/coccinelle"])
385 AS_IF([test "x$enable_python" != xno],
387 AC_SUBST(FEATURE_PYTHON, [1])
390 AC_SUBST(FEATURE_PYTHON, [0])
393 AS_IF([test "x$enable_ocaml" != xno],
395 AC_SUBST(FEATURE_OCAML, [1])
398 AC_SUBST(FEATURE_OCAML, [0])
401 dnl dynlink stuff depending on the OCaml version and whether it is enabled
402 AS_IF([test "x$OCAMLATLEAST311" = xyes -a "x$enable_ocaml" = xyes -a "x$OCAMLOPT" != xno],
404 AC_SUBST([DYNLINK_IS_NATIVE], [Dynlink.is_native])
407 AC_SUBST([DYNLINK_IS_NATIVE], [false])
410 dnl in case of the compilation of the manual
411 AC_COCCI_TOOL([PDFLATEX],[pdflatex],[$COCCI_SRCDIR/setup/fake-pdflatex.sh pdflatex])
414 dnl determine release configuration
415 AC_ARG_ENABLE([release], [AS_HELP_STRING([--enable-release], [build with a release configuration (yes,no,profile default: no)])])
416 AS_IF([test -z "$enable_release"],
418 AC_MSG_NOTICE([choosing the development Makefile configuration because the release configuration is not explicitly requested.])
419 AC_SUBST([enable_release], [no])
422 AC_SUBST([MODULES_profiling],[])
423 AS_IF([test "x$enable_release" = xyes],
424 [dnl set the default target to 'release' when enable_release is given
425 AC_SUBST([MAKETARGET_ALL], [all-release])
426 ], [test "x$enable_release" = xno],
427 [dnl otherwise, set the default target to 'dev'
428 AC_SUBST([MAKETARGET_ALL], [all-dev])
429 ], [test "x$enable_release" = xprofile],
430 [dnl selected profiling
431 AS_IF([test -z "$OCAMLPROF" -o "x$OCAMLPROF" = xno],
433 AC_MSG_ERROR([ocamlprof is required for profiling, but is absent.])
436 dnl configuration-time overrides for profiling
437 AC_SUBST([MAKETARGET_ALL], [all-dev])
438 AC_SUBST([OCAMLC], ["$COCCI_SRCDIR/setup/wrapper-ocamlcp.sh $OCAMLCORIG $OCAMLPROF"])
439 AC_SUBST([MODULES_profiling], [profiling.cmo])
440 AC_MSG_NOTICE([configured coccinelle for profiling])
442 [dnl custom target given
443 AC_SUBST([MAKETARGET_ALL], ["$enable_release"])
446 dnl determine whether to build the optimizing version
447 AC_ARG_ENABLE([opt], [AS_HELP_STRING([--enable-opt], [build an optimized spatch (yes,no, default: auto)])])
448 AS_IF([test "x$OCAMLOPT" = xno -a "x$enable_opt" != xno],
450 AS_IF([test -n "$enable_release" -a "x$enable_release" != xyes -a "x$enable_release" != xno],
452 AC_MSG_NOTICE([warning: ensure that make target $enable_release does not depend on the unavailable ocamlopt])
453 ], [test "x$enable_opt" = xyes],
455 AC_MSG_ERROR([the optimized version of coccinelle is requested explicitly, but ocamlopt is absent])
458 AC_MSG_NOTICE([the optimized version of coccinelle will not be build because ocamlopt is not present])
459 AC_SUBST([enable_opt], [no])
463 AS_IF([test "x$OCAMLVERSION" = x3.11.2 -a -z "$enable_opt"],
464 [dnl the optimized version may not be buildable with ocaml 3.11.2 (know bug), hence disable it by default
465 AC_MSG_NOTICE([the optimized version of coccinelle will not be build by default due to OCaml version $OCAMLVERSION])
466 AC_SUBST([enable_opt], [no])
469 dnl disable the optimized target when dynlinking is enabled but the optimized version of dynlink is not available
470 AS_IF([test "x$OPTIMIZED_dynlink" = xno -a "x$enable_ocaml" = xyes],
472 AS_IF([test -z "$enable_opt"],
474 AC_MSG_NOTICE([the optimized version of coccinelle will not be build by default because ocaml scripting is enabled but the required optimized dynlink package is not present])
475 AC_SUBST([enable_opt], [no])
476 ], [test "x$enable_opt" = xyes],
478 AC_MSG_ERROR([the optimized version of coccinelle in combination with ocaml scripting requires the optimized version of the dynlik package, which is not present])
482 dnl set the default enable-opt setting
483 AS_IF([test -z "$enable_opt"],
485 AS_IF([test "x$enable_release" = xyes -o "x$enable_release" = xno],
487 AC_SUBST([enable_opt], ["$enable_release"])
491 dnl variables depending on whether we build the optimized spatch
492 AS_IF([test "x$enable_opt" = xyes],
493 [dnl default target for the optimized version
494 AC_SUBST([SPATCHNAME], [spatch.opt])
495 AC_SUBST([MAKETARGET_SPATCH], [opt-only])
497 [dnl default target for the bytecode version
498 AC_SUBST([SPATCHNAME], [spatch])
499 AC_SUBST([MAKETARGET_SPATCH], [byte-only])
503 dnl ocamlbuild handling
504 AC_ARG_ENABLE([ocamlbuild], AS_HELP_STRING([--enable-ocamlbuild], [enable ocamlbuild support (default: no)]))
505 AS_IF([test "x$enable_ocamlbuild" = xyes],
506 [dnl ocamlbuild support requested
507 AS_IF([test -z "$OCAMLBUILD" -o "x$OCAMLBUILD" = xno],
509 AC_MSG_ERROR([Ocamlbuild is required but is not installed.])
512 AC_SUBST([FEATURE_OCAMLBUILD], [yes])
514 [dnl default: disable ocamlbuild support
515 AC_SUBST([FEATURE_OCAMLBUILD], [ ])
520 dnl generating configuration
527 globals/config.ml globals/regexp.ml python/pycocci.ml
528 ocaml/prepare_ocamlcocci.ml
538 AC_MSG_NOTICE([configuration completed])
541 ------------------------------------------------------------------------------
544 configure flags: $CONFIGURE_FLAGS
545 findlib: $OCAMLFIND (an actual version is strongly recommended)
546 menhir: $MENHIR (should be an optional tool)
547 menhirLib module: $enable_menhirLib (for local package use --disable-menhirLib)
549 ocaml scripting: $enable_ocaml (overridable with --enable-ocaml)
550 python scripting: $enable_python (overridable with --enable-python)
551 pycaml module: $enable_pycaml (for local package use --disable-pycaml)
553 pcre regexes: $enable_pcre_syntax (overridable with --enable-pcre-syntax)
554 pcre module: $enable_pcre (for local package use --disable-pcre)
555 pcre library: $HAVE_PCRE (requires the dev version of libpcre)
557 release config: $enable_release (strongly recommended to be 'yes', overridable with --enable-release)
558 optimized spatch: $enable_opt (overridable with --disable-opt)
560 ------------------------------------------------------------------------------
561 Coccinelle can now be compiled and installed.
564 If you compile coccinelle again after source code changes or
565 configuration changes, you may need to run first:
568 To compile coccinelle, run:
571 To install coccinelle, run:
574 Then, to test coccinelle, run for example:
575 \$ spatch -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c
577 Or when coccinelle is not installed yet:
578 \$ COCCINELLE_HOME=$(pwd) ./scripts/spatch -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c
581 if test "x$enable_python" != "xno"; then
583 ------------------------------------------------------------------------------
584 You may need to set some environment variables so that the python
585 libraries are found. The frontend 'spatch' sets the following variables:
587 \$ export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib
588 \$ export PYTHONPATH=\$PYTHONPATH:$prefix/share/coccinelle/python
594 ------------------------------------------------------------------------------