From 479e441c8780ba5143ad10a0e59db0913ea09e43 Mon Sep 17 00:00:00 2001 From: Romain Lenglet Date: Fri, 7 Aug 2009 22:33:22 +0900 Subject: [PATCH 3/4] Add macro AC_ERLANG_CHECK_MOD with doc and tests. --- ChangeLog | 2 +- NEWS | 2 +- doc/autoconf.texi | 18 ++++++++++++++++++ lib/autoconf/erlang.m4 | 25 +++++++++++++++++++++++++ tests/erlang.at | 22 ++++++++++++++++++++++ 5 files changed, 67 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e8a96c..26464ed 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,7 @@ fail if the test module doesn't compile. * lib/autoconf/erlang.m4: Add macros _AC_ERLANG_TRIM_ATOM, - AC_ERLANG_CHECK_FUNC. + AC_ERLANG_CHECK_MOD, 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. diff --git a/NEWS b/NEWS index 5e12643..94689bb 100644 --- a/NEWS +++ b/NEWS @@ -10,7 +10,7 @@ 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 + AC_ERLANG_CHECK_MOD, 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 70f1431..bac0873 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -7907,6 +7907,24 @@ should contain: @end example @end defmac address@hidden AC_ERLANG_CHECK_MOD (@var{module}, @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. The result of this +test is cached if caching is enabled when running @command{configure}. address@hidden is a list of shell commands to run if the module +is found; @var{action-if-not-found} is a list of shell commands to run +if it is not. For example, to check if module @code{error_logger} can +be loaded: + address@hidden +AC_ERLANG_CHECK_MOD([error_logger], + [], + [AC_MSG_ERROR([error_logger was not found!])]) address@hidden example address@hidden defmac + @defmac AC_ERLANG_CHECK_FUNC (@var{module}, @var{function}, @var{arity}, @ @ovar{action-if-found}, @ovar{action-if-not-found}) @acindex{ERLANG_CHECK_FUNC} diff --git a/lib/autoconf/erlang.m4 b/lib/autoconf/erlang.m4 index 65b9013..4c8ffe7 100644 --- a/lib/autoconf/erlang.m4 +++ b/lib/autoconf/erlang.m4 @@ -234,6 +234,31 @@ AC_DEFUN([_AC_ERLANG_TRIM_ATOM], [m4_bpatsubst([$1], [[^A-Za-z0-9_]], [_])]) +# AC_ERLANG_CHECK_MOD(MODULE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +# --------------------------------------------------------------------- +# Macro for checking if an Erlang module can be loaded. +AC_DEFUN([AC_ERLANG_CHECK_MOD], +[AC_REQUIRE([AC_ERLANG_PATH_ERLC])[]dnl +AC_REQUIRE([AC_ERLANG_PATH_ERL])[]dnl +AC_CACHE_CHECK([for Erlang/OTP '$1' module], + [_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_mod_$1])], + [AC_LANG_PUSH(Erlang)[]dnl + AC_RUN_IFELSE( + [AC_LANG_PROGRAM([], [dnl + ReturnValue = case code:get_object_code('[$1]') of + {'[$1]', _Beam, _Filename} -> 0; + _ -> 1 + end, + halt(ReturnValue)])], + [_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_mod_$1])="found"], + [_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_mod_$1])="not found"]) + AC_LANG_POP(Erlang)[]dnl + ]) +AS_IF([test "$_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_mod_$1])" = "found"], + [$2], [$3]) +])# AC_ERLANG_CHECK_MOD + + # AC_ERLANG_CHECK_FUNC(MODULE, FUNCTION, ARITY, [ACTION-IF-FOUND], # [ACTION-IF-NOT-FOUND]) # ---------------------------------------------------------------- diff --git a/tests/erlang.at b/tests/erlang.at index ccfd1bb..a9a055c 100644 --- a/tests/erlang.at +++ b/tests/erlang.at @@ -67,6 +67,28 @@ fi [AT_KEYWORDS([Erlang])]) +## ------------------------- ## +## Erlang module detection. ## +## ------------------------- ## + +AT_CHECK_MACRO([AC_ERLANG_CHECK_MOD], +[[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 module that should always exist: +AC_ERLANG_CHECK_MOD([code], + [AC_MSG_RESULT([ok])], + [AC_MSG_RESULT([failed]) + AC_MSG_ERROR([module should be detected])]) +# Test a module that should not exist, with a difficult name: +AC_ERLANG_CHECK_MOD([some-improbable(!)module-name], + [AC_MSG_RESULT([ok]) + AC_MSG_ERROR([module should not be detected])], + [AC_MSG_RESULT([failed])]) +]], +[AT_KEYWORDS([Erlang])]) + + ## --------------------------- ## ## Erlang function detection. ## ## --------------------------- ## -- 1.6.3.1