# -------------------------------------------------
AC_DEFUN([AC_ERLANG_PATH_ERLC],
[AC_ARG_VAR([ERLC], [Erlang/OTP compiler command [autodetected]])dnl
-if test -n "$ERLC"; then
- AC_MSG_CHECKING([for erlc])
- AC_MSG_RESULT([$ERLC])
-else
- AC_PATH_TOOL(ERLC, erlc, [$1], [$2])
-fi
AC_ARG_VAR([ERLCFLAGS], [Erlang/OTP compiler flags [none]])dnl
+AC_PATH_TOOL(ERLC, erlc, [$1], [$2])
])
# ------------------------------------------------
AC_DEFUN([AC_ERLANG_PATH_ERL],
[AC_ARG_VAR([ERL], [Erlang/OTP interpreter command [autodetected]])dnl
-if test -n "$ERL"; then
- AC_MSG_CHECKING([for erl])
- AC_MSG_RESULT([$ERL])
-else
- AC_PATH_TOOL(ERL, erl, [$1], [$2])[]dnl
-fi
+AC_PATH_TOOL(ERL, erl, [$1], [$2])
])
# ---------------
AC_LANG_DEFINE([Erlang], [erl], [ERL], [ERLC], [],
[ac_ext=erl
-ac_compile='$ERLC $ERLCFLAGS -b beam conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
+: ${ac_objext=o}
+ac_compile='$ERLC $ERLCFLAGS -b beam conftest.$ac_ext >&AS_MESSAGE_LOG_FD && ln -sf conftest.beam conftest.$ac_objext'
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_LANG_COMPILER(Erlang)
# ------------------------
# Find the Erlang compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
+# Technically we only need erlc to compile, but there's no AC_LANG_DISPATCH
+# hook specifically for AC_RUN_IFELSE, so we need to find erl here too.
AC_DEFUN([AC_LANG_COMPILER(Erlang)],
-[AC_REQUIRE([AC_ERLANG_PATH_ERLC])])
+[AC_REQUIRE([AC_ERLANG_NEED_ERLC])
+AC_REQUIRE([AC_ERLANG_NEED_ERL])])
# AC_ERLANG_CHECK_LIB(LIBRARY, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
# Macro for checking if an Erlang library is installed, and to
# determine its version.
AC_DEFUN([AC_ERLANG_CHECK_LIB],
-[AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl
-AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
+[AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
AC_CACHE_CHECK([for Erlang/OTP '$1' library subdirectory],
[ac_cv_erlang_lib_dir_$1],
- [AC_LANG_PUSH(Erlang)[]dnl
- AC_RUN_IFELSE(
- [AC_LANG_PROGRAM([], [dnl
- ReturnValue = case code:lib_dir("[$1]") of
- {error, bad_name} ->
- file:write_file("conftest.out", "not found\n"),
- 1;
- LibDir ->
- file:write_file("conftest.out", LibDir),
- 0
- end,
- halt(ReturnValue)])],
- [ac_cv_erlang_lib_dir_$1=`cat conftest.out`
- rm -f conftest.out],
- [if test ! -f conftest.out; then
- AC_MSG_FAILURE([test Erlang program execution failed])
- else
- ac_cv_erlang_lib_dir_$1="not found"
- rm -f conftest.out
- fi])
- AC_LANG_POP(Erlang)[]dnl
- ])
+ [ac_cv_erlang_lib_dir_$1=`$ERL -noshell -eval '
+ case code:lib_dir("$1") of
+ {error, bad_name} -> io:format("not found~n");
+ LibDir -> io:format("~s~n", @<:@LibDir@:>@)
+ end,
+ halt(0)
+ '`])
AC_CACHE_CHECK([for Erlang/OTP '$1' library version],
[ac_cv_erlang_lib_ver_$1],
[AS_IF([test "$ac_cv_erlang_lib_dir_$1" = "not found"],
- [ac_cv_erlang_lib_ver_$1="not found"],
- [ac_cv_erlang_lib_ver_$1=`AS_ECHO(["$ac_cv_erlang_lib_dir_$1"]) | sed -n -e 's,^.*-\([[^/-]]*\)$,\1,p'`])[]dnl
+ [ac_cv_erlang_lib_ver_$1="not found"],
+ [ac_cv_erlang_lib_ver_$1=`AS_ECHO(["$ac_cv_erlang_lib_dir_$1"]) |
+ sed -n -e 's,^.*-\([[^/-]]*\)$,\1,p'`])[]dnl
])
AC_SUBST([ERLANG_LIB_DIR_$1], [$ac_cv_erlang_lib_dir_$1])
AC_SUBST([ERLANG_LIB_VER_$1], [$ac_cv_erlang_lib_ver_$1])
# ------------------------
# Determines the Erlang/OTP root directory.
AC_DEFUN([AC_ERLANG_SUBST_ROOT_DIR],
-[AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl
-AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
+[AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
AC_CACHE_CHECK([for Erlang/OTP root directory],
[ac_cv_erlang_root_dir],
- [AC_LANG_PUSH(Erlang)[]dnl
- AC_RUN_IFELSE(
- [AC_LANG_PROGRAM([], [dnl
- RootDir = code:root_dir(),
- file:write_file("conftest.out", RootDir),
- ReturnValue = 0,
- halt(ReturnValue)])],
- [ac_cv_erlang_root_dir=`cat conftest.out`
- rm -f conftest.out],
- [rm -f conftest.out
- AC_MSG_FAILURE([test Erlang program execution failed])])
- AC_LANG_POP(Erlang)[]dnl
- ])
+ [ac_cv_erlang_root_dir=`$ERL -noshell -eval '
+ io:format("~s~n", @<:@code:root_dir()@:>@),
+ halt(0)
+ '`])
AC_SUBST([ERLANG_ROOT_DIR], [$ac_cv_erlang_root_dir])
])# AC_ERLANG_SUBST_ROOT_DIR
# AC_ERLANG_SUBST_LIB_DIR
# -----------------------
AC_DEFUN([AC_ERLANG_SUBST_LIB_DIR],
-[AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl
-AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
+[AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
AC_CACHE_CHECK([for Erlang/OTP library base directory],
[ac_cv_erlang_lib_dir],
- [AC_LANG_PUSH(Erlang)[]dnl
- AC_RUN_IFELSE(
- [AC_LANG_PROGRAM([], [dnl
- LibDir = code:lib_dir(),
- file:write_file("conftest.out", LibDir),
- ReturnValue = 0,
- halt(ReturnValue)])],
- [ac_cv_erlang_lib_dir=`cat conftest.out`
- rm -f conftest.out],
- [rm -f conftest.out
- AC_MSG_FAILURE([test Erlang program execution failed])])
- AC_LANG_POP(Erlang)[]dnl
- ])
+ [ac_cv_erlang_lib_dir=`$ERL -noshell -eval '
+ io:format("~s~n", @<:@code:lib_dir()@:>@),
+ halt(0)
+ '`])
AC_SUBST([ERLANG_LIB_DIR], [$ac_cv_erlang_lib_dir])
])# AC_ERLANG_SUBST_LIB_DIR
# ------------------------
# Determines the Erlang runtime system version.
AC_DEFUN([AC_ERLANG_SUBST_ERTS_VER],
-[AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl
-AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
+[AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
AC_CACHE_CHECK([for Erlang/OTP ERTS version],
[ac_cv_erlang_erts_ver],
- [AC_LANG_PUSH([Erlang])[]dnl
- AC_RUN_IFELSE(
- [AC_LANG_PROGRAM([], [dnl
- Version = erlang:system_info(version),
- file:write_file("conftest.out", Version),
- ReturnValue = 0,
- halt(ReturnValue)])],
- [ac_cv_erlang_erts_ver=`cat conftest.out`
- rm -f conftest.out],
- [rm -f conftest.out
- AC_MSG_FAILURE([test Erlang program execution failed])])
- AC_LANG_POP([Erlang])[]dnl
- ])
+ [ac_cv_erlang_erts_ver=`$ERL -noshell -eval '
+ io:format("~s~n", @<:@erlang:system_info(version)@:>@),
+ halt(0)
+ '`])
AC_SUBST([ERLANG_ERTS_VER], [$ac_cv_erlang_erts_ver])
])# AC_ERLANG_SUBST_ERTS_VER
# -*- Autotest -*-
+# Macros tested in acerlang.at:
+# AC_ERLANG_PATH_ERL
+# AC_ERLANG_PATH_ERLC
+# AC_ERLANG_SUBST_ERTS_VER
+# AU::AC_LANG_ERLANG
+
AT_BANNER([Erlang low level compiling and utility macros.])
# Copyright (C) 2009-2017, 2020 Free Software Foundation, Inc.
## Erlang Compiler. ##
## ----------------- ##
-AT_CHECK_MACRO([Erlang],
-[[AC_ERLANG_PATH_ERL([no])
-AC_ERLANG_PATH_ERLC([no])
-if test "$ERL" = "no" || test "$ERLC" = "no"; then AS_EXIT([77]); fi
-AC_LANG([Erlang])
-## Can't compile, but can run an Erlang module:
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [halt(0)])],
- [AC_MSG_RESULT([ok])
- AC_MSG_ERROR([compiling Erlang program should fail])],
- [AC_MSG_RESULT([failed])])
-AC_RUN_IFELSE([AC_LANG_PROGRAM([], [halt(0)])],
- [AC_MSG_RESULT([ok])],
- [AC_MSG_RESULT([failed])
- AC_MSG_ERROR([could not run test program])])
-]],
-[AT_KEYWORDS([Erlang])])
+AT_CHECK_MACRO([Erlang basic compilation],
+[[AC_LANG([Erlang])
+
+AC_CACHE_CHECK([whether erlc works], [ac_cv_erlang_erlc_works],
+ [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [halt(0)])],
+ [ac_cv_erlang_erlc_works=yes],
+ [ac_cv_erlang_erlc_works=no])])
+
+if test $ac_cv_erlang_erlc_works = no; then
+ AC_MSG_ERROR([could not compile a test Erlang module])
+fi
+
+# To keep AT_CHECK_MACRO happy, we lie and say that erl does work
+# when cross compiling.
+AC_CACHE_CHECK([whether erl works], [ac_cv_erlang_erl_works],
+ [AC_RUN_IFELSE([AC_LANG_PROGRAM([], [halt(0)])],
+ [ac_cv_erlang_erl_works=yes],
+ [ac_cv_erlang_erl_works=no],
+ [ac_cv_erlang_erl_works=yes])])
+
+if test $ac_cv_erlang_erl_works = no; then
+ AC_MSG_ERROR([could not run a test Erlang module])
+fi
+]])
## ---------------------- ##
## ---------------------- ##
AT_CHECK_MACRO([AC_ERLANG_CHECK_LIB],
-[[AC_ERLANG_PATH_ERL([no])
-AC_ERLANG_PATH_ERLC([no])
-if test "$ERL" = "no" || test "$ERLC" = "no"; then AS_EXIT([77]); fi
-AC_ERLANG_CHECK_LIB([stdlib],
- [AC_MSG_RESULT([ok])],
- [AC_MSG_RESULT([failed])])
+[[AC_ERLANG_CHECK_LIB([stdlib])
+if test "$ERLANG_LIB_DIR_stdlib" = "not found"; then
+ AC_MSG_ERROR([failed to find the Erlang stdlib])
+fi
## Test that the lib path detection really detected a directory:
-if test "$ERLANG_LIB_DIR_stdlib" != "not found" \
- && test ! -d "$ERLANG_LIB_DIR_stdlib"; then
- AC_MSG_ERROR([incorrect ERLANG_LIB_DIR_stdlib variable])
+if test ! -d "$ERLANG_LIB_DIR_stdlib"; then
+ AC_MSG_ERROR([incorrect ERLANG_LIB_DIR_stdlib variable])
fi
-]],
-[AT_KEYWORDS([Erlang])])
+]])
## --------------------------- ##
## --------------------------- ##
AT_CHECK_MACRO([AC_ERLANG_SUBST_ROOT_DIR],
-[[AC_ERLANG_PATH_ERL([no])
-AC_ERLANG_PATH_ERLC([no])
-if test "$ERL" = "no" || test "$ERLC" = "no"; then AS_EXIT([77]); fi
-AC_ERLANG_SUBST_ROOT_DIR
+[[AC_ERLANG_SUBST_ROOT_DIR
## Test that the root path detection really detected a directory:
if test ! -d "$ERLANG_ROOT_DIR"; then
AC_MSG_ERROR([incorrect ERLANG_ROOT_DIR variable])
fi
-]],
-[AT_KEYWORDS([Erlang])])
+]])
## -------------------------- ##
## -------------------------- ##
AT_CHECK_MACRO([AC_ERLANG_SUBST_LIB_DIR],
-[[AC_ERLANG_PATH_ERL([no])
-AC_ERLANG_PATH_ERLC([no])
-if test "$ERL" = "no" || test "$ERLC" = "no"; then AS_EXIT([77]); fi
-AC_ERLANG_SUBST_LIB_DIR
+[[AC_ERLANG_SUBST_LIB_DIR
## Test that the lib path detection really detected a directory:
if test ! -d "$ERLANG_LIB_DIR"; then
AC_MSG_ERROR([incorrect ERLANG_LIB_DIR variable])
[AT_KEYWORDS([Erlang])])
-## ----------------------------------- ##
-## Erlang install base dir detection. ##
-## ----------------------------------- ##
-
-AT_CHECK_MACRO([AC_ERLANG_SUBST_INSTALL_LIB_DIR],
- [AT_KEYWORDS([Erlang])])
-
-
## ---------------------------------- ##
## Erlang install lib dir detection. ##
## ---------------------------------- ##
AT_CHECK_MACRO([AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR],
[[AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR([test_blah], [1.24-b])
## Test that the generated directory name is well-formed:
-if test `echo "$ERLANG_INSTALL_LIB_DIR_test_blah" | sed -e 's/^.*\///'` != "test_blah-1.24-b"; then
+if test `echo "$ERLANG_INSTALL_LIB_DIR_test_blah" | sed -e 's/^.*\///'` \
+ != "test_blah-1.24-b"; then
AC_MSG_ERROR([incorrect ERLANG_INSTALL_LIB_DIR_test_blah variable])
fi
]],
[AT_KEYWORDS([Erlang])])
-
-
-## -------------------------- ##
-## Erlang version detection. ##
-## -------------------------- ##
-
-AT_CHECK_MACRO([AC_ERLANG_SUBST_ERTS_VER],
-[[AC_ERLANG_PATH_ERL([no])
-AC_ERLANG_PATH_ERLC([no])
-if test "$ERL" = "no" || test "$ERLC" = "no"; then AS_EXIT([77]); fi
-AC_ERLANG_SUBST_ERTS_VER
-]],
-[AT_KEYWORDS([Erlang])])