]> arthur.barton.de Git - ngircd-alex.git/blobdiff - configure.ng
Don't abort startup when setgid/setuid() fails with EINVAL
[ngircd-alex.git] / configure.ng
index 25654f9cfbdfc78d2ef74de059a64cfeeb8e355f..0dccfbc5d466ad0f908909ab4b9a4c2ee7cb8ce7 100644 (file)
@@ -1,6 +1,6 @@
 #
 # ngIRCd -- The Next Generation IRC Daemon
-# Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors
+# Copyright (c)2001-2024 Alexander Barton (alex@barton.de) and Contributors
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -9,19 +9,27 @@
 # Please read the file COPYING, README and AUTHORS for more information.
 #
 
-define(VERSION_ID,esyscmd(git describe|sed -e 's/rel-//g'|sed -e 's/-/~/'|tr -d \\n))
+define(VERSION_ID,esyscmd([
+       V=`git describe 2>/dev/null | sed -e 's/rel-//g' | sed -e 's/-/~/'`;
+       [ -z "$V" -a -r configure ] \
+               && V=`grep "PACKAGE_STRING=" configure | cut -d"'" -f2 | cut -d' ' -f2`
+       ( [ -n "$V" ] && echo "$V" || echo "??" ) | tr -d '\n';
+]))
+
+m4_ifdef([AM_SILENT_RULES],
+       [m4_define([ng_color_tests], [color-tests])],
+       [m4_define([ng_color_tests], [])])
 
 # -- Initialisation --
 
-AC_PREREQ([2.67])
-AC_INIT([ngIRCd], VERSION_ID,
-       [ngircd-ml@ngircd.barton.de], [ngircd], [http://ngircd.barton.de/])
+AC_PREREQ([2.61])
+AC_INIT([ngIRCd],[VERSION_ID],[ngircd@lists.barton.de],[ngircd],[https://ngircd.barton.de/])
 
 AC_CONFIG_SRCDIR([src/ngircd/ngircd.c])
 AC_CONFIG_HEADER([src/config.h])
 AC_CANONICAL_HOST
 
-AM_INIT_AUTOMAKE([1.11])
+AM_INIT_AUTOMAKE([-Wall 1.10 foreign ]ng_color_tests)
 
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
@@ -30,6 +38,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 AH_TEMPLATE([DEBUG], [Define if debug-mode should be enabled])
 AH_TEMPLATE([HAVE_sockaddr_in_len], [Define if sockaddr_in.sin_len exists])
 AH_TEMPLATE([HAVE_socklen_t], [Define if socklen_t exists])
+AH_TEMPLATE([ICONV], [Define if libiconv can be used, e.g. for CHARCONV])
 AH_TEMPLATE([IDENTAUTH], [Define if the server should do IDENT requests])
 AH_TEMPLATE([IRCPLUS], [Define if IRC+ protocol should be used])
 AH_TEMPLATE([PAM], [Define if PAM should be used])
@@ -51,10 +60,13 @@ AC_PROG_CC_STDC
 
 # -- Helper programs --
 
+m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
+
 AC_PROG_AWK
 AC_PROG_INSTALL
 AC_PROG_LN_S
 AC_PROG_MAKE_SET
+AC_PROG_MKDIR_P
 AC_PROG_RANLIB
 
 # -- Compiler Features --
@@ -63,28 +75,78 @@ AC_C_CONST
 AC_C_INLINE
 __ng_PROTOTYPES__
 
-# -- Hard coded system and compiler dependencies/features/options ... --
+# -- Function Definitions --
 
 AC_DEFUN([GCC_STACK_PROTECT_CC],[
-  ssp_cc=yes
-  # we use -fstack-protector-all for the test to enfoce the use of the guard variable 
-  AC_MSG_CHECKING([whether ${CC} accepts -fstack-protector])
-  ssp_old_cflags="$CFLAGS"
-  CFLAGS="$CFLAGS -fstack-protector-all"
-  AC_TRY_LINK(,,, ssp_cc=no)
-  echo $ssp_cc
-  CFLAGS="$ssp_old_cflags"
-  if test "X$ssp_cc" = "Xyes"; then
-      CFLAGS="$CFLAGS -fstack-protector"
-      AC_DEFINE([ENABLE_SSP_CC], 1, [Define if SSP C support is enabled.])
-  fi
+       ssp_cc=yes
+       # Use -fstack-protector-all for the test to enfoce the use of the
+       # guard variable
+       AC_MSG_CHECKING([whether ${CC} accepts -fstack-protector])
+       ssp_old_cflags="$CFLAGS"
+       CFLAGS="$CFLAGS -fstack-protector-all"
+       AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],[],[ssp_cc=no])
+       echo $ssp_cc
+       CFLAGS="$ssp_old_cflags"
+       if test "X$ssp_cc" = "Xyes"; then
+               CFLAGS="$CFLAGS -fstack-protector"
+               AC_DEFINE([ENABLE_SSP_CC], 1, [Define if SSP C support is enabled.])
+       fi
+])
+
+AC_DEFUN([WORKING_GETADDRINFO],[
+       AC_CHECK_FUNCS([getaddrinfo],[
+               AC_MSG_CHECKING([whether getaddrinfo() works])
+               AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <string.h>
+int
+main(int argc, char **argv)
+{
+       struct addrinfo hints, *ai;
+       memset(&hints, 0, sizeof(hints));
+       hints.ai_flags = AI_PASSIVE;
+       hints.ai_socktype = SOCK_STREAM;
+       hints.ai_family = PF_UNSPEC;
+       if(getaddrinfo(NULL, "0", &hints, &ai) != 0)
+               return 1;
+       return 0;
+}
+               ]])],[
+               AC_DEFINE([HAVE_WORKING_GETADDRINFO], 1, [getaddrinfo(0)])
+               AC_MSG_RESULT(yes)
+               ],[
+               AC_MSG_RESULT(no)
+               ],[
+               AC_MSG_RESULT(no)
+               ])
+       ])
+])
+
+AC_DEFUN([GCC_W_NO_FORMAT_TRUNC],[
+       result=yes
+       AC_MSG_CHECKING([whether ${CC} accepts -Wno-format-truncation])
+       old_cflags="$CFLAGS"
+       CFLAGS="$CFLAGS -Werror -Wno-format-truncation"
+       AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],[],[result=no])
+       echo $result
+       if test "X$result" = "Xyes"; then
+               CFLAGS="$old_cflags -Wno-format-truncation"
+       else
+               CFLAGS="$old_cflags"
+       fi
 ])
 
