I have contributed a patch to Autoconf’s Erlang-related macros, adapted from a patch sent to me by Ruslan Babayev. The AC_ERLANG_CHECK_LIB
macro has been modified to set the ERLANG_LIB_VER_library
variable when checking for the presence of a library library. The macro sets it to the version number of the library, in addition to setting the ERLANG_LIB_DIR_library
variable to the path of the library directory. For instance, to check the presence of the erl_interface
library, and to get its version, you can include those lines in your configure.ac
file:
AC_ERLANG_CHECK_LIB(erl_interface) AC_MSG_NOTICE([erl_interface version: \"$ERLANG_LIB_VER_erl_interface\"]) AC_MSG_NOTICE([erl_interface directory: \"$ERLANG_LIB_DIR_erl_interface\"])
Those new ERLANG_LIB_VER_library
variables can be used for two purposes:
- To check that the installed version of a library matches a specific version or range of versions.
- To automatically rewrite
.rel
files to contain the versions of libraries that are actually installed. I will write about this in a future article, since Ruslan also sent me a nice application skeleton that makes use of those features. This deserves a separate article.
To compare version numbers, I recommend to use the AX_COMPARE_VERSION
macro that is part of the Autoconf Macro Archive, a collection of freely reusable GNU Autoconf macros. In Debian GNU/Linux, it is distributed in the autoconf-archive
package. For instance, the following configure.ac
file snippet checks that the Erlang/OTP stdlib
library is installed, and that its version is greater or equal to 1.14
:
AC_ERLANG_CHECK_LIB(stdlib, [], [AC_MSG_ERROR([Erlang/OTP stdlib library not found but required])]) AX_COMPARE_VERSION([$ERLANG_LIB_VER_stdlib], [ge], [1.14], [], [AC_MSG_ERROR([Erlang/OTP stdlib library version >=1.14 required])])
Or better, to be more pedantic and to fit better with the standard behavior of Autoconf’s macros, notably to support Autoconf’s caching capability:
AC_ERLANG_CHECK_LIB(stdlib, [], [AC_MSG_ERROR([Erlang/OTP stdlib library not found but required])]) AC_CACHE_CHECK([whether the version of the Erlang/OTP stdlib library matches], [erlang_cv_lib_vercheck_stdlib], [AX_COMPARE_VERSION([$ERLANG_LIB_VER_stdlib], [ge], [1.14], [erlang_cv_lib_vercheck_stdlib="yes"], [erlang_cv_lib_vercheck_stdlib="no"])]) AS_IF([test "$erlang_cv_lib_vercheck_stdlib" = "yes"], [], [AC_MSG_ERROR([Erlang/OTP stdlib library version >=1.14 required])])
The configuration test above could be refactored into a reusable macro. However, since it uses the AX_COMPARE_VERSION
macro which is not included in GNU Autoconf, there is no chance that it could be included into the official GNU Autoconf project. And because the needs for checking Erlang/OTP library versions probably vary too much between projects, it seems better that anyone takes this configuration code snippet and adapts it to his needs in his own configure.ac
file.
To use this new version of this Autoconf Erlang macro, you either have to wait for the next release of Autoconf (version 2.60b?), or to use Autoconf’s current version 2.60 and to follow the following steps. Create a directory in your project root directory, e.g. named acmacros
. In that directory, create a file, e.g. named erlang-new.m4
, which contains only the new definition of the AC_ERLANG_CHECK_LIB
macro. You can download my own erlang-new_2006-09-05.m4
file. Project-specific macros have precedence over the macros installed with Autoconf. Therefore, this new definition of AC_ERLANG_CHECK_LIB
will be used instead of the one in Autoconf.
In addition, to use the Autoconf Macro Archive’s AX_COMPARE_VERSION
, you must copy its ax_compare_version.m4
file into the acmacros
directory. In the Debian GNU/Linux package, this file is installed in /usr/share/autoconf-archive
.
Then, to use those project-specific macros, one only has to give the path to the macro directory to aclocal
, which will scan the files in that directory automatically:
> aclocal -I acmacros > autoconf
Here you are! In a future article, I will write about Ruslan’s ideas to automate the configuration of Erlang/OTP .rel
and .app
files.