erlang.m4 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. # This file is part of Autoconf. -*- Autoconf -*-
  2. # Erlang/OTP language support.
  3. # Copyright (C) 2006, 2008-2012 Free Software Foundation, Inc.
  4. # This file is part of Autoconf. This program is free
  5. # software; you can redistribute it and/or modify it under the
  6. # terms of the GNU General Public License as published by the
  7. # Free Software Foundation, either version 3 of the License, or
  8. # (at your option) 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. # Under Section 7 of GPL version 3, you are granted additional
  16. # permissions described in the Autoconf Configure Script Exception,
  17. # version 3.0, as published by the Free Software Foundation.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # and a copy of the Autoconf Configure Script Exception along with
  21. # this program; see the files COPYINGv3 and COPYING.EXCEPTION
  22. # respectively. If not, see <http://www.gnu.org/licenses/>.
  23. # Written by Romain Lenglet.
  24. # Table of Contents:
  25. #
  26. # 0. Utility macros
  27. #
  28. # 1. Language selection
  29. # and routines to produce programs in a given language.
  30. #
  31. # 2. Producing programs in a given language.
  32. #
  33. # 3. Looking for a compiler
  34. # And possibly the associated preprocessor.
  35. ## ------------------- ##
  36. ## 0. Utility macros. ##
  37. ## ------------------- ##
  38. # AC_ERLANG_PATH_ERLC([VALUE-IF-NOT-FOUND], [PATH])
  39. # -------------------------------------------------
  40. AC_DEFUN([AC_ERLANG_PATH_ERLC],
  41. [AC_ARG_VAR([ERLC], [Erlang/OTP compiler command [autodetected]])dnl
  42. if test -n "$ERLC"; then
  43. AC_MSG_CHECKING([for erlc])
  44. AC_MSG_RESULT([$ERLC])
  45. else
  46. AC_PATH_TOOL(ERLC, erlc, [$1], [$2])
  47. fi
  48. AC_ARG_VAR([ERLCFLAGS], [Erlang/OTP compiler flags [none]])dnl
  49. ])
  50. # AC_ERLANG_NEED_ERLC([PATH])
  51. # ---------------------------
  52. AC_DEFUN([AC_ERLANG_NEED_ERLC],
  53. [AC_ERLANG_PATH_ERLC([not found], [$1])
  54. if test "$ERLC" = "not found"; then
  55. AC_MSG_ERROR([Erlang/OTP compiler (erlc) not found but required])
  56. fi
  57. ])
  58. # AC_ERLANG_PATH_ERL([VALUE-IF-NOT-FOUND], [PATH])
  59. # ------------------------------------------------
  60. AC_DEFUN([AC_ERLANG_PATH_ERL],
  61. [AC_ARG_VAR([ERL], [Erlang/OTP interpreter command [autodetected]])dnl
  62. if test -n "$ERL"; then
  63. AC_MSG_CHECKING([for erl])
  64. AC_MSG_RESULT([$ERL])
  65. else
  66. AC_PATH_TOOL(ERL, erl, [$1], [$2])[]dnl
  67. fi
  68. ])
  69. # AC_ERLANG_NEED_ERL([PATH])
  70. # --------------------------
  71. AC_DEFUN([AC_ERLANG_NEED_ERL],
  72. [AC_ERLANG_PATH_ERL([not found], [$1])
  73. if test "$ERL" = "not found"; then
  74. AC_MSG_ERROR([Erlang/OTP interpreter (erl) not found but required])
  75. fi
  76. ])
  77. ## ----------------------- ##
  78. ## 1. Language selection. ##
  79. ## ----------------------- ##
  80. # AC_LANG(Erlang)
  81. # ---------------
  82. AC_LANG_DEFINE([Erlang], [erl], [ERL], [ERLC], [],
  83. [ac_ext=erl
  84. ac_compile='$ERLC $ERLCFLAGS -b beam conftest.$ac_ext >&AS_MESSAGE_LOG_FD'
  85. 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'
  86. ])
  87. # AC_LANG_ERLANG
  88. # --------------
  89. AU_DEFUN([AC_LANG_ERLANG], [AC_LANG(Erlang)])
  90. ## ----------------------- ##
  91. ## 2. Producing programs. ##
  92. ## ----------------------- ##
  93. # AC_LANG_PROGRAM(Erlang)([PROLOGUE], [BODY])
  94. # -------------------------------------------
  95. m4_define([AC_LANG_PROGRAM(Erlang)],
  96. [[-module(conftest).
  97. -export([start/0]).]]
  98. [$1
  99. start() ->
  100. $2
  101. .
  102. ])
  103. # _AC_LANG_NULL_PROGRAM(Erlang)
  104. # -----------------------------
  105. # Produce source that does nothing.
  106. m4_define([_AC_LANG_NULL_PROGRAM(Erlang)],
  107. [AC_LANG_PROGRAM([], [halt(0)])])
  108. # _AC_LANG_IO_PROGRAM(Erlang)
  109. # ---------------------------
  110. # Produce source that performs I/O.
  111. m4_define([_AC_LANG_IO_PROGRAM(Erlang)],
  112. [AC_LANG_PROGRAM([], [dnl
  113. ReturnValue = case file:write_file("conftest.out", "") of
  114. {error, _} -> 1;
  115. ok -> 0
  116. end,
  117. halt(ReturnValue)])])
  118. ## -------------------------------------------- ##
  119. ## 3. Looking for Compilers and Preprocessors. ##
  120. ## -------------------------------------------- ##
  121. # AC_LANG_PREPROC(Erlang)
  122. # -----------------------
  123. # Find the Erlang preprocessor. Must be AC_DEFUN'd to be AC_REQUIRE'able.
  124. AC_DEFUN([AC_LANG_PREPROC(Erlang)],
  125. [m4_warn([syntax],
  126. [$0: No preprocessor defined for ]_AC_LANG)])
  127. # AC_LANG_COMPILER(Erlang)
  128. # ------------------------
  129. # Find the Erlang compiler. Must be AC_DEFUN'd to be AC_REQUIRE'able.
  130. AC_DEFUN([AC_LANG_COMPILER(Erlang)],
  131. [AC_REQUIRE([AC_ERLANG_PATH_ERLC])])
  132. # AC_ERLANG_CHECK_LIB(LIBRARY, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  133. # ----------------------------------------------------------------------
  134. # Macro for checking if an Erlang library is installed, and to
  135. # determine its version.
  136. AC_DEFUN([AC_ERLANG_CHECK_LIB],
  137. [AC_REQUIRE([AC_ERLANG_PATH_ERLC])[]dnl
  138. AC_REQUIRE([AC_ERLANG_PATH_ERL])[]dnl
  139. AC_CACHE_CHECK([for Erlang/OTP '$1' library subdirectory],
  140. [ac_cv_erlang_lib_dir_$1],
  141. [AC_LANG_PUSH(Erlang)[]dnl
  142. AC_RUN_IFELSE(
  143. [AC_LANG_PROGRAM([], [dnl
  144. ReturnValue = case code:lib_dir("[$1]") of
  145. {error, bad_name} ->
  146. file:write_file("conftest.out", "not found\n"),
  147. 1;
  148. LibDir ->
  149. file:write_file("conftest.out", LibDir),
  150. 0
  151. end,
  152. halt(ReturnValue)])],
  153. [ac_cv_erlang_lib_dir_$1=`cat conftest.out`
  154. rm -f conftest.out],
  155. [if test ! -f conftest.out; then
  156. AC_MSG_FAILURE([test Erlang program execution failed])
  157. else
  158. ac_cv_erlang_lib_dir_$1="not found"
  159. rm -f conftest.out
  160. fi])
  161. AC_LANG_POP(Erlang)[]dnl
  162. ])
  163. AC_CACHE_CHECK([for Erlang/OTP '$1' library version],
  164. [ac_cv_erlang_lib_ver_$1],
  165. [AS_IF([test "$ac_cv_erlang_lib_dir_$1" = "not found"],
  166. [ac_cv_erlang_lib_ver_$1="not found"],
  167. [ac_cv_erlang_lib_ver_$1=`AS_ECHO(["$ac_cv_erlang_lib_dir_$1"]) | sed -n -e 's,^.*-\([[^/-]]*\)$,\1,p'`])[]dnl
  168. ])
  169. AC_SUBST([ERLANG_LIB_DIR_$1], [$ac_cv_erlang_lib_dir_$1])
  170. AC_SUBST([ERLANG_LIB_VER_$1], [$ac_cv_erlang_lib_ver_$1])
  171. AS_IF([test "$ac_cv_erlang_lib_dir_$1" = "not found"], [$3], [$2])
  172. ])# AC_ERLANG_CHECK_LIB
  173. # AC_ERLANG_SUBST_ROOT_DIR
  174. # ------------------------
  175. # Determines the Erlang/OTP root directory.
  176. AC_DEFUN([AC_ERLANG_SUBST_ROOT_DIR],
  177. [AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl
  178. AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
  179. AC_CACHE_CHECK([for Erlang/OTP root directory],
  180. [ac_cv_erlang_root_dir],
  181. [AC_LANG_PUSH(Erlang)[]dnl
  182. AC_RUN_IFELSE(
  183. [AC_LANG_PROGRAM([], [dnl
  184. RootDir = code:root_dir(),
  185. file:write_file("conftest.out", RootDir),
  186. ReturnValue = 0,
  187. halt(ReturnValue)])],
  188. [ac_cv_erlang_root_dir=`cat conftest.out`
  189. rm -f conftest.out],
  190. [rm -f conftest.out
  191. AC_MSG_FAILURE([test Erlang program execution failed])])
  192. AC_LANG_POP(Erlang)[]dnl
  193. ])
  194. AC_SUBST([ERLANG_ROOT_DIR], [$ac_cv_erlang_root_dir])
  195. ])# AC_ERLANG_SUBST_ROOT_DIR
  196. # AC_ERLANG_SUBST_LIB_DIR
  197. # -----------------------
  198. AC_DEFUN([AC_ERLANG_SUBST_LIB_DIR],
  199. [AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl
  200. AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
  201. AC_CACHE_CHECK([for Erlang/OTP library base directory],
  202. [ac_cv_erlang_lib_dir],
  203. [AC_LANG_PUSH(Erlang)[]dnl
  204. AC_RUN_IFELSE(
  205. [AC_LANG_PROGRAM([], [dnl
  206. LibDir = code:lib_dir(),
  207. file:write_file("conftest.out", LibDir),
  208. ReturnValue = 0,
  209. halt(ReturnValue)])],
  210. [ac_cv_erlang_lib_dir=`cat conftest.out`
  211. rm -f conftest.out],
  212. [rm -f conftest.out
  213. AC_MSG_FAILURE([test Erlang program execution failed])])
  214. AC_LANG_POP(Erlang)[]dnl
  215. ])
  216. AC_SUBST([ERLANG_LIB_DIR], [$ac_cv_erlang_lib_dir])
  217. ])# AC_ERLANG_SUBST_LIB_DIR
  218. # AC_ERLANG_SUBST_INSTALL_LIB_DIR
  219. # -------------------------------
  220. # Directories for installing Erlang/OTP packages are separated from the
  221. # directories determined by running the Erlang/OTP installation that is used
  222. # for building.
  223. AC_DEFUN([AC_ERLANG_SUBST_INSTALL_LIB_DIR],
  224. [AC_MSG_CHECKING([for Erlang/OTP library installation base directory])
  225. AC_ARG_VAR([ERLANG_INSTALL_LIB_DIR],
  226. [Erlang/OTP library installation base directory [LIBDIR/erlang/lib]])
  227. if test -n "$ERLANG_INSTALL_LIB_DIR"; then
  228. AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR])
  229. else
  230. AC_SUBST([ERLANG_INSTALL_LIB_DIR], ['${libdir}/erlang/lib'])
  231. AC_MSG_RESULT([$libdir/erlang/lib])
  232. fi
  233. ])# AC_ERLANG_SUBST_INSTALL_LIB_DIR
  234. # AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR(PACKAGE_TARNAME, PACKAGE_VERSION)
  235. # --------------------------------------------------------------------
  236. AC_DEFUN([AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR],
  237. [AC_REQUIRE([AC_ERLANG_SUBST_INSTALL_LIB_DIR])[]dnl
  238. AC_MSG_CHECKING([for Erlang/OTP '$1' library installation subdirectory])
  239. AC_ARG_VAR([ERLANG_INSTALL_LIB_DIR_$1],
  240. [Erlang/OTP '$1' library installation subdirectory
  241. [ERLANG_INSTALL_LIB_DIR/$1-$2]])
  242. if test -n "$ERLANG_INSTALL_LIB_DIR_$1"; then
  243. AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR_$1])
  244. else
  245. AC_SUBST([ERLANG_INSTALL_LIB_DIR_$1], ['${ERLANG_INSTALL_LIB_DIR}/$1-$2'])
  246. AC_MSG_RESULT([$ERLANG_INSTALL_LIB_DIR/$1-$2])
  247. fi
  248. ])# AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR
  249. # AC_ERLANG_SUBST_ERTS_VER
  250. # ------------------------
  251. # Determines the Erlang runtime system version.
  252. AC_DEFUN([AC_ERLANG_SUBST_ERTS_VER],
  253. [AC_REQUIRE([AC_ERLANG_NEED_ERLC])[]dnl
  254. AC_REQUIRE([AC_ERLANG_NEED_ERL])[]dnl
  255. AC_CACHE_CHECK([for Erlang/OTP ERTS version],
  256. [ac_cv_erlang_erts_ver],
  257. [AC_LANG_PUSH([Erlang])[]dnl
  258. AC_RUN_IFELSE(
  259. [AC_LANG_PROGRAM([], [dnl
  260. Version = erlang:system_info(version),
  261. file:write_file("conftest.out", Version),
  262. ReturnValue = 0,
  263. halt(ReturnValue)])],
  264. [ac_cv_erlang_erts_ver=`cat conftest.out`
  265. rm -f conftest.out],
  266. [rm -f conftest.out
  267. AC_MSG_FAILURE([test Erlang program execution failed])])
  268. AC_LANG_POP([Erlang])[]dnl
  269. ])
  270. AC_SUBST([ERLANG_ERTS_VER], [$ac_cv_erlang_erts_ver])
  271. ])# AC_ERLANG_SUBST_ERTS_VER