From 362cd0946c54a8376c9d8ea9c0884c95be7529d6 Mon Sep 17 00:00:00 2001 From: Romain Lenglet Date: Fri, 7 Aug 2009 22:43:38 +0900 Subject: [PATCH 4/4] Add macros AC_ERLANG_CHECK_LIB_HEADER and AC_ERLANG_CHECK_HEADER with doc and tests. --- ChangeLog | 4 +++- NEWS | 3 ++- doc/autoconf.texi | 45 ++++++++++++++++++++++++++++++++++++++++++--- lib/autoconf/erlang.m4 | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tests/erlang.at | 43 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 26464ed..e99e3d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,9 @@ fail if the test module doesn't compile. * lib/autoconf/erlang.m4: Add macros _AC_ERLANG_TRIM_ATOM, - AC_ERLANG_CHECK_MOD, AC_ERLANG_CHECK_FUNC + AC_ERLANG_CHECK_MOD, AC_ERLANG_CHECK_FUNC, + _AC_ERLANG_CHECK_ATTRIBUTES, AC_ERLANG_CHECK_LIB_HEADER, + AC_ERLANG_CHECK_HEADER. * 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 94689bb..8b76d21 100644 --- a/NEWS +++ b/NEWS @@ -10,7 +10,8 @@ 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_MOD, AC_ERLANG_CHECK_FUNC + AC_ERLANG_CHECK_MOD, AC_ERLANG_CHECK_FUNC, AC_ERLANG_CHECK_LIB_HEADER, + AC_ERLANG_CHECK_HEADER ** The following documented autotest macros are new: AT_CHECK_EUNIT diff --git a/doc/autoconf.texi b/doc/autoconf.texi index bac0873..68a2734 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -7812,9 +7812,10 @@ obsolescent, and may be removed in a future release of Autoconf. @cindex Erlang, Library, checking 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}). +the presence of certain Erlang libraries, modules, functions, or +headers. 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} @@ -7945,6 +7946,44 @@ AC_ERLANG_CHECK_FUNC([erlang], [make_tuple], [2], @end example @end defmac address@hidden AC_ERLANG_CHECK_LIB_HEADER (@var{header}, @ovar{action-if-found}, @ + @ovar{action-if-not-found}) address@hidden +Test whether the Erlang include file @var{header} can be included with address@hidden("@var{header}")}, i.e. whether it can be found and +can be compiled. 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 header file can be included; address@hidden is a list of shell commands to run if it is +not. For example, to check if header @code{eunit/include/eunit.hrl} can +be included: + address@hidden +AC_ERLANG_CHECK_LIB_HEADER([eunit/include/eunit.hrl], + [], + [AC_MSG_ERROR([eunit/include/eunit.hrl was not found!])]) address@hidden example address@hidden defmac + address@hidden AC_ERLANG_CHECK_HEADER (@var{header}, @ovar{action-if-found}, @ + @ovar{action-if-not-found}) address@hidden +Test whether the Erlang include file @var{header} can be included with address@hidden("@var{header}")}, i.e. whether it can be found and can be +compiled. 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 header file can be included; address@hidden is a list of shell commands to run if it is +not. For example, to check if header @code{$somedir/some_header.hrl} +can be included: + address@hidden +AC_ERLANG_CHECK_HEADER([$somedir/some_header.hrl], + [], + [AC_MSG_ERROR([$somedir/some_header.hrl 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: diff --git a/lib/autoconf/erlang.m4 b/lib/autoconf/erlang.m4 index 4c8ffe7..f224534 100644 --- a/lib/autoconf/erlang.m4 +++ b/lib/autoconf/erlang.m4 @@ -295,6 +295,52 @@ AS_IF([]dnl ])# AC_ERLANG_CHECK_FUNC +# _AC_ERLANG_CHECK_ATTRIBUTES(ATTRS, [ACTION-IF-TRUE], [ACTION-IF-FALSE]) +# ---------------------------------------------------------------------------- +# Macro for checking that a module with the given attributes compiles. +# FIXME: remove this macro and use AC_COMPILE_IFELSE instead, after +# making it work with Erlang +AC_DEFUN([_AC_ERLANG_CHECK_ATTRIBUTES], +[AC_LANG_PUSH(Erlang)[]dnl +AC_RUN_IFELSE([AC_LANG_PROGRAM([$1], [halt(0)])], [$2], [$3]) +AC_LANG_POP(Erlang)[]dnl +])# _AC_ERLANG_CHECK_ATTRIBUTES + + +# AC_ERLANG_CHECK_LIB_HEADER(HEADER, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +# ---------------------------------------------------------------------------- +# Macro for checking if an Erlang header can be included using -include_lib(). +AC_DEFUN([AC_ERLANG_CHECK_LIB_HEADER], +[AC_REQUIRE([AC_ERLANG_PATH_ERLC])[]dnl +AC_REQUIRE([AC_ERLANG_PATH_ERL])[]dnl +AC_CACHE_CHECK([for Erlang/OTP '$1' library header], + [_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_lib_header_$1])], + # FIXME: replace with AC_COMPILE_IFELSE + [_AC_ERLANG_CHECK_ATTRIBUTES([-include_lib("[$1]").], + [_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_lib_header_$1])="found"], + [_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_lib_header_$1])="not found"])]) +AS_IF([test "$_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_lib_header_$1])" = "found"], + [$2], [$3]) +])# AC_ERLANG_CHECK_LIB_HEADER + + +# AC_ERLANG_CHECK_HEADER(HEADER, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) +# ---------------------------------------------------------------------------- +# Macro for checking if an Erlang header can be included using -include(). +AC_DEFUN([AC_ERLANG_CHECK_HEADER], +[AC_REQUIRE([AC_ERLANG_PATH_ERLC])[]dnl +AC_REQUIRE([AC_ERLANG_PATH_ERL])[]dnl +AC_CACHE_CHECK([for Erlang/OTP '$1' header], + [_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_header_$1])], + # FIXME: replace with AC_COMPILE_IFELSE + [_AC_ERLANG_CHECK_ATTRIBUTES([-include("[$1]").], + [_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_header_$1])="found"], + [_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_header_$1])="not found"])]) +AS_IF([test "$_AC_ERLANG_TRIM_ATOM([ac_cv_erlang_header_$1])" = "found"], + [$2], [$3]) +])# AC_ERLANG_CHECK_HEADER + + # AC_ERLANG_SUBST_ROOT_DIR # ------------------------ # Determines the Erlang/OTP root directory. diff --git a/tests/erlang.at b/tests/erlang.at index a9a055c..c95d96e 100644 --- a/tests/erlang.at +++ b/tests/erlang.at @@ -113,6 +113,49 @@ AC_ERLANG_CHECK_FUNC([some-improbable(!)module-name], [AT_KEYWORDS([Erlang])]) +## ------------------------- ## +## Erlang header detection. ## +## ------------------------- ## + +AT_CHECK_MACRO([AC_ERLANG_CHECK_LIB_HEADER], +[[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 header that should always exist: +AC_ERLANG_CHECK_LIB_HEADER([stdlib/include/qlc.hrl], + [AC_MSG_RESULT([ok])], + [AC_MSG_RESULT([failed]) + AC_MSG_ERROR([header should be detected])]) +# Test a header that should not exist: +AC_ERLANG_CHECK_LIB_HEADER([blah-blah-blah/include/does-not-exist.hrl], + [AC_MSG_RESULT([ok]) + AC_MSG_ERROR([header should not be detected])], + [AC_MSG_RESULT([failed])]) +]], +[AT_KEYWORDS([Erlang])]) + + +AT_CHECK_MACRO([AC_ERLANG_CHECK_HEADER], +[[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 header that exists: +echo "" > conftest.hrl +AC_ERLANG_CHECK_HEADER([conftest.hrl], + [AC_MSG_RESULT([ok]) + rm -f conftest.hrl], + [AC_MSG_RESULT([failed]) + rm -f conftest.hrl + AC_MSG_ERROR([header should be detected])]) +# Test a header that should not exist: +AC_ERLANG_CHECK_HEADER([does-not-exist.hrl], + [AC_MSG_RESULT([ok]) + AC_MSG_ERROR([header should not be detected])], + [AC_MSG_RESULT([failed])]) +]], +[AT_KEYWORDS([Erlang])]) + + ## --------------------------- ## ## Erlang root dir detection. ## ## --------------------------- ## -- 1.6.3.1