configure.ac 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. # Configure script for c++tools
  2. # Copyright (C) 2020-2022 Free Software Foundation, Inc.
  3. # Written by Nathan Sidwell <nathan@acm.org> while at FaceBook
  4. #
  5. # This file is free software; you can redistribute it and/or modify it
  6. # under the terms of the GNU General Public License as published by
  7. # the 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, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # 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; see the file COPYING3. If not see
  17. # <http://www.gnu.org/licenses/>.
  18. # C++ has grown a C++20 mapper server. This may be used to provide
  19. # and/or learn and/or build required modules. This sample server
  20. # shows how the protocol introduced by wg21.link/p1184 may be used.
  21. # By default g++ uses an in-process mapper.
  22. sinclude(../config/acx.m4)
  23. sinclude(../config/ax_lib_socket_nsl.m4)
  24. AC_INIT(c++tools)
  25. AC_CONFIG_SRCDIR([server.cc])
  26. # Determine the noncanonical names used for directories.
  27. ACX_NONCANONICAL_TARGET
  28. AC_CANONICAL_SYSTEM
  29. AC_PROG_INSTALL
  30. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
  31. AC_SUBST(INSTALL_PROGRAM)
  32. AC_PROG_CXX
  33. MISSING=`cd $ac_aux_dir && ${PWDCMD-pwd}`/missing
  34. AC_CHECK_PROGS([AUTOCONF], [autoconf], [$MISSING autoconf])
  35. AC_CHECK_PROGS([AUTOHEADER], [autoheader], [$MISSING autoheader])
  36. AC_LANG(C++)
  37. dnl Enabled by default
  38. AC_MSG_CHECKING([whether to build C++ tools])
  39. AC_ARG_ENABLE(c++-tools,
  40. [AS_HELP_STRING([--enable-c++-tools],
  41. [build auxiliary c++ tools])],
  42. cxx_aux_tools=$enableval,
  43. cxx_aux_tools=yes)
  44. AC_MSG_RESULT($cxx_aux_tools)
  45. CXX_AUX_TOOLS="$cxx_aux_tools"
  46. AC_SUBST(CXX_AUX_TOOLS)
  47. AC_ARG_ENABLE([maintainer-mode],
  48. AS_HELP_STRING([--enable-maintainer-mode],
  49. [enable maintainer mode. Add rules to rebuild configurey bits]),,
  50. [enable_maintainer_mode=no])
  51. case "$enable_maintainer_mode" in
  52. yes) maintainer_mode=yes ;;
  53. no) maintainer_mode=no ;;
  54. *) AC_MSG_ERROR([unknown maintainer mode $enable_maintainer_mode]) ;;
  55. esac
  56. AC_MSG_CHECKING([maintainer-mode])
  57. AC_MSG_RESULT([$maintainer_mode])
  58. test "$maintainer_mode" = yes && MAINTAINER=yes
  59. AC_SUBST(MAINTAINER)
  60. # Handle configuration of checking; for the tools in this directory we
  61. # default to release checking and stricter checks do not change this.
  62. AC_ARG_ENABLE(checking,
  63. [AS_HELP_STRING([[--enable-checking[=LIST]]],
  64. [enable expensive run-time checks. With LIST,
  65. enable only specific categories of checks.
  66. Categories are: yes,no,all,none,release.])],
  67. [ac_checking_flags="${enableval}"],[
  68. # Default to checking.
  69. ac_checking_flags=yes
  70. ])
  71. IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS="$IFS,"
  72. for check in release $ac_checking_flags
  73. do
  74. case $check in
  75. # these set all the flags to specific states
  76. yes|all|release|assert) ac_assert_checking=1 ; ;;
  77. no|none) ac_assert_checking= ; ;;
  78. *) ;;
  79. esac
  80. done
  81. IFS="$ac_save_IFS"
  82. if test x$ac_assert_checking != x ; then
  83. AC_DEFINE(ENABLE_ASSERT_CHECKING, 1,
  84. [Define if you want assertions enabled. This is a cheap check.])
  85. fi
  86. # Check whether --enable-default-pie was given.
  87. AC_ARG_ENABLE(default-pie,
  88. [AS_HELP_STRING([--enable-default-pie],
  89. [enable Position Independent Executable as default])],
  90. [PIEFLAG=-fPIE], [PIEFLAG=])
  91. AC_SUBST([PIEFLAG])
  92. # Check if O_CLOEXEC is defined by fcntl
  93. AC_CACHE_CHECK(for O_CLOEXEC, ac_cv_o_cloexec, [
  94. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  95. #include <fcntl.h>]], [[
  96. return open ("/dev/null", O_RDONLY | O_CLOEXEC);]])],
  97. [ac_cv_o_cloexec=yes],[ac_cv_o_cloexec=no])])
  98. if test $ac_cv_o_cloexec = yes; then
  99. AC_DEFINE(HOST_HAS_O_CLOEXEC, 1,
  100. [Define if O_CLOEXEC supported by fcntl.])
  101. fi
  102. AC_CHECK_HEADERS(sys/mman.h)
  103. # C++ Modules would like some networking features to provide the mapping
  104. # server. You can still use modules without them though.
  105. # The following network-related checks could probably do with some
  106. # Windows and other non-linux defenses and checking.
  107. # Local socket connectivity wants AF_UNIX networking
  108. # Check for AF_UNIX networking
  109. AC_CACHE_CHECK(for AF_UNIX, ac_cv_af_unix, [
  110. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  111. #include <sys/types.h>
  112. #include <sys/socket.h>
  113. #include <sys/un.h>
  114. #include <netinet/in.h>]],[[
  115. sockaddr_un un;
  116. un.sun_family = AF_UNSPEC;
  117. int fd = socket (AF_UNIX, SOCK_STREAM, 0);
  118. connect (fd, (sockaddr *)&un, sizeof (un));]])],
  119. [ac_cv_af_unix=yes],
  120. [ac_cv_af_unix=no])])
  121. if test $ac_cv_af_unix = yes; then
  122. AC_DEFINE(HAVE_AF_UNIX, 1,
  123. [Define if AF_UNIX supported.])
  124. fi
  125. # Remote socket connectivity wants AF_INET6 networking
  126. # Check for AF_INET6 networking
  127. AC_CACHE_CHECK(for AF_INET6, ac_cv_af_inet6, [
  128. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  129. #include <sys/types.h>
  130. #include <sys/socket.h>
  131. #include <netinet/in.h>
  132. #include <netdb.h>]],[[
  133. sockaddr_in6 in6;
  134. in6.sin6_family = AF_UNSPEC;
  135. struct addrinfo *addrs = 0;
  136. struct addrinfo hints;
  137. hints.ai_flags = 0;
  138. hints.ai_family = AF_INET6;
  139. hints.ai_socktype = SOCK_STREAM;
  140. hints.ai_protocol = 0;
  141. hints.ai_canonname = 0;
  142. hints.ai_addr = 0;
  143. hints.ai_next = 0;
  144. int e = getaddrinfo ("localhost", 0, &hints, &addrs);
  145. const char *str = gai_strerror (e);
  146. freeaddrinfo (addrs);
  147. int fd = socket (AF_INET6, SOCK_STREAM, 0);
  148. connect (fd, (sockaddr *)&in6, sizeof (in6));]])],
  149. [ac_cv_af_inet6=yes],
  150. [ac_cv_af_inet6=no])])
  151. if test $ac_cv_af_inet6 = yes; then
  152. AC_DEFINE(HAVE_AF_INET6, 1,
  153. [Define if AF_INET6 supported.])
  154. fi
  155. # Efficient server response wants epoll
  156. # Check for epoll_create, epoll_ctl, epoll_pwait
  157. AC_CACHE_CHECK(for epoll, ac_cv_epoll, [
  158. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  159. #include <sys/epoll.h>]],[[
  160. int fd = epoll_create (1);
  161. epoll_event ev;
  162. ev.events = EPOLLIN;
  163. ev.data.fd = 0;
  164. epoll_ctl (fd, EPOLL_CTL_ADD, 0, &ev);
  165. epoll_pwait (fd, 0, 0, -1, 0);]])],
  166. [ac_cv_epoll=yes],
  167. [ac_cv_epoll=no])])
  168. if test $ac_cv_epoll = yes; then
  169. AC_DEFINE(HAVE_EPOLL, 1,
  170. [Define if epoll_create, epoll_ctl, epoll_pwait provided.])
  171. fi
  172. # If we can't use epoll, try pselect.
  173. # Check for pselect
  174. AC_CACHE_CHECK(for pselect, ac_cv_pselect, [
  175. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  176. #include <sys/select.h>]],[[
  177. pselect (0, 0, 0, 0, 0, 0);]])],
  178. [ac_cv_pselect=yes],
  179. [ac_cv_pselect=no])])
  180. if test $ac_cv_pselect = yes; then
  181. AC_DEFINE(HAVE_PSELECT, 1,
  182. [Define if pselect provided.])
  183. fi
  184. # And failing that, use good old select.
  185. # If we can't even use this, the server is serialized.
  186. # Check for select
  187. AC_CACHE_CHECK(for select, ac_cv_select, [
  188. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  189. #include <sys/select.h>]],[[
  190. select (0, 0, 0, 0, 0);]])],
  191. [ac_cv_select=yes],
  192. [ac_cv_select=no])])
  193. if test $ac_cv_select = yes; then
  194. AC_DEFINE(HAVE_SELECT, 1,
  195. [Define if select provided.])
  196. fi
  197. # Avoid some fnctl calls by using accept4, when available.
  198. # Check for accept4
  199. AC_CACHE_CHECK(for accept4, ac_cv_accept4, [
  200. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  201. #include <sys/socket.h>]],[[
  202. int err = accept4 (1, 0, 0, SOCK_NONBLOCK);]])],
  203. [ac_cv_accept4=yes],
  204. [ac_cv_accept4=no])])
  205. if test $ac_cv_accept4 = yes; then
  206. AC_DEFINE(HAVE_ACCEPT4, 1,
  207. [Define if accept4 provided.])
  208. fi
  209. # For better server messages, look for a way to stringize network addresses
  210. # Check for inet_ntop
  211. AC_CACHE_CHECK(for inet_ntop, ac_cv_inet_ntop, [
  212. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  213. #include <arpa/inet.h>
  214. #include <netinet/in.h>]],[[
  215. sockaddr_in6 in6;
  216. char buf[INET6_ADDRSTRLEN];
  217. const char *str = inet_ntop (AF_INET6, &in6, buf, sizeof (buf));]])],
  218. [ac_cv_inet_ntop=yes],
  219. [ac_cv_inet_ntop=no])])
  220. if test $ac_cv_inet_ntop = yes; then
  221. AC_DEFINE(HAVE_INET_NTOP, 1,
  222. [Define if inet_ntop provided.])
  223. fi
  224. # Determine what GCC version number to use in filesystem paths.
  225. GCC_BASE_VER
  226. # Solaris needs libsocket and libnsl for socket functions before 11.4.
  227. # libcody uses those.
  228. save_LIBS="$LIBS"
  229. LIBS=
  230. AX_LIB_SOCKET_NSL
  231. NETLIBS="$LIBS"
  232. LIBS="$save_LIBS"
  233. AC_SUBST(NETLIBS)
  234. AC_CONFIG_HEADERS([config.h])
  235. AC_CONFIG_FILES([Makefile])
  236. AC_OUTPUT