From 4b3183679a3c35f3b7b2dba63b44b7ada2377536 Mon Sep 17 00:00:00 2001 From: Romain Lenglet Date: Fri, 7 Aug 2009 08:08:47 +0900 Subject: [PATCH 2/4] Add macro AC_ERLANG_CHECK_FUNC with doc and tests. --- ChangeLog | 7 +++++++ NEWS | 3 +++ doc/autoconf.texi | 34 +++++++++++++++++++++++++++------- lib/autoconf/erlang.m4 | 44 ++++++++++++++++++++++++++++++++++++++++++++ tests/erlang.at | 24 ++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 85c68ee..9e8a96c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,13 @@ * lib/autoconf/erlang.m4 (AC_LANG(Erlang)): Make AC_RUN_IFELSE fail if the test module doesn't compile. + * lib/autoconf/erlang.m4: Add macros _AC_ERLANG_TRIM_ATOM, + AC_ERLANG_CHECK_FUNC. + * doc/autoconf.texi (Erlang Libraries): Add doc for new macros. + * tests/erlang.at (Erlang Eunit unit tests): Add test for new + macros. + * NEWS: Mention new Erlang macros. + 2009-08-02 Paolo Bonzini Use exit code to detect no occurrences with grep. diff --git a/NEWS b/NEWS index 50f4e0e..5e12643 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,9 @@ GNU Autoconf NEWS - User visible changes. These macros are present only for backwards compatibility purposes. +** The following documented autoconf macros are new: + AC_ERLANG_CHECK_FUNC + ** The following documented autotest macros are new: AT_CHECK_EUNIT diff --git a/doc/autoconf.texi b/doc/autoconf.texi index b1b38da..70f1431 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -7811,10 +7811,10 @@ obsolescent, and may be removed in a future release of Autoconf. @section Erlang Libraries @cindex Erlang, Library, checking -The following macros check for an installation of Erlang/OTP, and for the -presence of certain Erlang libraries. All those macros require the -configuration of an Erlang interpreter and an Erlang compiler -(@pxref{Erlang Compiler and Interpreter}). +The following macros check for an installation of Erlang/OTP, and for +the presence of certain Erlang libraries, modules or functions. All +those macros require the configuration of an Erlang interpreter and an +Erlang compiler (@pxref{Erlang Compiler and Interpreter}). @defmac AC_ERLANG_SUBST_ERTS_VER @acindex{ERLANG_SUBST_ERTS_VER} @@ -7907,9 +7907,29 @@ should contain: @end example @end defmac -In addition to the above macros, which test installed Erlang libraries, the -following macros determine the paths to the directories into which newly built -Erlang libraries are to be installed: address@hidden AC_ERLANG_CHECK_FUNC (@var{module}, @var{function}, @var{arity}, @ + @ovar{action-if-found}, @ovar{action-if-not-found}) address@hidden +Test whether the Erlang module named @var{module} can be loaded by +Erlang's @code{code:get_object_code/1} function, and that this module +defines and exports a function named @var{function} with arity address@hidden The result of this test is cached if caching is enabled +when running @command{configure}. @var{action-if-found} is a list of +shell commands to run if the function is found; address@hidden is a list of shell commands to run if it is +not. For example, to check if function @code{erlang:make_tuple/2} can +be called: + address@hidden +AC_ERLANG_CHECK_FUNC([erlang], [make_tuple], [2], + [], + [AC_MSG_ERROR([erlang:make_tuple/2 was not found!])]) address@hidden example address@hidden defmac + +In addition to the above macros, which test installed Erlang libraries, +the following macros determine the paths to the directories into which +newly built Erlang libraries are to be installed: @defmac AC_ERLANG_SUBST_INSTALL_LIB_DIR @acindex{ERLANG_SUBST_INSTALL_LIB_DIR} diff --git a/lib/autoconf/erlang.m4 b/lib/autoconf/erlang.m4 index 59b02e4..65b9013 100644 --- a/lib/autoconf/erlang.m4 +++ b/lib/autoconf/erlang.m4 @@ -226,6 +226,50 @@ AS_IF([test "$ac_cv_erlang_lib_dir_$1" = "not found"], [$3], [$2]) ])# AC_ERLANG_CHECK_LIB +# _AC_ERLANG_TRIM_ATOM(ATOM) +# -------------------------- +# Transforms an Erlang atom to substitute all characters that are not +# allowed in shell script variable names. +AC_DEFUN([_AC_ERLANG_TRIM_ATOM], +[m4_bpatsubst([$1], [[^A-Za-z0-9_]], [_])]) + + +# AC_ERLANG_CHECK_FUNC(MODULE, FUNCTION, ARITY, [ACTION-IF-FOUND], +# [ACTION-IF-NOT-FOUND]) +# ---------------------------------------------------------------- +# Macro for checking if an Erlang module can be loaded, and that it +# defines and exports a function with a given name and arity. +AC_DEFUN([AC_ERLANG_CHECK_FUNC], +[AC_REQUIRE([AC_ERLANG_PATH_ERLC])[]dnl +AC_REQUIRE([AC_ERLANG_PATH_ERL])[]dnl +AC_CACHE_CHECK([for Erlang/OTP '$1:$2/$3' function], + [_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_func_$1__$2_$3])], + [AC_LANG_PUSH(Erlang)[]dnl + AC_RUN_IFELSE( + [AC_LANG_PROGRAM([], [dnl + ReturnValue = case code:get_object_code('[$1]') of + {'[$1]', Beam, _Filename} -> + case beam_lib:chunks(Beam, [[exports]]) of + {ok, {'[$1]', [[{exports, Exports}]]}} -> + case lists:member({'[$2]', [$3]}, Exports) of + true -> 0; + false -> 1 + end; + _ -> 1 + end; + _ -> 1 + end, + halt(ReturnValue)])], + [_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_func_$1__$2_$3])="found"], + [_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_func_$1__$2_$3])="not found"]) + AC_LANG_POP(Erlang)[]dnl + ]) +AS_IF([]dnl + [test "$_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_func_$1__$2_$3])" = "found"], + [$4], [$5]) +])# AC_ERLANG_CHECK_FUNC + + # AC_ERLANG_SUBST_ROOT_DIR # ------------------------ # Determines the Erlang/OTP root directory. diff --git a/tests/erlang.at b/tests/erlang.at index e8a5de7..ccfd1bb 100644 --- a/tests/erlang.at +++ b/tests/erlang.at @@ -68,6 +68,30 @@ fi ## --------------------------- ## +## Erlang function detection. ## +## --------------------------- ## + +AT_CHECK_MACRO([AC_ERLANG_CHECK_FUNC], +[[AC_ERLANG_PATH_ERL([not found]) +AC_ERLANG_PATH_ERLC([not found]) +if test "$ERL" = "not found" || test "$ERLC" = "not found"; then exit 77; fi +# Test a function that should always exist: +AC_ERLANG_CHECK_FUNC([code], [lib_dir], [1], + [AC_MSG_RESULT([ok])], + [AC_MSG_RESULT([failed]) + AC_MSG_ERROR([function should be detected])]) +# Test a function that should not exist, with a difficult name: +AC_ERLANG_CHECK_FUNC([some-improbable(!)module-name], + [some-improbable-function-name (?!)], + [424242], + [AC_MSG_RESULT([ok]) + AC_MSG_ERROR([function should not be detected])], + [AC_MSG_RESULT([failed])]) +]], +[AT_KEYWORDS([Erlang])]) + + +## --------------------------- ## ## Erlang root dir detection. ## ## --------------------------- ## -- 1.6.3.1