1# This file is part of Autoconf. -*- Autoconf -*- 2# Erlang/OTP language support. 3# Copyright (C) 2006 Free Software Foundation, Inc. 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 2, or (at your option) 8# any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program; if not, write to the Free Software 17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 18# 02110-1301, USA. 19# 20# As a special exception, the Free Software Foundation gives unlimited 21# permission to copy, distribute and modify the configure scripts that 22# are the output of Autoconf. You need not follow the terms of the GNU 23# General Public License when using or distributing such scripts, even 24# though portions of the text of Autoconf appear in them. The GNU 25# General Public License (GPL) does govern all other use of the material 26# that constitutes the Autoconf program. 27# 28# Certain portions of the Autoconf source text are designed to be copied 29# (in certain cases, depending on the input) into the output of 30# Autoconf. We call these the "data" portions. The rest of the Autoconf 31# source text consists of comments plus executable code that decides which 32# of the data portions to output in any given case. We call these 33# comments and executable code the "non-data" portions. Autoconf never 34# copies any of the non-data portions into its output. 35# 36# This special exception to the GPL applies to versions of Autoconf 37# released by the Free Software Foundation. When you make and 38# distribute a modified version of Autoconf, you may extend this special 39# exception to the GPL to apply to your modified version as well, *unless* 40# your modified version has the potential to copy into its output some 41# of the text that was the non-data portion of the version that you started 42# with. (In other words, unless your change moves or copies text from 43# the non-data portions to the data portions.) If your modification has 44# such potential, you must delete any notice of this special exception 45# to the GPL from your modified version. 46# 47# Written by Romain Lenglet. 48 49 50# AC_ERLANG_PATH_ERLC([VALUE-IF-NOT-FOUND], [PATH]) 51# ---------------------------------------------- 52AC_DEFUN([AC_ERLANG_PATH_ERLC], 53[AC_ARG_VAR([ERLC], [Erlang/OTP compiler command [autodetected]])dnl 54if test -n "$ERLC"; then 55 AC_MSG_CHECKING([for erlc]) 56 AC_MSG_RESULT([$ERLC]) 57else 58 AC_PATH_TOOL(ERLC, erlc, [$1], [$2]) 59fi 60AC_ARG_VAR([ERLCFLAGS], [Erlang/OTP compiler flags [none]])dnl 61])# AC_ERLANG_PATH_ERLC 62 63# AC_ERLANG_NEED_ERLC([PATH]) 64# ------------------------ 65AC_DEFUN([AC_ERLANG_NEED_ERLC], 66[AC_ERLANG_PATH_ERLC([not found], [$1]) 67if test "$ERLC" = "not found"; then 68 AC_MSG_ERROR([Erlang/OTP compiler (erlc) not found but required]) 69fi 70])# AC_ERLANG_NEED_ERLC 71 72# AC_ERLANG_PATH_ERL([VALUE-IF-NOT-FOUND], [PATH]) 73# --------------------------------------------- 74AC_DEFUN([AC_ERLANG_PATH_ERL], 75[AC_ARG_VAR([ERL], [Erlang/OTP interpreter command [autodetected]])dnl 76if test -n "$ERL"; then 77 AC_MSG_CHECKING([for erl]) 78 AC_MSG_RESULT([$ERL]) 79else 80 AC_PATH_TOOL(ERL, erl, [$1], [$2])[]dnl 81fi 82])# AC_ERLANG_PATH_ERL 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])# AC_ERLANG_NEED_ERL 92 93 94 95 96 97 98 99dnl Extend Autoconf's AC_LANG macro to accept Erlang as a language for tests 100 101## ----------------------- ## 102## 1. Language selection. ## 103## ----------------------- ## 104 105 106# ------------------------- # 107# 1x. The Erlang language. # 108# ------------------------- # 109 110# AC_LANG(Erlang) 111# --------------- 112m4_define([AC_LANG(Erlang)], 113[ac_ext=erl 114ac_compile='$ERLC $ERLCFLAGS -b beam conftest.$ac_ext >&AS_MESSAGE_LOG_FD' 115ac_link='$ERLC $ERLCFLAGS -b beam conftest.$ac_ext >&AS_MESSAGE_LOG_FD ; echo "#!/bin/sh" > conftest$ac_exeext ; echo "\"$ERL\" -run conftest start -run init stop -noshell" >> conftest$ac_exeext ; chmod +x conftest$ac_exeext' 116]) 117 118# AC_LANG_ERLANG 119# -------------- 120m4_define([AC_LANG_ERLANG], [AC_LANG(Erlang)]) 121 122 123# _AC_LANG_ABBREV(Erlang) 124# ----------------------- 125m4_define([_AC_LANG_ABBREV(Erlang)], [erl]) 126 127 128# _AC_LANG_PREFIX(Erlang) 129# ----------------------- 130m4_define([_AC_LANG_PREFIX(Erlang)], [ERL]) 131 132 133## ---------------------- ## 134## 2.Producing programs. ## 135## ---------------------- ## 136 137 138# ---------------------- # 139# 2x. Generic routines. # 140# ---------------------- # 141 142# AC_LANG_SOURCE(Erlang)(BODY) 143# ---------------------------- 144m4_define([AC_LANG_SOURCE(Erlang)], 145[$1]) 146 147# AC_LANG_PROGRAM(Erlang)([PROLOGUE], [BODY]) 148# ------------------------------------------- 149m4_define([AC_LANG_PROGRAM(Erlang)], 150[[-module(conftest). 151-export([start/0]).]] 152[$1 153start() -> 154$2 155. 156]) 157 158 159## -------------------------------------------- ## 160## 3. Looking for Compilers and Preprocessors. ## 161## -------------------------------------------- ## 162 163# ------------------------- # 164# 3x. The Erlang compiler. # 165# ------------------------- # 166 167# AC_LANG_PREPROC(Erlang) 168# ----------------------- 169# Find the Erlang preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able. 170AC_DEFUN([AC_LANG_PREPROC(Erlang)], 171[m4_warn([syntax], 172 [$0: No preprocessor defined for ]_AC_LANG)]) 173 174# AC_LANG_COMPILER(Erlang) 175# ---------------------------- 176# Find the Erlang compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able. 177AC_DEFUN([AC_LANG_COMPILER(Erlang)], 178[AC_REQUIRE([AC_ERLANG_PATH_ERLC])]) 179 180 181 182 183 184dnl Macro for checking if an Erlang library is installed, and to 185dnl determine its version 186 187# AC_ERLANG_CHECK_LIB(LIBRARY, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) 188# ------------------------------------------------------------------- 189AC_DEFUN([AC_ERLANG_CHECK_LIB], 190[AC_REQUIRE([AC_ERLANG_PATH_ERLC])[]dnl 191AC_REQUIRE([AC_ERLANG_PATH_ERL])[]dnl 192AC_CACHE_CHECK([for Erlang/OTP '$1' library subdirectory], 193 [erlang_cv_lib_dir_$1], 194 [AC_LANG_PUSH(Erlang)[]dnl 195 AC_RUN_IFELSE( 196 [AC_LANG_PROGRAM([], [dnl 197 ReturnValue = case code:lib_dir("[$1]") of 198 {error, bad_name} -> 199 file:write_file("conftest.out", "not found\n"), 200 1; 201 LibDir -> 202 file:write_file("conftest.out", LibDir), 203 0 204 end, 205 halt(ReturnValue)])], 206 [erlang_cv_lib_dir_$1=`cat conftest.out`], 207 [if test ! -f conftest.out; then 208 AC_MSG_FAILURE([test Erlang program execution failed]) 209 else 210 erlang_cv_lib_dir_$1="not found" 211 fi]) 212 AC_LANG_POP(Erlang)[]dnl 213 ]) 214AC_CACHE_CHECK([for Erlang/OTP '$1' library version], 215 [erlang_cv_lib_ver_$1], 216 [AS_IF([test "$erlang_cv_lib_dir_$1" = "not found"], 217 [erlang_cv_lib_ver_$1="not found"], 218 [erlang_cv_lib_ver_$1=`echo "$erlang_cv_lib_dir_$1" | sed -n -e 's,^.*-\([[^/-]]*\)$,\1,p'`])[]dnl 219 ]) 220AC_SUBST([ERLANG_LIB_DIR_$1], [$erlang_cv_lib_dir_$1]) 221AC_SUBST([ERLANG_LIB_VER_$1], [$erlang_cv_lib_ver_$1]) 222AS_IF([test "$erlang_cv_lib_dir_$1" = "not found"], [$3], [$2]) 223])# AC_ERLANG_CHECK_LIB 224 225 226 227dnl Determines the Erlang/OTP root directory 228 229# AC_ERLANG_SUBST_ROOT_DIR 230# --------------- 231AC_DEFUN([AC_ERLANG_SUBST_ROOT_DIR], 232[AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl 233AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl 234AC_CACHE_CHECK([for Erlang/OTP root directory], 235 [erlang_cv_root_dir], 236 [AC_LANG_PUSH(Erlang)[]dnl 237 AC_RUN_IFELSE( 238 [AC_LANG_PROGRAM([], [dnl 239 RootDir = code:root_dir(), 240 file:write_file("conftest.out", RootDir), 241 ReturnValue = 0, 242 halt(ReturnValue)])], 243 [erlang_cv_root_dir=`cat conftest.out`], 244 [AC_MSG_FAILURE([test Erlang program execution failed])]) 245 AC_LANG_POP(Erlang)[]dnl 246 ]) 247AC_SUBST([ERLANG_ROOT_DIR], [$erlang_cv_root_dir]) 248])# AC_ERLANG_SUBST_ROOT_DIR 249 250# AC_ERLANG_SUBST_LIB_DIR 251# --------------- 252AC_DEFUN([AC_ERLANG_SUBST_LIB_DIR], 253[AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl 254AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl 255AC_CACHE_CHECK([for Erlang/OTP library base directory], 256 [erlang_cv_lib_dir], 257 [AC_LANG_PUSH(Erlang)[]dnl 258 AC_RUN_IFELSE( 259 [AC_LANG_PROGRAM([], [dnl 260 LibDir = code:lib_dir(), 261 file:write_file("conftest.out", LibDir), 262 ReturnValue = 0, 263 halt(ReturnValue)])], 264 [erlang_cv_lib_dir=`cat conftest.out`], 265 [AC_MSG_FAILURE([test Erlang program execution failed])]) 266 AC_LANG_POP(Erlang)[]dnl 267 ]) 268AC_SUBST([ERLANG_LIB_DIR], [$erlang_cv_lib_dir]) 269])# AC_ERLANG_SUBST_LIB_DIR 270 271 272dnl Directories for installing Erlang/OTP packages are separated from the 273dnl directories determined by running the Erlang/OTP installation that is used 274dnl for building. 275 276 277# AC_ERLANG_SUBST_INSTALL_LIB_DIR 278# --------------- 279AC_DEFUN([AC_ERLANG_SUBST_INSTALL_LIB_DIR], 280[AC_MSG_CHECKING([for Erlang/OTP library installation base directory]) 281AC_ARG_VAR([ERLANG_INSTALL_LIB_DIR], 282 [Erlang/OTP library installation base directory [LIBDIR/erlang/lib]]) 283if test -n "$ERLANG_INSTALL_LIB_DIR"; then 284 AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR]) 285else 286 AC_SUBST([ERLANG_INSTALL_LIB_DIR], ['${libdir}/erlang/lib']) 287 AC_MSG_RESULT([$libdir/erlang/lib]) 288fi 289])# AC_ERLANG_SUBST_INSTALL_LIB_DIR 290 291 292# AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR(PACKAGE_TARNAME, PACKAGE_VERSION) 293# --------------- 294AC_DEFUN([AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR], 295[AC_REQUIRE([AC_ERLANG_SUBST_INSTALL_LIB_DIR])[]dnl 296AC_MSG_CHECKING([for Erlang/OTP '$1' library installation subdirectory]) 297AC_ARG_VAR([ERLANG_INSTALL_LIB_DIR_$1], 298 [Erlang/OTP '$1' library installation subdirectory [ERLANG_INSTALL_LIB_DIR/$1-$2]]) 299if test -n "$ERLANG_INSTALL_LIB_DIR_$1"; then 300 AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR_$1]) 301else 302 AC_SUBST([ERLANG_INSTALL_LIB_DIR_$1], ['${ERLANG_INSTALL_LIB_DIR}/$1-$2']) 303 AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR/$1-$2]) 304fi 305])# AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR 306 307