xref: /netbsd-src/external/gpl3/autoconf/dist/lib/autoconf/erlang.m4 (revision d874e91932377fc40d53f102e48fc3ee6f4fe9de)
1# This file is part of Autoconf.                       -*- Autoconf -*-
2# Erlang/OTP language support.
3# Copyright (C) 2006, 2008-2012 Free Software Foundation, Inc.
4
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.
10#
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.
15#
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.
19#
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/>.
24
25# Written by Romain Lenglet.
26
27
28# Table of Contents:
29#
30# 0. Utility macros
31#
32# 1. Language selection
33#    and routines to produce programs in a given language.
34#
35# 2. Producing programs in a given language.
36#
37# 3. Looking for a compiler
38#    And possibly the associated preprocessor.
39
40
41
42## ------------------- ##
43## 0. Utility macros.  ##
44## ------------------- ##
45
46
47# AC_ERLANG_PATH_ERLC([VALUE-IF-NOT-FOUND], [PATH])
48# -------------------------------------------------
49AC_DEFUN([AC_ERLANG_PATH_ERLC],
50[AC_ARG_VAR([ERLC], [Erlang/OTP compiler command [autodetected]])dnl
51if test -n "$ERLC"; then
52    AC_MSG_CHECKING([for erlc])
53    AC_MSG_RESULT([$ERLC])
54else
55    AC_PATH_TOOL(ERLC, erlc, [$1], [$2])
56fi
57AC_ARG_VAR([ERLCFLAGS], [Erlang/OTP compiler flags [none]])dnl
58])
59
60
61# AC_ERLANG_NEED_ERLC([PATH])
62# ---------------------------
63AC_DEFUN([AC_ERLANG_NEED_ERLC],
64[AC_ERLANG_PATH_ERLC([not found], [$1])
65if test "$ERLC" = "not found"; then
66    AC_MSG_ERROR([Erlang/OTP compiler (erlc) not found but required])
67fi
68])
69
70
71# AC_ERLANG_PATH_ERL([VALUE-IF-NOT-FOUND], [PATH])
72# ------------------------------------------------
73AC_DEFUN([AC_ERLANG_PATH_ERL],
74[AC_ARG_VAR([ERL], [Erlang/OTP interpreter command [autodetected]])dnl
75if test -n "$ERL"; then
76    AC_MSG_CHECKING([for erl])
77    AC_MSG_RESULT([$ERL])
78else
79    AC_PATH_TOOL(ERL, erl, [$1], [$2])[]dnl
80fi
81])
82
83
84# AC_ERLANG_NEED_ERL([PATH])
85# --------------------------
86AC_DEFUN([AC_ERLANG_NEED_ERL],
87[AC_ERLANG_PATH_ERL([not found], [$1])
88if test "$ERL" = "not found"; then
89    AC_MSG_ERROR([Erlang/OTP interpreter (erl) not found but required])
90fi
91])
92
93
94
95## ----------------------- ##
96## 1. Language selection.  ##
97## ----------------------- ##
98
99
100# AC_LANG(Erlang)
101# ---------------
102AC_LANG_DEFINE([Erlang], [erl], [ERL], [ERLC], [],
103[ac_ext=erl
104ac_compile='$ERLC $ERLCFLAGS -b beam conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
105ac_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'
106])
107
108
109
110# AC_LANG_ERLANG
111# --------------
112AU_DEFUN([AC_LANG_ERLANG], [AC_LANG(Erlang)])
113
114
115
116## ----------------------- ##
117## 2. Producing programs.  ##
118## ----------------------- ##
119
120
121# AC_LANG_PROGRAM(Erlang)([PROLOGUE], [BODY])
122# -------------------------------------------
123m4_define([AC_LANG_PROGRAM(Erlang)],
124[[-module(conftest).
125-export([start/0]).]]
126[$1
127start() ->
128$2
129.
130])
131
132
133# _AC_LANG_NULL_PROGRAM(Erlang)
134# -----------------------------
135# Produce source that does nothing.
136m4_define([_AC_LANG_NULL_PROGRAM(Erlang)],
137[AC_LANG_PROGRAM([], [halt(0)])])
138
139
140# _AC_LANG_IO_PROGRAM(Erlang)
141# ---------------------------
142# Produce source that performs I/O.
143m4_define([_AC_LANG_IO_PROGRAM(Erlang)],
144[AC_LANG_PROGRAM([], [dnl
145   ReturnValue = case file:write_file("conftest.out", "") of
146       {error, _} -> 1;
147       ok -> 0
148   end,
149   halt(ReturnValue)])])
150
151
152## -------------------------------------------- ##
153## 3. Looking for Compilers and Preprocessors.  ##
154## -------------------------------------------- ##
155
156
157# AC_LANG_PREPROC(Erlang)
158# -----------------------
159# Find the Erlang preprocessor.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
160AC_DEFUN([AC_LANG_PREPROC(Erlang)],
161[m4_warn([syntax],
162	 [$0: No preprocessor defined for ]_AC_LANG)])
163
164# AC_LANG_COMPILER(Erlang)
165# ------------------------
166# Find the Erlang compiler.  Must be AC_DEFUN'd to be AC_REQUIRE'able.
167AC_DEFUN([AC_LANG_COMPILER(Erlang)],
168[AC_REQUIRE([AC_ERLANG_PATH_ERLC])])
169
170
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.
175AC_DEFUN([AC_ERLANG_CHECK_LIB],
176[AC_REQUIRE([AC_ERLANG_PATH_ERLC])[]dnl
177AC_REQUIRE([AC_ERLANG_PATH_ERL])[]dnl
178AC_CACHE_CHECK([for Erlang/OTP '$1' library subdirectory],
179    [ac_cv_erlang_lib_dir_$1],
180    [AC_LANG_PUSH(Erlang)[]dnl
181     AC_RUN_IFELSE(
182	[AC_LANG_PROGRAM([], [dnl
183	    ReturnValue = case code:lib_dir("[$1]") of
184	    {error, bad_name} ->
185		file:write_file("conftest.out", "not found\n"),
186		1;
187	    LibDir ->
188		file:write_file("conftest.out", LibDir),
189		0
190	    end,
191	    halt(ReturnValue)])],
192	[ac_cv_erlang_lib_dir_$1=`cat conftest.out`
193	 rm -f conftest.out],
194	[if test ! -f conftest.out; then
195	     AC_MSG_FAILURE([test Erlang program execution failed])
196	 else
197	     ac_cv_erlang_lib_dir_$1="not found"
198	     rm -f conftest.out
199	 fi])
200     AC_LANG_POP(Erlang)[]dnl
201    ])
202AC_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
207    ])
208AC_SUBST([ERLANG_LIB_DIR_$1], [$ac_cv_erlang_lib_dir_$1])
209AC_SUBST([ERLANG_LIB_VER_$1], [$ac_cv_erlang_lib_ver_$1])
210AS_IF([test "$ac_cv_erlang_lib_dir_$1" = "not found"], [$3], [$2])
211])# AC_ERLANG_CHECK_LIB
212
213
214# AC_ERLANG_SUBST_ROOT_DIR
215# ------------------------
216# Determines the Erlang/OTP root directory.
217AC_DEFUN([AC_ERLANG_SUBST_ROOT_DIR],
218[AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl
219AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
220AC_CACHE_CHECK([for Erlang/OTP root directory],
221    [ac_cv_erlang_root_dir],
222    [AC_LANG_PUSH(Erlang)[]dnl
223     AC_RUN_IFELSE(
224	[AC_LANG_PROGRAM([], [dnl
225	    RootDir = code:root_dir(),
226	    file:write_file("conftest.out", RootDir),
227	    ReturnValue = 0,
228	    halt(ReturnValue)])],
229	[ac_cv_erlang_root_dir=`cat conftest.out`
230	 rm -f conftest.out],
231	[rm -f conftest.out
232	 AC_MSG_FAILURE([test Erlang program execution failed])])
233     AC_LANG_POP(Erlang)[]dnl
234    ])
235AC_SUBST([ERLANG_ROOT_DIR], [$ac_cv_erlang_root_dir])
236])# AC_ERLANG_SUBST_ROOT_DIR
237
238
239# AC_ERLANG_SUBST_LIB_DIR
240# -----------------------
241AC_DEFUN([AC_ERLANG_SUBST_LIB_DIR],
242[AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl
243AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
244AC_CACHE_CHECK([for Erlang/OTP library base directory],
245    [ac_cv_erlang_lib_dir],
246    [AC_LANG_PUSH(Erlang)[]dnl
247     AC_RUN_IFELSE(
248	[AC_LANG_PROGRAM([], [dnl
249	    LibDir = code:lib_dir(),
250	    file:write_file("conftest.out", LibDir),
251	    ReturnValue = 0,
252	    halt(ReturnValue)])],
253	[ac_cv_erlang_lib_dir=`cat conftest.out`
254	 rm -f conftest.out],
255	[rm -f conftest.out
256	 AC_MSG_FAILURE([test Erlang program execution failed])])
257     AC_LANG_POP(Erlang)[]dnl
258    ])
259AC_SUBST([ERLANG_LIB_DIR], [$ac_cv_erlang_lib_dir])
260])# AC_ERLANG_SUBST_LIB_DIR
261
262
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
267# for building.
268AC_DEFUN([AC_ERLANG_SUBST_INSTALL_LIB_DIR],
269[AC_MSG_CHECKING([for Erlang/OTP library installation base directory])
270AC_ARG_VAR([ERLANG_INSTALL_LIB_DIR],
271    [Erlang/OTP library installation base directory [LIBDIR/erlang/lib]])
272if test -n "$ERLANG_INSTALL_LIB_DIR"; then
273    AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR])
274else
275    AC_SUBST([ERLANG_INSTALL_LIB_DIR], ['${libdir}/erlang/lib'])
276    AC_MSG_RESULT([$libdir/erlang/lib])
277fi
278])# AC_ERLANG_SUBST_INSTALL_LIB_DIR
279
280
281# AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR(PACKAGE_TARNAME, PACKAGE_VERSION)
282# --------------------------------------------------------------------
283AC_DEFUN([AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR],
284[AC_REQUIRE([AC_ERLANG_SUBST_INSTALL_LIB_DIR])[]dnl
285AC_MSG_CHECKING([for Erlang/OTP '$1' library installation subdirectory])
286AC_ARG_VAR([ERLANG_INSTALL_LIB_DIR_$1],
287    [Erlang/OTP '$1' library installation subdirectory
288       [ERLANG_INSTALL_LIB_DIR/$1-$2]])
289if test -n "$ERLANG_INSTALL_LIB_DIR_$1"; then
290    AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR_$1])
291else
292    AC_SUBST([ERLANG_INSTALL_LIB_DIR_$1], ['${ERLANG_INSTALL_LIB_DIR}/$1-$2'])
293    AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR/$1-$2])
294fi
295])# AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR
296
297
298# AC_ERLANG_SUBST_ERTS_VER
299# ------------------------
300# Determines the Erlang runtime system version.
301AC_DEFUN([AC_ERLANG_SUBST_ERTS_VER],
302[AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl
303AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
304AC_CACHE_CHECK([for Erlang/OTP ERTS version],
305    [ac_cv_erlang_erts_ver],
306    [AC_LANG_PUSH([Erlang])[]dnl
307     AC_RUN_IFELSE(
308	[AC_LANG_PROGRAM([], [dnl
309	    Version = erlang:system_info(version),
310	    file:write_file("conftest.out", Version),
311	    ReturnValue = 0,
312	    halt(ReturnValue)])],
313	[ac_cv_erlang_erts_ver=`cat conftest.out`
314	 rm -f conftest.out],
315	[rm -f conftest.out
316	 AC_MSG_FAILURE([test Erlang program execution failed])])
317     AC_LANG_POP([Erlang])[]dnl
318    ])
319AC_SUBST([ERLANG_ERTS_VER], [$ac_cv_erlang_erts_ver])
320])# AC_ERLANG_SUBST_ERTS_VER
321