Fix syntax-check complaints
[autoconf.git] / lib / autoconf / erlang.m4
blob0c9e390f7e28aeab2da841990a81d02d60692312
1 # This file is part of Autoconf.                       -*- Autoconf -*-
2 # Erlang/OTP language support.
3 # Copyright (C) 2006, 2008-2017, 2020-2024 Free Software Foundation,
4 # Inc.
6 # This file is part of Autoconf.  This program is free
7 # software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the
9 # Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # Under Section 7 of GPL version 3, you are granted additional
18 # permissions described in the Autoconf Configure Script Exception,
19 # version 3.0, as published by the Free Software Foundation.
21 # You should have received a copy of the GNU General Public License
22 # and a copy of the Autoconf Configure Script Exception along with
23 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
24 # respectively.  If not, see <https://www.gnu.org/licenses/>.
26 # Written by Romain Lenglet.
29 # Table of Contents:
31 # 0. Utility macros
33 # 1. Language selection
34 #    and routines to produce programs in a given language.
36 # 2. Producing programs in a given language.
38 # 3. Looking for a compiler
39 #    And possibly the associated preprocessor.
43 ## ------------------- ##
44 ## 0. Utility macros.  ##
45 ## ------------------- ##
48 # AC_ERLANG_PATH_ERLC([VALUE-IF-NOT-FOUND], [PATH])
49 # -------------------------------------------------
50 AC_DEFUN([AC_ERLANG_PATH_ERLC],
51 [AC_ARG_VAR([ERLC], [Erlang/OTP compiler command [autodetected]])dnl
52 AC_ARG_VAR([ERLCFLAGS], [Erlang/OTP compiler flags [none]])dnl
53 AC_PATH_TOOL(ERLC, erlc, [$1], [$2])
57 # AC_ERLANG_NEED_ERLC([PATH])
58 # ---------------------------
59 AC_DEFUN([AC_ERLANG_NEED_ERLC],
60 [AC_ERLANG_PATH_ERLC([not found], [$1])
61 if test "$ERLC" = "not found"; then
62     AC_MSG_ERROR([Erlang/OTP compiler (erlc) not found but required], 77)
67 # AC_ERLANG_PATH_ERL([VALUE-IF-NOT-FOUND], [PATH])
68 # ------------------------------------------------
69 AC_DEFUN([AC_ERLANG_PATH_ERL],
70 [AC_ARG_VAR([ERL], [Erlang/OTP interpreter command [autodetected]])dnl
71 AC_PATH_TOOL(ERL, erl, [$1], [$2])
75 # AC_ERLANG_NEED_ERL([PATH])
76 # --------------------------
77 AC_DEFUN([AC_ERLANG_NEED_ERL],
78 [AC_ERLANG_PATH_ERL([not found], [$1])
79 if test "$ERL" = "not found"; then
80     AC_MSG_ERROR([Erlang/OTP interpreter (erl) not found but required], 77)
86 ## ----------------------- ##
87 ## 1. Language selection.  ##
88 ## ----------------------- ##
91 # AC_LANG(Erlang)
92 # ---------------
93 AC_LANG_DEFINE([Erlang], [erl], [ERL], [ERLC], [],
94 [ac_ext=erl
95 : ${ac_objext=o}
96 ac_compile='$ERLC $ERLCFLAGS -b beam conftest.$ac_ext >&AS_MESSAGE_LOG_FD && ln -sf conftest.beam conftest.$ac_objext'
97 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'
102 # AC_LANG_ERLANG
103 # --------------
104 AU_DEFUN([AC_LANG_ERLANG], [AC_LANG(Erlang)])
108 ## ----------------------- ##
109 ## 2. Producing programs.  ##
110 ## ----------------------- ##
113 # AC_LANG_PROGRAM(Erlang)([PROLOGUE], [BODY])
114 # -------------------------------------------
115 m4_define([AC_LANG_PROGRAM(Erlang)],
116 [[-module(conftest).
117 -export([start/0]).]]
119 start() ->
125 # _AC_LANG_NULL_PROGRAM(Erlang)
126 # -----------------------------
127 # Produce source that does nothing.
128 m4_define([_AC_LANG_NULL_PROGRAM(Erlang)],
129 [AC_LANG_PROGRAM([], [halt(0)])])
132 # _AC_LANG_IO_PROGRAM(Erlang)
133 # ---------------------------
134 # Produce source that performs I/O.
135 m4_define([_AC_LANG_IO_PROGRAM(Erlang)],
136 [AC_LANG_PROGRAM([], [dnl
137    ReturnValue = case file:write_file("conftest.out", "") of
138        {error, _} -> 1;
139        ok -> 0
140    end,
141    halt(ReturnValue)])])
144 ## -------------------------------------------- ##
145 ## 3. Looking for Compilers and Preprocessors.  ##
146 ## -------------------------------------------- ##
149 # AC_LANG_PREPROC(Erlang)
150 # -----------------------
151 # Find the Erlang preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
152 AC_DEFUN([AC_LANG_PREPROC(Erlang)],
153 [m4_warn([syntax],
154          [$0: No preprocessor defined for ]_AC_LANG)])
156 # AC_LANG_COMPILER(Erlang)
157 # ------------------------
158 # Find the Erlang compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
159 # Technically we only need erlc to compile, but there's no AC_LANG_DISPATCH
160 # hook specifically for AC_RUN_IFELSE, so we need to find erl here too.
161 AC_DEFUN([AC_LANG_COMPILER(Erlang)],
162 [AC_REQUIRE([AC_ERLANG_NEED_ERLC])
163 AC_REQUIRE([AC_ERLANG_NEED_ERL])])
166 # AC_ERLANG_CHECK_LIB(LIBRARY, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
167 # ----------------------------------------------------------------------
168 # Macro for checking if an Erlang library is installed, and to
169 # determine its version.
170 AC_DEFUN([AC_ERLANG_CHECK_LIB],
171 [AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
172 AC_CACHE_CHECK([for Erlang/OTP '$1' library subdirectory],
173     [ac_cv_erlang_lib_dir_$1],
174     [ac_cv_erlang_lib_dir_$1=`$ERL -noshell -eval '
175         case code:lib_dir("$1") of
176             {error, bad_name} -> io:format("not found~n");
177             LibDir -> io:format("~s~n", @<:@LibDir@:>@)
178         end,
179         halt(0)
180     '`])
181 AC_CACHE_CHECK([for Erlang/OTP '$1' library version],
182     [ac_cv_erlang_lib_ver_$1],
183     [AS_IF([test "$ac_cv_erlang_lib_dir_$1" = "not found"],
184         [ac_cv_erlang_lib_ver_$1="not found"],
185         [ac_cv_erlang_lib_ver_$1=`AS_ECHO(["$ac_cv_erlang_lib_dir_$1"]) |
186             sed -n -e 's,^.*-\([[^/-]]*\)$,\1,p'`])[]dnl
187     ])
188 AC_SUBST([ERLANG_LIB_DIR_$1], [$ac_cv_erlang_lib_dir_$1])
189 AC_SUBST([ERLANG_LIB_VER_$1], [$ac_cv_erlang_lib_ver_$1])
190 AS_IF([test "$ac_cv_erlang_lib_dir_$1" = "not found"], [$3], [$2])
191 ])# AC_ERLANG_CHECK_LIB
194 # AC_ERLANG_SUBST_ROOT_DIR
195 # ------------------------
196 # Determines the Erlang/OTP root directory.
197 AC_DEFUN([AC_ERLANG_SUBST_ROOT_DIR],
198 [AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
199 AC_CACHE_CHECK([for Erlang/OTP root directory],
200     [ac_cv_erlang_root_dir],
201     [ac_cv_erlang_root_dir=`$ERL -noshell -eval '
202         io:format("~s~n", @<:@code:root_dir()@:>@),
203         halt(0)
204     '`])
205 AC_SUBST([ERLANG_ROOT_DIR], [$ac_cv_erlang_root_dir])
206 ])# AC_ERLANG_SUBST_ROOT_DIR
209 # AC_ERLANG_SUBST_LIB_DIR
210 # -----------------------
211 AC_DEFUN([AC_ERLANG_SUBST_LIB_DIR],
212 [AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
213 AC_CACHE_CHECK([for Erlang/OTP library base directory],
214     [ac_cv_erlang_lib_dir],
215     [ac_cv_erlang_lib_dir=`$ERL -noshell -eval '
216         io:format("~s~n", @<:@code:lib_dir()@:>@),
217         halt(0)
218     '`])
219 AC_SUBST([ERLANG_LIB_DIR], [$ac_cv_erlang_lib_dir])
220 ])# AC_ERLANG_SUBST_LIB_DIR
223 # AC_ERLANG_SUBST_INSTALL_LIB_DIR
224 # -------------------------------
225 # Directories for installing Erlang/OTP packages are separated from the
226 # directories determined by running the Erlang/OTP installation that is used
227 # for building.
228 AC_DEFUN([AC_ERLANG_SUBST_INSTALL_LIB_DIR],
229 [AC_MSG_CHECKING([for Erlang/OTP library installation base directory])
230 AC_ARG_VAR([ERLANG_INSTALL_LIB_DIR],
231     [Erlang/OTP library installation base directory [LIBDIR/erlang/lib]])
232 if test -n "$ERLANG_INSTALL_LIB_DIR"; then
233     AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR])
234 else
235     AC_SUBST([ERLANG_INSTALL_LIB_DIR], ['${libdir}/erlang/lib'])
236     AC_MSG_RESULT([$libdir/erlang/lib])
238 ])# AC_ERLANG_SUBST_INSTALL_LIB_DIR
241 # AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR(PACKAGE_TARNAME, PACKAGE_VERSION)
242 # --------------------------------------------------------------------
243 AC_DEFUN([AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR],
244 [AC_REQUIRE([AC_ERLANG_SUBST_INSTALL_LIB_DIR])[]dnl
245 AC_MSG_CHECKING([for Erlang/OTP '$1' library installation subdirectory])
246 AC_ARG_VAR([ERLANG_INSTALL_LIB_DIR_$1],
247     [Erlang/OTP '$1' library installation subdirectory
248        [ERLANG_INSTALL_LIB_DIR/$1-$2]])
249 if test -n "$ERLANG_INSTALL_LIB_DIR_$1"; then
250     AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR_$1])
251 else
252     AC_SUBST([ERLANG_INSTALL_LIB_DIR_$1], ['${ERLANG_INSTALL_LIB_DIR}/$1-$2'])
253     AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR/$1-$2])
255 ])# AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR
258 # AC_ERLANG_SUBST_ERTS_VER
259 # ------------------------
260 # Determines the Erlang runtime system version.
261 AC_DEFUN([AC_ERLANG_SUBST_ERTS_VER],
262 [AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
263 AC_CACHE_CHECK([for Erlang/OTP ERTS version],
264     [ac_cv_erlang_erts_ver],
265     [ac_cv_erlang_erts_ver=`$ERL -noshell -eval '
266         io:format("~s~n", @<:@erlang:system_info(version)@:>@),
267         halt(0)
268     '`])
269 AC_SUBST([ERLANG_ERTS_VER], [$ac_cv_erlang_erts_ver])
270 ])# AC_ERLANG_SUBST_ERTS_VER