Fixed building issues after merge
[cascardo/gnio.git] / configure.ac
index 6132f5d..d2a587d 100644 (file)
@@ -44,18 +44,234 @@ PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.13.8 gthread-2.0 gobject-2.0 gmodule-no-ex
 AC_SUBST(GLIB_CFLAGS)
 AC_SUBST(GLIB_LIBS)
 
+PKG_CHECK_MODULES(GTHREAD, gthread-2.0)
+
 GETTEXT_PACKAGE=gnio
 AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [The gettext domain name])
 AC_SUBST(GETTEXT_PACKAGE)
 
 AM_GLIB_GNU_GETTEXT
 
+AC_CHECK_FUNC(getaddrinfo_a)
+AC_CHECK_FUNC(gethostbyname_r)
 
 dnl ==========================================================================
        
 dnl Globally define_GNU_SOURCE and therefore enable the GNU extensions
 AC_DEFINE(_GNU_SOURCE, 1, [Enable GNU Extensions])
 
+AC_CHECK_HEADERS([sys/sockio.h sys/param.h ifaddrs.h])
+
+AM_CONDITIONAL(WIN32, [echo "$host" | grep -qE '^.*-.*-mingw.*$'])
+
+case "$host" in
+  *-*-mingw*)
+    AC_DEFINE(HAVE_IPV6, 1, [Define to 1 if IPv6 is potentially available])
+    AC_DEFINE(HAVE_GETADDRINFO, 1, [Define if the system provides getaddrinfo(2)])
+    AC_DEFINE(HAVE_GETADDRINFO_THREADSAFE, 1,   [Define if getaddrinfo is threadsafe])
+    AC_DEFINE(HAVE_SOCKADDR_STORAGE,1,[Whether you have struct sockaddr_storage])
+    ;;
+  *)
+    AC_MSG_CHECKING([for linux/netlink.h])
+    AC_TRY_CPP([#include <linux/netlink.h>],
+           [
+             AC_MSG_RESULT(yes)
+                 AC_DEFINE(HAVE_LINUX_NETLINK_H, 1,
+               [Define if linux/netlink.h header exists])
+               ],[
+                 AC_MSG_RESULT(no)
+               ])
+
+    AC_CHECK_MEMBER([struct sockaddr.sa_len],
+                AC_DEFINE(HAVE_SOCKADDR_SA_LEN, 1,
+                  [Define if struct sockaddr has sa_len field]),,
+                [#include <sys/types.h>
+                 #include <sys/socket.h>])
+
+    AC_MSG_CHECKING([for struct sockaddr_storage])
+    AC_TRY_COMPILE([ #include <sys/types.h>
+    #include <sys/socket.h>], [struct sockaddr_storage s; s],
+      have_sockaddr_storage=yes, have_sockaddr_storage=no)
+    if test "$have_sockaddr_storage" = yes; then
+      AC_DEFINE(HAVE_SOCKADDR_STORAGE,1,[Whether you have struct sockaddr_storage])
+      AC_MSG_RESULT(yes)
+    else
+      AC_MSG_RESULT(no)
+    fi
+
+    # Check for IPv6 support on unix
+    # (will be done at runtime on win32)
+    AC_MSG_CHECKING([for IPv6 availability])
+    AC_TRY_LINK([ #include <sys/types.h>
+                  #include <sys/socket.h>
+                  #include <netinet/in.h> ],
+                [ struct sockaddr_in6 s;
+                  struct in6_addr t=in6addr_any;
+                  int i=AF_INET6;
+                  s;
+                  t.s6_addr[0] = 0; ],
+                [
+                  AC_DEFINE(HAVE_IPV6, 1, [Define to 1 if IPv6 is potentially available])
+                  AC_MSG_RESULT(yes)
+                ],
+                [
+                  AC_DEFINE(HAVE_IPV6, 0, [Define to 1 if IPv6 is potentially available])
+                  AC_MSG_RESULT(no)
+                ]
+    )
+    # Most of this code checks for variants of gethostbyname().  For
+    # simplicity and curiosity, we check for all variants, though only one
+    # working variant is needed.
+
+    # Look for getifaddrs()
+    AC_CHECK_FUNC(getifaddrs, AC_DEFINE(HAVE_GETIFADDRS, 1,
+        [Define if getifaddrs() is available]))
+
+
+    # The user may be able to tell us if a function is thread-safe.  We
+    # know of no good way to test this programaticly.
+
+    # On some systems, getaddrinfo() is thread-safe
+    AC_ARG_ENABLE(threadsafe_getaddrinfo,
+              AC_HELP_STRING([--enable-threadsafe-getaddrinfo],
+                             [assume getaddrinfo() is threadsafe]))
+
+    # On some systems, gethostbyname() is thread-safe
+    AC_ARG_ENABLE(threadsafe_gethostbyname,
+              AC_HELP_STRING([--enable-threadsafe-gethostbyname],
+                             [assume gethostbyname() is threadsafe]))
+
+
+    # Look for getaddrinfo().  If we have that, we don't need
+    # gethostbyname().  We assume if the system has getaddrinfo(), they
+    # have getnameinfo().
+    AC_CHECK_FUNC(getaddrinfo, 
+     [ # have getaddrinfo()
+      HAVE_GETADDRINFO=yes
+      AC_DEFINE(HAVE_GETADDRINFO, 1,
+        [Define if getaddrinfo() is available])
+      # Check for threadsafe getaddrinfo()
+      AC_MSG_CHECKING([for threadsafe getaddrinfo()])
+      if test "x$enable_threadsafe_getaddrinfo" = "xyes" ; then
+        HAVE_GETADDRINFO_THREADSAFE=yes
+        AC_MSG_RESULT(yes)
+        AC_DEFINE(HAVE_GETADDRINFO_THREADSAFE, 1,
+        [Define if getaddrinfo is threadsafe])
+      else
+        AC_MSG_RESULT(no)
+        # If there is no threadsafe getaddrinfo, use a Glib mutex.
+        if test "x$GTHREAD_CFLAGS" != "x"; then
+          AC_DEFINE(HAVE_GETADDRINFO_GLIB_MUTEX, 1,
+                    [Define if getaddrinfo requires a mutex for thread-safety])
+        HAVE_GETADDRINFO_GLIB_MUTEX=yes
+        else
+        AC_MSG_WARN([
+
+    You do not have a thread-safe getaddrinfo() or GLib threads.
+    Calls to getaddrinfo() may
+    not be thread-safe.  This build of GNIO could malfunction if used in
+    programs that use threads.  If your system has a thread-safe version
+    of getaddrinfo(), pass the option --enable-threadsafe-getaddrinfo
+    to configure.  The function's manpage may be able to tell you whether
+    it is thread-safe or not.
+
+    ])
+        fi
+      fi
+     ],
+     [  # no getaddrinfo()
+      AC_MSG_RESULT(no)
+     ])
+    # Check if the user told use gethostbyname() is thread-safe.
+    AC_MSG_CHECKING([for threadsafe gethostbyname()])
+    if test "x$enable_threadsafe_gethostbyname" = "xyes" ; then
+      AC_MSG_RESULT(yes)
+      AC_DEFINE(HAVE_GETHOSTBYNAME_THREADSAFE, 1, 
+        [Define if gethostbyname is threadsafe])
+      HAVE_GETHOSTBYNAME_THREADSAFE=yes
+    else
+      AC_MSG_RESULT(no)
+    fi
+
+    # Look for a gethostbyname_r() we can use.  We assume that if the
+    # system has gethostbyname_r(), they also have gethostbyaddr_r().
+
+    # First, look for the glibc varient
+    AC_MSG_CHECKING([for glibc gethostbyname_r])
+    AC_TRY_LINK([#include <netdb.h>],
+            [struct hostent result_buf;
+             char buf[1024];
+             struct hostent *result;
+             int h_erropp;
+
+             gethostbyname_r("localhost",
+                             &result_buf,
+                             buf,
+                             sizeof(buf),
+                             &result,
+                             &h_erropp);],
+             [AC_MSG_RESULT([yes])
+              AC_DEFINE(HAVE_GETHOSTBYNAME_R_GLIBC, 1,
+                 [Define if glibc variant of gethostbyname() is available])
+              HAVE_GETHOSTBYNAME_R=yes],
+             [AC_MSG_RESULT([no])])
+    # Whups, maybe we're on Solaris or Irix
+    AC_MSG_CHECKING([for Solaris/Irix gethostbyname_r])
+    AC_TRY_LINK([#include <netdb.h>],
+            [struct hostent result;
+             char buf[1024];
+             int h_errnop;
+
+             gethostbyname_r("localhost",
+                             &result,
+                             buf,
+                             sizeof(buf),
+                             &h_errnop);],
+            [AC_MSG_RESULT([yes])
+             AC_DEFINE(HAVE_GETHOSTBYNAME_R_SOLARIS, 1,
+                    [Define if Solaris variant of gethostbyname() is available])
+             HAVE_GETHOSTBYNAME_R=yes],
+            [AC_MSG_RESULT([no])])
+
+    # Or not.  Perhaps we're on HP-UX?
+    AC_MSG_CHECKING([for HP-UX gethostbyname_r])
+    AC_TRY_LINK([#include <netdb.h>],
+            [struct hostent result;
+             char buf[1024];
+
+             gethostbyname_r("localhost",
+                             &result,
+                             buf);],
+            [AC_MSG_RESULT([yes])
+             AC_DEFINE(HAVE_GETHOSTBYNAME_R_HPUX, 1,
+                   [Define if HPUX variant of gethostbyname() is available])
+             HAVE_GETHOSTBYNAME_R=yes],
+            [AC_MSG_RESULT([no])])
+    # If there is no gethostbyname_r, use Glib threads.
+    if test -z "$HAVE_GETHOSTBYNAME_THREADSAFE" -a -z "$HAVE_GETHOSTBYNAME_R" -a "$GTHREAD_CFLAGS"; then
+        AC_DEFINE(HAVE_GETHOSTBYNAME_R_GLIB_MUTEX, 1,
+                    [Define if gethostbyname requires a mutex for thread-safety])
+        HAVE_GETHOSTBYNAME_R=yes
+    fi
+
+    # Duh-oh.  We don't have _any_ thread-safety, so warn the builder
+    if test -z "$HAVE_GETADDRINFO_THREADSAFE" -a -z "$HAVE_GETHOSTBYNAME_THREADSAFE" -a -z "$HAVE_GETHOSTBYNAME_R"; then
+        AC_MSG_WARN([
+
+    You do not have a thread-safe gethostbyname_r() or GLib threads.
+    Calls to gethostbyname() (called by the GOIO address functions) may
+    not be thread-safe.  This build of GOIO could malfunction if used in
+    programs that use threads.  If your system has a thread-safe version
+    of gethostbyname(), pass the option --enable-threadsafe-gethostbyname
+    to configure.  The function's manpage may be able to tell you whether
+    it is thread-safe or not.
+
+    ])
+    fi
+    ;;
+esac
+
+
 dnl ==========================================================================
        
 AC_DEFINE(_FILE_OFFSET_BITS, 64, [Enable LFS])
@@ -110,7 +326,6 @@ AC_OUTPUT([
 Makefile
 gnio/Makefile
 test/Makefile
-po/Makefile.in
 ])
 
 echo