1 # This file is part of Autoconf. -*- Autoconf -*-
2 # Erlang/OTP language support.
3 # Copyright (C) 2006, 2008-2011 Free Software Foundation, Inc.
5 # This file is part of Autoconf. This program is free
6 # software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the
8 # Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # Under Section 7 of GPL version 3, you are granted additional
17 # permissions described in the Autoconf Configure Script Exception,
18 # version 3.0, as published by the Free Software Foundation.
20 # You should have received a copy of the GNU General Public License
21 # and a copy of the Autoconf Configure Script Exception along with
22 # this program; see the files COPYINGv3 and COPYING.EXCEPTION
23 # respectively. If not, see <http://www.gnu.org/licenses/>.
25 # Written by Romain Lenglet.
32 # 1. Language selection
33 # and routines to produce programs in a given language.
35 # 2. Producing programs in a given language.
37 # 3. Looking for a compiler
38 # And possibly the associated preprocessor.
42 ## ------------------- ##
43 ## 0. Utility macros. ##
44 ## ------------------- ##
47 # AC_ERLANG_PATH_ERLC([VALUE-IF-NOT-FOUND], [PATH])
48 # -------------------------------------------------
49 AC_DEFUN([AC_ERLANG_PATH_ERLC],
50 [AC_ARG_VAR([ERLC], [Erlang/OTP compiler command [autodetected]])dnl
51 if test -n "$ERLC"; then
52 AC_MSG_CHECKING([for erlc])
53 AC_MSG_RESULT([$ERLC])
55 AC_PATH_TOOL(ERLC, erlc, [$1], [$2])
57 AC_ARG_VAR([ERLCFLAGS], [Erlang/OTP compiler flags [none]])dnl
61 # AC_ERLANG_NEED_ERLC([PATH])
62 # ---------------------------
63 AC_DEFUN([AC_ERLANG_NEED_ERLC],
64 [AC_ERLANG_PATH_ERLC([not found], [$1])
65 if test "$ERLC" = "not found"; then
66 AC_MSG_ERROR([Erlang/OTP compiler (erlc) not found but required])
71 # AC_ERLANG_PATH_ERL([VALUE-IF-NOT-FOUND], [PATH])
72 # ------------------------------------------------
73 AC_DEFUN([AC_ERLANG_PATH_ERL],
74 [AC_ARG_VAR([ERL], [Erlang/OTP interpreter command [autodetected]])dnl
75 if test -n "$ERL"; then
76 AC_MSG_CHECKING([for erl])
79 AC_PATH_TOOL(ERL, erl, [$1], [$2])[]dnl
84 # AC_ERLANG_NEED_ERL([PATH])
85 # --------------------------
86 AC_DEFUN([AC_ERLANG_NEED_ERL],
87 [AC_ERLANG_PATH_ERL([not found], [$1])
88 if test "$ERL" = "not found"; then
89 AC_MSG_ERROR([Erlang/OTP interpreter (erl) not found but required])
95 ## ----------------------- ##
96 ## 1. Language selection. ##
97 ## ----------------------- ##
102 AC_LANG_DEFINE([Erlang], [erl], [ERL], [ERLC], [],
104 ac_compile='$ERLC $ERLCFLAGS -b beam conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
105 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'
112 AU_DEFUN([AC_LANG_ERLANG], [AC_LANG(Erlang)])
116 ## ----------------------- ##
117 ## 2. Producing programs. ##
118 ## ----------------------- ##
121 # AC_LANG_PROGRAM(Erlang)([PROLOGUE], [BODY])
122 # -------------------------------------------
123 m4_define([AC_LANG_PROGRAM(Erlang)],
125 -export([start/0]).]]
133 # _AC_LANG_NULL_PROGRAM(Erlang)
134 # -----------------------------
135 # Produce source that does nothing.
136 m4_define([_AC_LANG_NULL_PROGRAM(Erlang)],
137 [AC_LANG_PROGRAM([], [halt(0)])])
140 # _AC_LANG_IO_PROGRAM(Erlang)
141 # ---------------------------
142 # Produce source that performs I/O.
143 m4_define([_AC_LANG_IO_PROGRAM(Erlang)],
144 [AC_LANG_PROGRAM([], [dnl
145 ReturnValue = case file:write_file("conftest.out", "") of
149 halt(ReturnValue)])])
152 ## -------------------------------------------- ##
153 ## 3. Looking for Compilers and Preprocessors. ##
154 ## -------------------------------------------- ##
157 # AC_LANG_PREPROC(Erlang)
158 # -----------------------
159 # Find the Erlang preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
160 AC_DEFUN([AC_LANG_PREPROC(Erlang)],
162 [$0: No preprocessor defined for ]_AC_LANG)])
164 # AC_LANG_COMPILER(Erlang)
165 # ------------------------
166 # Find the Erlang compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
167 AC_DEFUN([AC_LANG_COMPILER(Erlang)],
168 [AC_REQUIRE([AC_ERLANG_PATH_ERLC])])
171 # AC_ERLANG_CHECK_LIB(LIBRARY, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
172 # ----------------------------------------------------------------------
173 # Macro for checking if an Erlang library is installed, and to
174 # determine its version.
175 AC_DEFUN([AC_ERLANG_CHECK_LIB],
176 [AC_REQUIRE([AC_ERLANG_PATH_ERLC])[]dnl
177 AC_REQUIRE([AC_ERLANG_PATH_ERL])[]dnl
178 AC_CACHE_CHECK([for Erlang/OTP '$1' library subdirectory],
179 [ac_cv_erlang_lib_dir_$1],
180 [AC_LANG_PUSH(Erlang)[]dnl
182 [AC_LANG_PROGRAM([], [dnl
183 ReturnValue = case code:lib_dir("[$1]") of
185 file:write_file("conftest.out", "not found\n"),
188 file:write_file("conftest.out", LibDir),
191 halt(ReturnValue)])],
192 [ac_cv_erlang_lib_dir_$1=`cat conftest.out`
194 [if test ! -f conftest.out; then
195 AC_MSG_FAILURE([test Erlang program execution failed])
197 ac_cv_erlang_lib_dir_$1="not found"
200 AC_LANG_POP(Erlang)[]dnl
202 AC_CACHE_CHECK([for Erlang/OTP '$1' library version],
203 [ac_cv_erlang_lib_ver_$1],
204 [AS_IF([test "$ac_cv_erlang_lib_dir_$1" = "not found"],
205 [ac_cv_erlang_lib_ver_$1="not found"],
206 [ac_cv_erlang_lib_ver_$1=`AS_ECHO(["$ac_cv_erlang_lib_dir_$1"]) | sed -n -e 's,^.*-\([[^/-]]*\)$,\1,p'`])[]dnl
208 AC_SUBST([ERLANG_LIB_DIR_$1], [$ac_cv_erlang_lib_dir_$1])
209 AC_SUBST([ERLANG_LIB_VER_$1], [$ac_cv_erlang_lib_ver_$1])
210 AS_IF([test "$ac_cv_erlang_lib_dir_$1" = "not found"], [$3], [$2])
211 ])# AC_ERLANG_CHECK_LIB
214 # AC_ERLANG_SUBST_ROOT_DIR
215 # ------------------------
216 # Determines the Erlang/OTP root directory.
217 AC_DEFUN([AC_ERLANG_SUBST_ROOT_DIR],
218 [AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl
219 AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
220 AC_CACHE_CHECK([for Erlang/OTP root directory],
221 [ac_cv_erlang_root_dir],
222 [AC_LANG_PUSH(Erlang)[]dnl
224 [AC_LANG_PROGRAM([], [dnl
225 RootDir = code:root_dir(),
226 file:write_file("conftest.out", RootDir),
228 halt(ReturnValue)])],
229 [ac_cv_erlang_root_dir=`cat conftest.out`
232 AC_MSG_FAILURE([test Erlang program execution failed])])
233 AC_LANG_POP(Erlang)[]dnl
235 AC_SUBST([ERLANG_ROOT_DIR], [$ac_cv_erlang_root_dir])
236 ])# AC_ERLANG_SUBST_ROOT_DIR
239 # AC_ERLANG_SUBST_LIB_DIR
240 # -----------------------
241 AC_DEFUN([AC_ERLANG_SUBST_LIB_DIR],
242 [AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl
243 AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
244 AC_CACHE_CHECK([for Erlang/OTP library base directory],
245 [ac_cv_erlang_lib_dir],
246 [AC_LANG_PUSH(Erlang)[]dnl
248 [AC_LANG_PROGRAM([], [dnl
249 LibDir = code:lib_dir(),
250 file:write_file("conftest.out", LibDir),
252 halt(ReturnValue)])],
253 [ac_cv_erlang_lib_dir=`cat conftest.out`
256 AC_MSG_FAILURE([test Erlang program execution failed])])
257 AC_LANG_POP(Erlang)[]dnl
259 AC_SUBST([ERLANG_LIB_DIR], [$ac_cv_erlang_lib_dir])
260 ])# AC_ERLANG_SUBST_LIB_DIR
263 # AC_ERLANG_SUBST_INSTALL_LIB_DIR
264 # -------------------------------
265 # Directories for installing Erlang/OTP packages are separated from the
266 # directories determined by running the Erlang/OTP installation that is used
268 AC_DEFUN([AC_ERLANG_SUBST_INSTALL_LIB_DIR],
269 [AC_MSG_CHECKING([for Erlang/OTP library installation base directory])
270 AC_ARG_VAR([ERLANG_INSTALL_LIB_DIR],
271 [Erlang/OTP library installation base directory [LIBDIR/erlang/lib]])
272 if test -n "$ERLANG_INSTALL_LIB_DIR"; then
273 AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR])
275 AC_SUBST([ERLANG_INSTALL_LIB_DIR], ['${libdir}/erlang/lib'])
276 AC_MSG_RESULT([$libdir/erlang/lib])
278 ])# AC_ERLANG_SUBST_INSTALL_LIB_DIR
281 # AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR(PACKAGE_TARNAME, PACKAGE_VERSION)
282 # --------------------------------------------------------------------
283 AC_DEFUN([AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR],
284 [AC_REQUIRE([AC_ERLANG_SUBST_INSTALL_LIB_DIR])[]dnl
285 AC_MSG_CHECKING([for Erlang/OTP '$1' library installation subdirectory])
286 AC_ARG_VAR([ERLANG_INSTALL_LIB_DIR_$1],
287 [Erlang/OTP '$1' library installation subdirectory
288 [ERLANG_INSTALL_LIB_DIR/$1-$2]])
289 if test -n "$ERLANG_INSTALL_LIB_DIR_$1"; then
290 AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR_$1])
292 AC_SUBST([ERLANG_INSTALL_LIB_DIR_$1], ['${ERLANG_INSTALL_LIB_DIR}/$1-$2'])
293 AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR/$1-$2])
295 ])# AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR
298 # AC_ERLANG_SUBST_ERTS_VER
299 # ------------------------
300 # Determines the Erlang runtime system version.
301 AC_DEFUN([AC_ERLANG_SUBST_ERTS_VER],
302 [AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl
303 AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
304 AC_CACHE_CHECK([for Erlang/OTP ERTS version],
305 [ac_cv_erlang_erts_ver],
306 [AC_LANG_PUSH([Erlang])[]dnl
308 [AC_LANG_PROGRAM([], [dnl
309 Version = erlang:system_info(version),
310 file:write_file("conftest.out", Version),
312 halt(ReturnValue)])],
313 [ac_cv_erlang_erts_ver=`cat conftest.out`
316 AC_MSG_FAILURE([test Erlang program execution failed])])
317 AC_LANG_POP([Erlang])[]dnl
319 AC_SUBST([ERLANG_ERTS_VER], [$ac_cv_erlang_erts_ver])
320 ])# AC_ERLANG_SUBST_ERTS_VER