Hi,

Here is a series of patches for 1) fixing the command line used for 
AC_RUN_IFELSE so that the run fails if the module doesn't compile (patch 
0001), and 2) adding 4 new macros to test for modules, functions, and headers 
(patches 0002-0004) with their doc and tests.

I have split the changes into 4 patches, to hopefully make your review easier.

Best regards,
--
Romain Lenglet
From be6531288d2602ff4fffb5d00fc38944cff00145 Mon Sep 17 00:00:00 2001
From: Romain Lenglet <[email protected]>
Date: Fri, 7 Aug 2009 08:02:01 +0900
Subject: [PATCH 1/4] Make AC_RUN_IFELSE fail for Erlang if the program doesn't compile.

---
 ChangeLog              |    5 +++++
 lib/autoconf/erlang.m4 |    2 +-
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8e88f2c..85c68ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-08-07  Romain Lenglet  <[email protected]>
+
+	* lib/autoconf/erlang.m4 (AC_LANG(Erlang)): Make AC_RUN_IFELSE
+	fail if the test module doesn't compile.
+
 2009-08-02  Paolo Bonzini  <[email protected]>
 
 	Use exit code to detect no occurrences with grep.
diff --git a/lib/autoconf/erlang.m4 b/lib/autoconf/erlang.m4
index 0c4504d..59b02e4 100644
--- a/lib/autoconf/erlang.m4
+++ b/lib/autoconf/erlang.m4
@@ -124,7 +124,7 @@ fi
 AC_LANG_DEFINE([Erlang], [erl], [ERL], [],
 [ac_ext=erl
 ac_compile='$ERLC $ERLCFLAGS -b beam conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
-ac_link='$ERLC $ERLCFLAGS -b beam conftest.$ac_ext >&AS_MESSAGE_LOG_FD ; echo "[#]!/bin/sh" > conftest$ac_exeext ; AS_ECHO(["\"$ERL\" -run conftest start -run init stop -noshell"]) >> conftest$ac_exeext ; chmod +x conftest$ac_exeext'
+ac_link='$ERLC $ERLCFLAGS -b beam conftest.$ac_ext >&AS_MESSAGE_LOG_FD && echo "[#]!/bin/sh" > conftest$ac_exeext && AS_ECHO(["\"$ERL\" -run conftest start -run init stop -noshell"]) >> conftest$ac_exeext && chmod +x conftest$ac_exeext'
 ])
 
 
-- 
1.6.3.1

From 4b3183679a3c35f3b7b2dba63b44b7ada2377536 Mon Sep 17 00:00:00 2001
From: Romain Lenglet <[email protected]>
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  <[email protected]>
 
 	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:
+...@defmac AC_ERLANG_CHECK_FUNC (@var{module}, @var{function}, @var{arity}, @
+  @ovar{action-if-found}, @ovar{action-if-not-found})
+...@acindex{erlang_check_func}
+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
+...@var{arity}.  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;
+...@var{action-if-not-found} 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:
+
+...@example
+AC_ERLANG_CHECK_FUNC([erlang], [make_tuple], [2],
+  [],
+  [AC_MSG_ERROR([erlang:make_tuple/2 was not found!])])
+...@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:
 
 @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

From 479e441c8780ba5143ad10a0e59db0913ea09e43 Mon Sep 17 00:00:00 2001
From: Romain Lenglet <[email protected]>
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
 
+...@defmac AC_ERLANG_CHECK_MOD (@var{module}, @ovar{action-if-found}, @
+  @ovar{action-if-not-found})
+...@acindex{erlang_check_mod}
+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}.
+...@var{action-if-found} 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:
+
+...@example
+AC_ERLANG_CHECK_MOD([error_logger],
+  [],
+  [AC_MSG_ERROR([error_logger was not found!])])
+...@end example
+...@end 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

From 362cd0946c54a8376c9d8ea9c0884c95be7529d6 Mon Sep 17 00:00:00 2001
From: Romain Lenglet <[email protected]>
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
 
+...@defmac AC_ERLANG_CHECK_LIB_HEADER (@var{header}, @ovar{action-if-found}, @
+  @ovar{action-if-not-found})
+...@acindex{erlang_check_lib_header}
+Test whether the Erlang include file @var{header} can be included with
+...@code{-include_lib("@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;
+...@var{action-if-not-found} 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:
+
+...@example
+AC_ERLANG_CHECK_LIB_HEADER([eunit/include/eunit.hrl],
+  [],
+  [AC_MSG_ERROR([eunit/include/eunit.hrl was not found!])])
+...@end example
+...@end defmac
+
+...@defmac AC_ERLANG_CHECK_HEADER (@var{header}, @ovar{action-if-found}, @
+  @ovar{action-if-not-found})
+...@acindex{erlang_check_header}
+Test whether the Erlang include file @var{header} can be included with
+...@code{-include("@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;
+...@var{action-if-not-found} 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:
+
+...@example
+AC_ERLANG_CHECK_HEADER([$somedir/some_header.hrl],
+  [],
+  [AC_MSG_ERROR([$somedir/some_header.hrl was not found!])])
+...@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:
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

Reply via email to