+# -- Hard coded system and compiler dependencies/features/options ... --
+
 if test "$GCC" = "yes"; then
        # We are using the GNU C compiler. Good!
        CFLAGS="$CFLAGS -pipe -W -Wall -Wpointer-arith -Wstrict-prototypes"
 
        GCC_STACK_PROTECT_CC
+       GCC_W_NO_FORMAT_TRUNC
 fi
 
 case "$host_os" in
@@ -98,7 +160,7 @@ esac
 # Add additional CFLAGS, eventually specified on the command line:
 test -n "$CFLAGS_ADD" && CFLAGS="$CFLAGS $CFLAGS_ADD"
 
-CFLAGS="$CFLAGS -DSYSCONFDIR='\"\$(sysconfdir)\"'"
+CFLAGS="$CFLAGS -DSYSCONFDIR='\"\$(sysconfdir)\"' -DDOCDIR='\"\$(docdir)\"'"
 
 # -- Headers --
 
@@ -108,33 +170,49 @@ AC_HEADER_TIME
 
 # Required header files
 AC_CHECK_HEADERS([ \
-       fcntl.h netdb.h netinet/in.h netinet/in_systm.h stdlib.h string.h \
-       strings.h sys/socket.h sys/time.h unistd.h \
+               fcntl.h \
+               netdb.h \
+               netinet/in.h \
+               stdlib.h \
+               string.h \
+               strings.h \
+               sys/socket.h \
+               sys/time.h \
+               sys/types.h \
+               unistd.h \
        ],,AC_MSG_ERROR([required C header missing!]))
 
 # Optional header files
 AC_CHECK_HEADERS_ONCE([ \
-       arpa/inet.h inttypes.h malloc.h netinet/ip.h stdbool.h stddef.h \
-       stdint.h varargs.h \
-       ])
+       arpa/inet.h \
+       inttypes.h \
+       malloc.h \
+       netinet/in_systm.h \
+       netinet/ip.h \
+       stdbool.h \
+       stddef.h \
+       stdint.h \
+       sys/resource.h \
+       sys/un.h \
+       varargs.h \
+])
 
 # -- Datatypes --
 
 AC_MSG_CHECKING(whether socklen_t exists)
