dnl run 'autoreconf' to obtain aclocal.m4, and update configure and setup/pkg.m4 dnl run 'automake -acf' to update setup/{install-sh,missing} dnl standard initialization (we only use autoconf not automake) AC_PREREQ([2.68]) AC_INIT([coccinelle], m4_esyscmd([cat ./version | tr -d '\n']), [cocci@diku.dk], [], [http://coccinelle.lip6.fr/]) AC_CONFIG_MACRO_DIR([setup]) AC_CONFIG_AUX_DIR([setup]) AC_SUBST([CONFIGURE_FLAGS], ["$*"]) AC_SUBST([COCCI_VERSION], ["$PACKAGE_VERSION"]) AC_SUBST([COCCI_SRCDIR], ["$(pwd)"]) AC_MSG_NOTICE([configuring coccinelle $COCCI_VERSION in $COCCI_SRCDIR]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([cocci.ml]) dnl this file must be present in our src directory AC_COCCI_CONFVERSION dnl reminder that this configure depends on macros generated by aclocal AC_MSG_NOTICE([this configure program uses pkg-config m4 macros]) AC_MSG_NOTICE([this configure program uses ocaml m4 macros (see setup/ocaml.m4)]) AC_MSG_NOTICE([this configure program uses custom m4 macros (see setup/cocci.m4)]) AC_MSG_NOTICE([some fake substitutions for required but unavailable programs may be used (see setup/fake*)]) dnl dnl Note: the conditionals in this configure script are tricky. dnl The approach taken here is that many tools can be enabled/disabled dnl and paths can be given explicitly via commandline parameters or dnl environment variables. dnl dnl dnl Basic tools dnl AC_MSG_NOTICE([verifying basic tools]) AC_PROG_INSTALL AC_PROG_MKDIR_P AC_PROG_CPP AC_PATH_PROG([TAR],[tar]) AC_PATH_PROG([PATCH],[patch]) dnl ensures that INSTALL points to an absolute install-sh when that one is configured. AS_IF([test "$INSTALL" = "setup/install-sh -c" -o "$INSTALL" = "./setup-install-sh -c"], [dnl AC_SUBST([INSTALL], ["$COCCI_SRCDIR/$INSTALL"]) ]) dnl the same for MKDIR_P AS_IF([test "$MKDIR_P" = "setup/install-sh -c -d" -o "$INSTALL" = "./setup-install-sh -c -d"], [dnl AC_SUBST([MKDIR_P], ["$COCCI_SRCDIR/$MKDIR_P"]) ]) dnl patchelf is an optional dependency and in principle not used for building coccinelle AC_PATH_PROG([PATCHELF],[patchelf]) dnl pkg config is required, but we have an alternative script for it AC_COCCI_TOOL([PKG_CONFIG],[pkg-config]) AS_IF([test "x$PKG_CONFIG" = xno], [dnl no specific pkg-config configured AC_SUBST([PKG_CONFIG_ORIG],[pkg-config]) ], [dnl a specific pkg-config configured AC_SUBST([PKG_CONFIG_ORIG],[$PKG_CONFIG]) ]) dnl always use the wrapper around pkg-config AC_SUBST([PKG_CONFIG],["$COCCI_SRCDIR/setup/fake-subst.sh $PKG_CONFIG_ORIG"]) dnl ocaml compiler configuration AC_PROG_OCAML AC_CHECK_OCAMLVERSION([OCAMLATLEAST310],[3.10]) AC_CHECK_OCAMLVERSION([OCAMLATLEAST311],[3.11]) AC_SUBST([OCAMLCORIG],["$OCAMLC"]) AS_IF([test "x$OCAMLC" = xno -o "x$OCAMLDEP" = xno -o "x$OCAMLDOC" = xno -o "x$OCAMLMKLIB" = xno], [dnl AC_MSG_ERROR([You must install the OCaml compiler]) ]) AS_IF([test "x$OCAMLATLEAST310" = xno],[AC_MSG_NOTICE([a more recent OCaml installation may be required])]) dnl ocaml tools AC_PROG_CAMLP4 AC_COCCI_TOOL([OCAMLLEX],[ocamllex],[]) AC_COCCI_TOOL([OCAMLYACC],[ocamlyacc],[]) AC_COCCI_TOOL([OCAMLFIND],[ocamlfind],[$COCCI_SRCDIR/setup/fake-subst.sh ocamlfind]) AC_COCCI_TOOL([OCAMLPROF],[ocamlprof],[]) dnl enforce ocaml tool requirements AS_IF([test "x$OCAMLLEX" = xno], [dnl AC_MSG_ERROR([the OCaml Lexer needs to be installed (the ocamllex command). It should be part of your OCaml distribution.]) ]) AS_IF([test "x$OCAMLYACC" = xno], [dnl AC_MSG_ERROR([The OCaml parser generated needs to be installed (the ocamlyacc command). It should be part of your OCaml distribution.]) ]) AS_IF([test "x$OCAMLFIND" = xno], [dnl AC_MSG_ERROR([A suitable OCaml findlib (the ocamlfind command) could not be found.]) ]) dnl these runtime commands can also be passed as runtime flags to spatch. AC_COCCI_RUNTIME_CMD([OCAMLFIND],[ocamlfind]) AC_COCCI_RUNTIME_CMD([OCAMLC],[ocamlc]) AC_COCCI_RUNTIME_CMD([OCAMLOPT],[ocamlopt]) AC_COCCI_RUNTIME_CMD([OCAMLDEP],[ocamldep]) AC_COCCI_RUNTIME_CMD([CAMLP4],[camlp4]) AC_COCCI_RUNTIME_CMD([CAMLP4O],[camlp4o]) dnl AC_CACHE_SAVE dnl dnl Basic ocaml modules dnl AC_MSG_NOTICE([verifying basic ocaml modules]) dnl default dir with the bundled ocaml packages AC_COCCI_SET_EXTERNAL_DIR([$COCCI_SRCDIR/bundles]) dnl set some defaults dnl add a line for each package that is dnl configured via AC_CHECK_COCCI_EXTPKG dnl or AC_REQ_COCCI_EXTPKG AC_COCCI_INIT_PKG_EMPTY([menhirLib]) AC_COCCI_INIT_PKG_EMPTY([dynlink]) AC_COCCI_INIT_PKG_EMPTY([pcre]) AC_COCCI_INIT_PKG_EMPTY([pycaml]) AC_COCCI_INIT_PKG_EMPTY([camlp4]) dnl required ocaml packages AC_MSG_NOTICE([the following OCaml packages should be provided by your ocaml installation]) AC_REQ_COCCI_STDPKG([unix]) AC_REQ_COCCI_STDPKG([bigarray]) AC_REQ_COCCI_STDPKG([num]) AC_REQ_COCCI_STDPKG([str]) dnl required modules (Some are available locally too) AC_REQ_COCCI_EXTPKG([dynlink]) AC_REQ_COCCI_EXTPKG([camlp4]) AC_REQ_COCCI_EXTPKG([menhirLib]) dnl AC_CACHE_SAVE dnl dnl Handling of optional features dnl AC_MSG_NOTICE([verifying optional features]) dnl test if the optimized version of dynlink is available AS_IF([test "x$OCAML_PKG_dynlink" != xno -a -f "$PATH_dynlink/dynlink.cmxa"], [dnl yes AC_SUBST([OPTIMIZED_dynlink], [yes]) ], [dnl no AC_SUBST([OPTIMIZED_dynlink], [no]) ]) dnl menhir handling dnl variables: dnl with_menhir: whether or not menhir must be used AC_COCCI_TOOL([MENHIR],[menhir],[$COCCI_SRCDIR/setup/fake-menhir.sh menhir]) AS_IF([test "x$SUBSTITUTED_MENHIR" = xyes], [dnl AC_MSG_NOTICE([pregenerated parsers will be required as substitute for Menhir]) ]) dnl ocaml script handling dnl variables: dnl enable_ocaml: whether to enable ocaml scripts AC_ARG_ENABLE([ocaml], AS_HELP_STRING([--enable-ocaml], [enable ocaml scripting (default: auto)])) AS_IF([test "x$OCAML_PKG_dynlink" = xno], [dnl AS_IF([test -z "$enable_ocaml"], [dnl AC_SUBST([enable_ocaml], [no]) AC_MSG_NOTICE([ocaml scripting is disabled because the 'dynlink' package is not installed]) ], [test "x$enable_ocaml" != xno], [dnl AC_MSG_ERROR([the OCaml package dynlink is required for ocaml scripting]) ]) ]) dnl too old ocaml version, disable dynlink by default AS_IF([test "x$OCAMLATLEAST311" = xno], [dnl AS_IF([test -z "$enable_ocaml"], [dnl AC_SUBST([enable_ocaml], [no]) AC_MSG_NOTICE([ocaml scripting has been disabled by default because your OCaml version may not support dynamic linking properly]) ], [test "x$enable_ocaml" = xyes], [dnl AC_MSG_NOTICE([warning: your ocaml version may be too old for dynamic linking, thus ocaml scripting may not work]) ]) ]) dnl no optimized version, disable dynlink by default AS_IF([test "x$OPTIMIZED_dynlink" = xno], [dnl AS_IF([test -z "$enable_ocaml"], [dnl AC_SUBST([enable_ocaml], [no]) AC_MSG_NOTICE([ocaml scripting has been disabled by default because the optimized version of dynlink is not available]) ], [test "x$enable_ocaml" = xyes], [dnl AC_MSG_NOTICE([warning: the optimized version of dynlink is not available, thus ocaml scripting may not work]) ]) ]) dnl scripting requirement on ocamlfind AS_IF([test -n "$SUBSTITUTED_OCAMLFIND"], [dnl AS_IF([test -z "$enable_ocaml"], [dnl this is perhaps a bit too strict AC_SUBST([enable_ocaml],[no]) AC_MSG_NOTICE([ocaml scripting is disabled because it depends on ocamlfind]) ], [test "x$enable_ocaml" != xno], [dnl AC_MSG_NOTICE([warning: ocamlfind is not found but may be required when ocaml scripts are used]) ]) ]) dnl scripting requirement on camlp4 AS_IF([test "x$CAMLP4" = xno], [dnl AS_IF([test -z "$enable_ocaml"], [dnl this is perhaps a bit too strict AC_SUBST([enable_ocaml],no) AC_MSG_NOTICE([ocaml scripting is disabled because it requires camlp4 which is not available]) ], [test "x$enable_ocaml" != xno], [dnl AC_MSG_NOTICE([warning: camlp4 is not found but may be required when ocaml scripts are used]) ]) ]) AS_IF([test "x$enable_ocaml" = xno], [dnl AC_COCCI_INIT_PKG_EMPTY([dynlink]) dnl prevent linking with it AC_SUBST(OCAMLCOCCI_MODULE, [No_prepare_ocamlcocci]) AC_SUBST(OCAMLCOCCI_FILE, [no_prepare_ocamlcocci.ml]) ], [dnl AC_SUBST([enable_ocaml], [yes]) AC_SUBST(OCAMLCOCCI_MODULE, [Yes_prepare_ocamlcocci]) AC_SUBST(OCAMLCOCCI_FILE, [yes_prepare_ocamlcocci.ml]) ]) dnl python handling dnl variables: dnl with_python: whether to enable the python feature (and what version) dnl OCAML_PKG_pycaml: if "local" use local pycaml package AC_ARG_VAR([PYTHON], [path to python when the version is determined automatically]) AC_ARG_ENABLE([python], [AS_HELP_STRING([--enable-python], [enable python scripting (yes/no) (default: auto)])]) AS_IF([test "x$enable_python" != xno], [dnl dnl an explicitly set --with-python disables the global pycaml by default dnl set --enable-pycaml if it is clear that the installed pycaml library dnl is consistent with the chosen python version AS_IF([test -n "$enable_python" -a -z "$enable_pycaml"], [dnl if explicit python given: AC_MSG_NOTICE([skipped the selection of a global pycaml module because --enable-python is given explicitly but --enable-pycaml is not.]) AC_SUBST([enable_pycaml], [no]) ]) dnl sets "$PYVER" if python is available AC_COCCI_PYVER AS_IF([test -z "$PYVER"], [dnl PYVER undetermined AS_IF([test "x$enable_python" = xyes], [dnl AC_MSG_ERROR([python scripting is enabled explicitly but the version of python could not be determined]) ]) ], [dnl AC_MSG_NOTICE([looking for the corresponding python library]) PKG_CHECK_MODULES([PYTHON], [python-$PYVER],[AC_SUBST(HAVE_PYTHON,[yes])],[AC_SUBST(HAVE_PYTHON,[no])]) AS_IF([test "x$HAVE_PYTHON" != xyes -a "x$enable_python" != xyes], [dnl fallback if the above failed AC_MSG_NOTICE([trying the default python library as fallback]) PKG_CHECK_MODULES([PYTHON], [python],[AC_SUBST(HAVE_PYTHON,[yes])],[AC_SUBST(HAVE_PYTHON,[no])]) ]) ]) ]) AS_IF([test -z "$enable_python"], [dnl AS_IF([test "x$HAVE_PYTHON" = xyes], [dnl AC_SUBST([enable_python], [yes]) ], [dnl AC_SUBST([enable_python], [no]) ]) ]) AS_IF([test "x$enable_python" != xno], [dnl AS_IF([test "x$HAVE_PYTHON" = xyes], [dnl AC_MSG_NOTICE([support for python scripts is enabled]) ], [dnl AC_MSG_ERROR([the python scripts feature is enabled but the pkg-config python library is not found]) ]) AC_REQ_COCCI_EXTPKG([pycaml]) AC_SUBST([PYCOCCI_MODULE], [Yes_pycocci]) AC_SUBST([PYCOCCI_FILE],[yes_pycocci.ml]) ], [dnl AC_COCCI_INIT_PKG_EMPTY([pycaml]) AC_SUBST([PYCOCCI_MODULE], [No_pycocci]) AC_SUBST([PYCOCCI_FILE],[no_pycocci.ml]) ]) dnl pcre handling dnl variables: dnl enable_pcre: whether to enable the pcre feature dnl OCAML_PKG_pcre: if "local" use str package AC_ARG_ENABLE([pcre-syntax], AS_HELP_STRING([--enable-pcre-syntax], [enable pcre regular expression syntax (default: auto)])) AS_IF([test "x$enable_pcre_syntax" != "xno"], [dnl PKG_CHECK_MODULES([PCRE], [libpcre],[AC_SUBST([HAVE_PCRE],[yes])],[AC_SUBST([HAVE_PCRE],[no])]) AS_IF([test -z "$enable_pcre_syntax" -a "x$HAVE_PCRE" != xyes], [dnl AC_SUBST([enable_pcre_syntax], [no]) ], [dnl AC_CHECK_COCCI_EXTPKG([pcre]) dnl will set $enable_pcre to 'yes', 'no', or 'local' enable_pcre_syntax=$enable_pcre ]) ]) AS_IF([test "x$enable_pcre_syntax" != xno], [dnl AS_IF([test "x$HAVE_PCRE" = xyes], [dnl AC_MSG_NOTICE([support for pcre syntax is enabled]) ], [dnl AC_MSG_ERROR([the pcre feature is enabled but the pkg-config libpcre library is not found]) ]) AC_SUBST([REGEXP_MODULE], [Regexp_pcre]) AC_SUBST([REGEXP_FILE], [regexp_pcre.ml]) ], [dnl AC_COCCI_INIT_PKG_EMPTY([pcre]) AC_SUBST([REGEXP_MODULE], [Regexp_str]) AC_SUBST([REGEXP_FILE], [regexp_str.ml]) ]) dnl AC_CACHE_SAVE dnl obtain the value of $prefix AS_IF([test "$prefix" = "NONE"],[prefix=$ac_default_prefix]) dnl dnl backwards compatibility dnl dnl defines some variables needed by the Make infrastructure AC_SUBST(SHAREDIR,["${prefix}/share/coccinelle"]) AS_IF([test "x$enable_python" != xno], [dnl AC_SUBST(FEATURE_PYTHON, [1]) ], [dnl AC_SUBST(FEATURE_PYTHON, [0]) ]) AS_IF([test "x$enable_ocaml" != xno], [dnl AC_SUBST(FEATURE_OCAML, [1]) ], [dnl AC_SUBST(FEATURE_OCAML, [0]) ]) dnl dynlink stuff depending on the OCaml version and whether it is enabled AS_IF([test "x$OCAMLATLEAST311" = xyes -a "x$enable_ocaml" = xyes -a "x$OCAMLOPT" != xno], [dnl AC_SUBST([DYNLINK_IS_NATIVE], [Dynlink.is_native]) ], [dnl AC_SUBST([DYNLINK_IS_NATIVE], [false]) ]) dnl in case of the compilation of the manual AC_COCCI_TOOL([PDFLATEX],[pdflatex],[$COCCI_SRCDIR/setup/fake-pdflatex.sh pdflatex]) dnl determine release configuration AC_ARG_ENABLE([release], [AS_HELP_STRING([--enable-release], [build with a release configuration (yes,no,profile default: no)])]) AS_IF([test -z "$enable_release"], [dnl AC_MSG_NOTICE([choosing the development Makefile configuration because the release configuration is not explicitly requested.]) AC_SUBST([enable_release], [no]) ]) AC_SUBST([MODULES_profiling],[]) AS_IF([test "x$enable_release" = xyes], [dnl set the default target to 'release' when enable_release is given AC_SUBST([MAKETARGET_ALL], [all-release]) ], [test "x$enable_release" = xno], [dnl otherwise, set the default target to 'dev' AC_SUBST([MAKETARGET_ALL], [all-dev]) ], [test "x$enable_release" = xprofile], [dnl selected profiling AS_IF([test -z "$OCAMLPROF" -o "x$OCAMLPROF" = xno], [dnl AC_MSG_ERROR([ocamlprof is required for profiling, but is absent.]) ]) dnl configuration-time overrides for profiling AC_SUBST([MAKETARGET_ALL], [all-dev]) AC_SUBST([OCAMLC], ["$COCCI_SRCDIR/setup/wrapper-ocamlcp.sh $OCAMLCORIG $OCAMLPROF"]) AC_SUBST([MODULES_profiling], [profiling.cmo]) AC_MSG_NOTICE([configured coccinelle for profiling]) ], [dnl custom target given AC_SUBST([MAKETARGET_ALL], ["$enable_release"]) ]) dnl determine whether to build the optimizing version AC_ARG_ENABLE([opt], [AS_HELP_STRING([--enable-opt], [build an optimized spatch (yes,no, default: auto)])]) AS_IF([test "x$OCAMLOPT" = xno -a "x$enable_opt" != xno], [dnl AS_IF([test -n "$enable_release" -a "x$enable_release" != xyes -a "x$enable_release" != xno], [dnl AC_MSG_NOTICE([warning: ensure that make target $enable_release does not depend on the unavailable ocamlopt]) ], [test "x$enable_opt" = xyes], [dnl AC_MSG_ERROR([the optimized version of coccinelle is requested explicitly, but ocamlopt is absent]) ], [dnl AC_MSG_NOTICE([the optimized version of coccinelle will not be build because ocamlopt is not present]) AC_SUBST([enable_opt], [no]) ]) ]) AS_IF([test "x$OCAMLVERSION" = x3.11.2 -a -z "$enable_opt"], [dnl the optimized version may not be buildable with ocaml 3.11.2 (know bug), hence disable it by default AC_MSG_NOTICE([the optimized version of coccinelle will not be build by default due to OCaml version $OCAMLVERSION]) AC_SUBST([enable_opt], [no]) ]) dnl disable the optimized target when dynlinking is enabled but the optimized version of dynlink is not available AS_IF([test "x$OPTIMIZED_dynlink" = xno -a "x$enable_ocaml" = xyes], [dnl AS_IF([test -z "$enable_opt"], [dnl 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]) AC_SUBST([enable_opt], [no]) ], [test "x$enable_opt" = xyes], [dnl 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]) ]) ]) dnl set the default enable-opt setting AS_IF([test -z "$enable_opt"], [dnl AS_IF([test "x$enable_release" = xyes -o "x$enable_release" = xno], [dnl AC_SUBST([enable_opt], ["$enable_release"]) ]) ]) dnl variables depending on whether we build the optimized spatch AS_IF([test "x$enable_opt" = xyes], [dnl default target for the optimized version AC_SUBST([SPATCHNAME], [spatch.opt]) AC_SUBST([MAKETARGET_SPATCH], [opt-only]) ], [dnl default target for the bytecode version AC_SUBST([SPATCHNAME], [spatch]) AC_SUBST([MAKETARGET_SPATCH], [byte-only]) ]) dnl ocamlbuild handling AC_ARG_ENABLE([ocamlbuild], AS_HELP_STRING([--enable-ocamlbuild], [enable ocamlbuild support (default: no)])) AS_IF([test "x$enable_ocamlbuild" = xyes], [dnl ocamlbuild support requested AS_IF([test -z "$OCAMLBUILD" -o "x$OCAMLBUILD" = xno], [dnl AC_MSG_ERROR([Ocamlbuild is required but is not installed.]) ]) AC_SUBST([FEATURE_OCAMLBUILD], [yes]) ], [dnl default: disable ocamlbuild support AC_SUBST([FEATURE_OCAMLBUILD], [ ]) ]) dnl dnl generating configuration dnl AC_CONFIG_FILES([ Makefile.config version.ml commons/commands.ml globals/config.ml globals/regexp.ml python/pycocci.ml ocaml/prepare_ocamlcocci.ml scripts/spatch.sh docs/spatch.1 myocamlbuild.ml setup/Makefile ]) AC_OUTPUT AC_MSG_NOTICE([configuration completed]) cat << EOF ------------------------------------------------------------------------------ Summary configure flags: $CONFIGURE_FLAGS findlib: $OCAMLFIND (an actual version is strongly recommended) menhir: $MENHIR (should be an optional tool) menhirLib module: $enable_menhirLib (for local package use --disable-menhirLib) ocaml scripting: $enable_ocaml (overridable with --enable-ocaml) python scripting: $enable_python (overridable with --enable-python) pycaml module: $enable_pycaml (for local package use --disable-pycaml) pcre regexes: $enable_pcre_syntax (overridable with --enable-pcre-syntax) pcre module: $enable_pcre (for local package use --disable-pcre) pcre library: $HAVE_PCRE (requires the dev version of libpcre) release config: $enable_release (strongly recommended to be 'yes', overridable with --enable-release) optimized spatch: $enable_opt (overridable with --disable-opt) ------------------------------------------------------------------------------ Coccinelle can now be compiled and installed. If you compile coccinelle again after source code changes or configuration changes, you may need to run first: \$ make clean To compile coccinelle, run: \$ make all To install coccinelle, run: \$ make install Then, to test coccinelle, run for example: \$ spatch -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c Or when coccinelle is not installed yet: \$ COCCINELLE_HOME=$(pwd) ./scripts/spatch -sp_file demos/simple.cocci demos/simple.c -o /tmp/new_simple.c EOF if test "x$enable_python" != "xno"; then cat << EOF ------------------------------------------------------------------------------ You may need to set some environment variables so that the python libraries are found. The frontend 'spatch' sets the following variables: \$ export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$prefix/lib \$ export PYTHONPATH=\$PYTHONPATH:$prefix/share/coccinelle/python EOF fi cat << EOF ------------------------------------------------------------------------------ EOF