1# 2# Copyright (c) 2019 Brent Cook 3# 4# Permission to use, copy, modify, and distribute this software for any 5# purpose with or without fee is hereby granted, provided that the above 6# copyright notice and this permission notice appear in all copies. 7# 8# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 16AC_INIT([OpenBGPD], m4_esyscmd([tr -d '\n' < VERSION])) 17 18AC_CANONICAL_HOST 19AM_INIT_AUTOMAKE([subdir-objects foreign]) 20AC_CONFIG_MACRO_DIR([m4]) 21m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 22AC_PROG_CC([cc gcc]) 23 24case $host_os in 25 *darwin*) 26 HOST_OS=darwin 27 AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV]) 28 ;; 29 *freebsd*) 30 HOST_OS=freebsd 31 ;; 32 *linux*) 33 HOST_OS=linux 34 AM_CFLAGS="-D_DEFAULT_SOURCE -D_BSD_SOURCE -D_GNU_SOURCE" 35 AC_DEFINE([SPT_TYPE], [SPT_REUSEARGV]) 36 ;; 37 *netbsd*) 38 HOST_OS=netbsd 39 ;; 40 *openbsd*) 41 HOST_OS=openbsd 42 AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD has __bounded__]) 43 AC_DEFINE([HAVE_ATTRIBUTE__DEAD], [1], [OpenBSD has __dead]) 44 ;; 45 *solaris*) 46 HOST_OS=solaris 47 AM_CFLAGS="-D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP" 48 ;; 49 *) ;; 50esac 51 52AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin]) 53AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd]) 54AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux]) 55AM_CONDITIONAL([HOST_NETBSD], [test x$HOST_OS = xnetbsd]) 56AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris]) 57 58AM_CONDITIONAL([HAVE_CARP], [test x$HOST_OS = xopenbsd]) 59AM_CONDITIONAL([HAVE_PFKEY], [test x$HOST_OS = xopenbsd]) 60AM_CONDITIONAL([HAVE_PFTABLE], [test x$HOST_OS = xopenbsd]) 61AM_CONDITIONAL([HAVE_KROUTE], [test x$HOST_OS = xopenbsd]) 62 63AC_PROG_SED 64AC_PROG_CC 65AC_PROG_CC_STDC 66AM_PROG_CC_C_O 67AC_PROG_LIBTOOL 68AC_PROG_YACC 69 70AC_ARG_ENABLE(warnings, 71 AS_HELP_STRING([--disable-warnings], 72 [ enable compiler warnings [default=enabled]]), 73 [case $enableval in 74 yes) enable_warnings=yes;; 75 no) enable_warnings=no;; 76 *) enable_warnings=yes;; esac], 77 enable_warnings=yes) 78 79if test "$enable_warnings" = yes; then 80 AM_CFLAGS="$AM_CFLAGS -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual -Wsign-compare" 81 82 save_cflags="$CFLAGS" 83 CFLAGS=-Wno-pointer-sign 84 AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign]) 85 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], 86 [AC_MSG_RESULT([yes])] 87 [WARN_CFLAGS=-Wno-pointer-sign], 88 [AC_MSG_RESULT([no])] 89 ) 90 AM_CFLAGS="$AM_CFLAGS $WARN_CFLAGS" 91 CFLAGS="$save_cflags" 92fi 93 94AC_MSG_CHECKING([if compiling with clang]) 95AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ 96#ifndef __clang__ 97 not clang 98#endif 99 ]])], 100 [AC_MSG_RESULT([yes])] 101 [CLANG_FLAGS=-Qunused-arguments], 102 [AC_MSG_RESULT([no])] 103) 104AM_CFLAGS="$AM_CFLAGS $CLANG_FLAGS" 105AM_LDFLAGS="$LDFLAGS $CLANG_FLAGS" 106AC_SUBST(AM_CFLAGS) 107AC_SUBST(AM_LDFLAGS) 108 109# check functions that are expected to be in libc 110AC_CHECK_FUNCS([arc4random asprintf explicit_bzero]) 111AC_CHECK_FUNCS([getentropy reallocarray recallocarray freezero]) 112AC_CHECK_FUNCS([setproctitle setgroups]) 113AC_CHECK_FUNCS([setregid setresgid setreuid setresuid]) 114AC_CHECK_FUNCS([strlcat strlcpy strtonum sysconf]) 115AC_CHECK_FUNCS([pledge unveil]) 116AC_CHECK_FUNCS([SipHash]) 117AC_CHECK_FUNCS([getdtablecount getrtable]) 118AC_CHECK_FUNCS([strnvis]) 119 120dnl NetBSD added an strnvis and unfortunately made it incompatible with the 121dnl existing one in OpenBSD and Linux's libbsd (the former having existed 122dnl for over ten years). Despite this incompatibility being reported during 123dnl development (see http://gnats.netbsd.org/44977) they still shipped it. 124dnl Even more unfortunately FreeBSD and later MacOS picked up this incompatible 125dnl implementation. Try to detect this mess, and assume the only safe option 126dnl if we're cross compiling. 127dnl 128dnl OpenBSD, 2001: strnvis(char *dst, const char *src, size_t dlen, int flag); 129dnl NetBSD: 2012, strnvis(char *dst, size_t dlen, const char *src, int flag); 130if test "x$ac_cv_func_strnvis" = "xyes"; then 131 AC_MSG_CHECKING([for working strnvis]) 132 AC_RUN_IFELSE( 133 [AC_LANG_PROGRAM([[ 134#include <signal.h> 135#include <stdlib.h> 136#include <string.h> 137#include <vis.h> 138static void sighandler(int sig) { _exit(1); } 139 ]], [[ 140 char dst[16]; 141 142 signal(SIGSEGV, sighandler); 143 if (strnvis(dst, "src", 4, 0) && strcmp(dst, "src") == 0) 144 exit(0); 145 exit(1) 146 ]])], 147 [AC_MSG_RESULT([yes])], 148 [AC_MSG_RESULT([no]) 149 ac_cv_broken_strnvis="yes" ], 150 [AC_MSG_WARN([cross compiling: assuming broken]) 151 ac_cv_broken_strnvis="yes" ] 152 ) 153fi 154 155 156AC_CHECK_HEADERS([endian.h]) 157AC_CHECK_HEADERS([netinet/ip_ipsp.h], [], [], [[#include <sys/socket.h>]]) 158AC_CHECK_HEADERS([linux/in6.h]) 159 160# check auxiliary libraries that might contain other functions 161AC_SEARCH_LIBS([arc4random], [crypto]) 162AC_SEARCH_LIBS([clock_gettime],[rt posix4]) 163AC_SEARCH_LIBS([ibuf_open], [util]) 164AC_SEARCH_LIBS([SHA512Init], [md]) 165AC_SEARCH_LIBS([inet_net_pton],[resolv]) 166AC_SEARCH_LIBS([fmt_scaled], [util]) 167 168AC_CHECK_FUNCS([arc4random clock_gettime ibuf_open SHA512Init]) 169AC_CHECK_FUNCS([inet_net_pton fmt_scaled]) 170 171# Share test results with automake 172AM_CONDITIONAL([HAVE_ARC4RANDOM], [test "x$ac_cv_func_arc4random" = xyes]) 173AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) 174AM_CONDITIONAL([HAVE_CLOSEFROM], [test "x$ac_cv_func_closefrom" = xyes]) 175AM_CONDITIONAL([HAVE_CLOCK_GETRES], [test "x$ac_cv_func_clock_getres" = xyes]) 176AM_CONDITIONAL([HAVE_CLOCK_GETTIME], [test "x$ac_cv_func_clock_gettime" = xyes]) 177AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes]) 178AM_CONDITIONAL([HAVE_FREEZERO], [test "x$ac_cv_func_freezero" = xyes]) 179AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes]) 180AM_CONDITIONAL([HAVE_IMSG], [test "x$ac_cv_func_ibuf_open" = xyes]) 181AM_CONDITIONAL([HAVE_MD5], [test "x$ac_cv_func_MD5Init" = xyes]) 182AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes]) 183AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes]) 184AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes]) 185AM_CONDITIONAL([HAVE_RECALLOCARRAY], [test "x$ac_cv_func_recallocarray" = xyes]) 186AM_CONDITIONAL([HAVE_SETGROUPS], [test "x$ac_cv_func_setgroups" = xyes]) 187AM_CONDITIONAL([HAVE_SETRESGID], [test "x$ac_cv_func_setresgid" = xyes]) 188AM_CONDITIONAL([HAVE_SETRESUID], [test "x$ac_cv_func_setresuid" = xyes]) 189AM_CONDITIONAL([HAVE_SETPROCTITLE], [test "x$ac_cv_func_setproctitle" = xyes]) 190AM_CONDITIONAL([HAVE_SHA512], [test "x$ac_cv_func_SHA512Init" = xyes]) 191AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes]) 192AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes]) 193AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes]) 194AM_CONDITIONAL([HAVE_SYSCONF], [test "x$ac_cv_func_sysconf" = xyes]) 195AM_CONDITIONAL([HAVE_PLEDGE], [test "x$ac_cv_func_pledge" = xyes]) 196AM_CONDITIONAL([HAVE_UNVEIL], [test "x$ac_cv_func_unveil" = xyes]) 197AM_CONDITIONAL([HAVE_SIPHASH], [test "x$ac_cv_func_SipHash" = xyes]) 198AM_CONDITIONAL([HAVE_GETDTABLECOUNT], [test "x$ac_cv_func_getdtablecount" = xyes]) 199AM_CONDITIONAL([HAVE_GETRTABLE], [test "x$ac_cv_func_getrtable" = xyes]) 200AM_CONDITIONAL([HAVE_STRNVIS], [test "x$ac_cv_func_strnvis" = xyes]) 201AM_CONDITIONAL([BROKEN_STRNVIS], [test "x$ac_cv_broken_strnvis" = xyes]) 202AM_CONDITIONAL([HAVE_INET_NET_PTON], [test "x$ac_cv_func_inet_net_pton" = xyes]) 203AM_CONDITIONAL([HAVE_FMT_SCALED], [test "x$ac_cv_func_fmt_scaled" = xyes]) 204 205# overrides for arc4random implementations with known issues 206AM_CONDITIONAL([HAVE_ARC4RANDOM], 207 [test "x$HOST_OS" != xdarwin \ 208 -a "x$HOST_OS" != xfreebsd \ 209 -a "x$HOST_OS" != xnetbsd \ 210 -a "x$ac_cv_func_arc4random" = xyes]) 211 212AC_CHECK_HEADERS([err.h sha2.h]) 213 214AC_CHECK_MEMBERS([struct sockaddr_in.sin_len], , , 215 [ #include <netdb.h> 216 #include <netinet/in.h> 217 #include <sys/socket.h> ] 218) 219 220AC_CHECK_MEMBERS([struct tcp_md5sig.tcpm_key], , , 221 [ #include <sys/socket.h> 222 #include <netinet/in.h> 223 #include <netinet/tcp.h> ] 224) 225AM_CONDITIONAL([HAVE_LINUX_TCPMD5], [test "x$ac_cv_member_struct_tcp_md5sig_tcpm_key" = xyes]) 226 227AC_ARG_WITH([privsep-user], 228 AS_HELP_STRING([--with-privsep-user=user], 229 [Privilege separation user for bgpd to use]), 230 PRIVSEP_USER="$withval", 231 PRIVSEP_USER="_bgpd" 232) 233AC_DEFINE_UNQUOTED(BGPD_USER, "$PRIVSEP_USER", [Unprivileged user]) 234AC_SUBST(PRIVSEP_USER) 235 236# workaround the issue that there is no autoconf release supporting 237# runstatedir but many linux distros patched their versions instead 238# Check if the variable is set, if not use a basic default. 239AC_ARG_WITH([runstatedir], 240 AS_HELP_STRING([--with-runstatedir=DIR], 241 [Location for bgpd control socket [LOCALSTATEDIR/run]]), 242 runstatedir="$withval" 243) 244if test "x$runstatedir" = x; then 245 runstatedir='${localstatedir}/run' 246 AC_SUBST(runstatedir) 247fi 248 249AC_CONFIG_FILES([ 250 Makefile 251 include/Makefile 252 compat/Makefile 253 src/bgpctl/Makefile 254 src/bgpd/Makefile 255]) 256 257AC_OUTPUT 258