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