-AC_TRY_COMPILE([
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 #include <sys/types.h>
 #include <sys/socket.h>
-       ],[
+       ]],[[
        socklen_t a, b;
        a = 2; b = 4; a += b;
-       ],[
+       ]])],[
        AC_DEFINE(HAVE_socklen_t) AC_MSG_RESULT(yes)
        ],[
        AC_MSG_RESULT(no)
 ])
 
 AC_TYPE_PID_T
-AC_TYPE_SIGNAL
 AC_TYPE_SIZE_T
 AC_TYPE_SSIZE_T
 AC_TYPE_UID_T
@@ -152,11 +230,11 @@ AC_SEARCH_LIBS([memmove], [UTIL], [], [
        AC_MSG_ERROR([unable to find the memmove() function])
 ])
 # gethostbyname: Solaris libnsl
-AC_SEARCH_LIBS([gethostbyname], [nsl], [], [
+AC_SEARCH_LIBS([gethostbyname], [bind nsl network], [], [
        AC_MSG_ERROR([unable to find the gethostbyname() function])
 ])
 # bind: SVR4 libsocket
-AC_SEARCH_LIBS([bind], [socket], [], [
+AC_SEARCH_LIBS([bind], [socket network], [], [
        AC_MSG_ERROR([unable to find the bind() function])
 ])
 
@@ -167,16 +245,53 @@ AC_FUNC_STRFTIME
 
 # Required functions
 AC_CHECK_FUNCS([ \
-       alarm dup2 endpwent gethostbyaddr gethostbyname gethostname \
-       gettimeofday inet_ntoa memmove memset setsid socket strcasecmp \
-       strchr strcspn strerror strncasecmp strrchr strspn strstr \
+               alarm \
+               dup2 \
+               endpwent \
+               gethostbyaddr \
+               gethostbyname \
+               gethostname \
+               gettimeofday \
+               inet_ntoa \
+               memmove \
+               memset \
+               setsid \
+               socket \
+               strcasecmp \
+               strchr \
+               strcspn \
+               strerror \
+               strncasecmp \
+               strrchr \
+               strspn \
+               strstr \
        ],,
        AC_MSG_ERROR([required function missing!]))
 
 # Optional functions
-AC_CHECK_FUNCS_ONCE([ \
-       gai_strerror getaddrinfo getnameinfo inet_aton sigaction sigprocmask \
-       snprintf vsnprintf strdup strlcpy strlcat strtok_r waitpid])
+AC_CHECK_FUNCS_ONCE([
+       arc4random \
+       arc4random_stir \
+       gai_strerror \
+       getnameinfo \
+       inet_aton \
+       setgroups \
+       setrlimit \
+       sigaction \
+       sigprocmask \
+       snprintf \
+       strdup \
+       strlcat \
+       strlcpy \
+       strndup \
+       strsignal \
+       strtok_r \
+       unsetenv \
+       vsnprintf \
+       waitpid \
+])
+
+WORKING_GETADDRINFO
 
 # -- Configuration options --
 
@@ -369,9 +484,13 @@ AC_ARG_WITH(openssl,
                                CPPFLAGS="-I$withval/include $CPPFLAGS"
                                LDFLAGS="-L$withval/lib $LDFLAGS"
                        fi
-                       AC_CHECK_LIB(crypto, BIO_s_mem)
-                       AC_CHECK_LIB(ssl, SSL_library_init)
-                       AC_CHECK_FUNCS(SSL_library_init, x_ssl_openssl=yes,
+                       PKG_CHECK_MODULES([OPENSSL], [libssl libcrypto],
+                               [LIBS="$LIBS $OPENSSL_LIBS" CFLAGS="$CFLAGS $OPENSSL_CFLAGS"
+                               AC_DEFINE(HAVE_LIBSSL, 1)],
+                               [AC_CHECK_LIB(crypto, BIO_s_mem)
+                               AC_CHECK_LIB(ssl, SSL_new)]
+                       )
+                       AC_CHECK_FUNCS(SSL_new, x_ssl_openssl=yes,
                                AC_MSG_ERROR([Can't enable openssl])
                        )
                fi
@@ -406,6 +525,8 @@ if test "$x_ssl_openssl" = "yes"; then
        x_ssl_lib=openssl
 fi
 
+AM_CONDITIONAL(HAVE_SSL, [test $x_ssl_lib != "no"])
+
 # use TCP wrappers?
 
 x_tcpwrap_on=no
@@ -419,14 +540,18 @@ AC_ARG_WITH(tcp-wrappers,
                                LDFLAGS="-L$withval/lib $LDFLAGS"
                        fi
                        AC_MSG_CHECKING(for hosts_access)
+                       saved_LIBS="$LIBS"
                        LIBS="-lwrap $LIBS"
-                       AC_TRY_LINK([
+                       LIBS_END="-lwrap $LIBS_END"
+                       AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+#include <sys/types.h>
+#include <sys/socket.h>
 #include <tcpd.h>
 int allow_severity = 0;
 int deny_severity = 0;
-                               ],[
+                               ]],[[
                                tcpd_warn("link test");
-                               ],[
+                               ]])],[
                                AC_MSG_RESULT(yes)
                                AC_DEFINE(TCPWRAP, 1)
                                x_tcpwrap_on=yes
@@ -434,6 +559,7 @@ int deny_severity = 0;
                                AC_MSG_RESULT(no)
                                AC_MSG_ERROR([Can't enable TCP wrappers!])
                        ])
+                       LIBS="$saved_LIBS"
                fi
        ]
 )
@@ -500,21 +626,55 @@ AC_ARG_ENABLE(ircplus,
 )
 if test "$x_ircplus_on" = "yes"; then
        AC_DEFINE(IRCPLUS, 1)
+
+       # Compile in iconv support?
+       # We only check for it when IRC+ is enabled, because the IRC+ command
+       # CHARCONV is the only function depending on it.
+       x_iconv_on=no
+       AC_ARG_WITH(iconv,
+               AS_HELP_STRING([--with-iconv],
+                              [enable character conversion using libiconv]),
+               [ if test "$withval" != "no"; then
+                       if test "$withval" != "yes"; then
+                               CFLAGS="-I$withval/include $CFLAGS"
+                               CPPFLAGS="-I$withval/include $CPPFLAGS"
+                               LDFLAGS="-L$withval/lib $LDFLAGS"
+                       fi
+                       AC_CHECK_LIB(iconv, iconv_open)
+                       AC_CHECK_FUNCS(iconv_open, x_iconv_on=yes)
+                       if test "$x_iconv_on" != "yes"; then
+                               AC_CHECK_LIB(iconv, libiconv_open)
+                               AC_CHECK_FUNCS(libiconv_open, x_iconv_on=yes)
+                       fi
+                       if test "$x_iconv_on" != "yes"; then
+                               AC_MSG_ERROR([Can't enable libiconv support!])
+                       fi
+               fi ]
+       )
+       if test "$x_iconv_on" = "yes"; then
+               AC_DEFINE(ICONV, 1)
+       fi
 fi
 
 # enable support for IPv6?
-x_ipv6_on=no
+
+x_ipv6_on=yes
 AC_ARG_ENABLE(ipv6,
-       AS_HELP_STRING([--enable-ipv6],
-                      [enable IPv6 protocol support]),
-       if test "$enableval" = "yes"; then x_ipv6_on=yes; fi
+       AS_HELP_STRING([--disable-ipv6],
+                      [disable IPv6 protocol support (autodetected by default)]),
+       [       if test "$enableval" = "no"; then
+                       x_ipv6_on=no
+               else
+                       AC_CHECK_FUNCS(
+                               [getaddrinfo getnameinfo],,
+                               AC_MSG_ERROR([required function missing for IPv6 support!])
+                       )
+               fi
+       ],
+       [       AC_CHECK_FUNCS([getaddrinfo getnameinfo],, x_ipv6_on=no)
+       ]
 )
 if test "$x_ipv6_on" = "yes"; then
-       # getaddrinfo() and getnameinfo() are optional when not compiling
-       # with IPv6 support, but are required for IPv6 to work!
-       AC_CHECK_FUNCS([ \
-               getaddrinfo getnameinfo \
-               ],,AC_MSG_ERROR([required function missing for IPv6 support!]))
        AC_DEFINE(WANT_IPV6, 1)
 fi
 
@@ -561,19 +721,18 @@ AC_DEFINE_UNQUOTED(HOST_CPU, "$host_cpu" )
 AC_DEFINE_UNQUOTED(HOST_VENDOR, "$host_vendor" )
 AC_DEFINE_UNQUOTED(HOST_OS, "$host_os" )
 
-# Add additional CFLAGS, eventually specified on the command line, but after
-# running this configure script. Useful for "-Werror" for example.
+# Add additional CFLAGS, LDFLAGS and LIBS which were specified on the command
+# line or by some tests from above, but after running this script. Useful for
+# adding "-Werror", for example:
 test -n "$CFLAGS_END" && CFLAGS="$CFLAGS $CFLAGS_END"
+test -n "$LDFLAGS_END" && LDFLAGS="$LDFLAGS $LDFLAGS_END"
+test -n "$LIBS_END" && LIBS="$LIBS $LIBS_END"
 
 # -- Generate files --
 
 AC_CONFIG_FILES([ \
        Makefile \
-       contrib/Anope/Makefile \
        contrib/Debian/Makefile \
-       contrib/MacOSX/Makefile \
-       contrib/MacOSX/ngIRCd.pmdoc/Makefile \
-       contrib/MacOSX/ngIRCd.xcodeproj/Makefile \
        contrib/Makefile \
        doc/Makefile \
        doc/src/Makefile \
@@ -593,7 +752,9 @@ if test $? -eq 0; then
        # Generate debian/ link if the dpkg command exists
        # (read: if we are running on a debian compatible system)
        echo "creating Debian-specific links ..."
-       test -f debian/rules || ln -s contrib/Debian debian
+       if test ! -f debian/rules -a -f contrib/Debian/rules; then
+               ln -s contrib/Debian debian
+       fi
 fi
 
 # -- Result --
@@ -663,7 +824,7 @@ test "$x_ipv6_on" = "yes" \
        && echo $ECHO_N "yes   $ECHO_C" \
        || echo $ECHO_N "no    $ECHO_C"
 echo $ECHO_N "        I/O backend: $ECHO_C"
-       echo "\"$x_io_backend\""
+       echo "$x_io_backend"
 
 echo $ECHO_N "        PAM support: $ECHO_C"
 test "$x_pam_on" = "yes" \
@@ -672,9 +833,13 @@ test "$x_pam_on" = "yes" \
 echo $ECHO_N "        SSL support: $ECHO_C"
 echo "$x_ssl_lib"
 
+echo $ECHO_N "   libiconv support: $ECHO_C"
+       echo "$x_iconv_on"
+
 echo
 
-if ! grep "^AUTOMAKE_OPTIONS = ../portab/ansi2knr" src/ngircd/Makefile.am >/dev/null 2>&1; then
+define(_automake_regex_,[[^AUTOMAKE_OPTIONS = [a-z .\-]*/portab/ansi2knr]])
+if ! grep "_automake_regex_" src/ngircd/Makefile.am >/dev/null 2>&1; then
        echo "WARNING:"
        echo "This GNU automake generated build system does not support \"de-ANSI-fication\","
        echo "therefore don't use it to generate \"official\" distribution archives!"