]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libphobos/m4/druntime/libraries.m4
libphobos: Add target-zlib to top-level configure
[thirdparty/gcc.git] / libphobos / m4 / druntime / libraries.m4
index 35a791d137a57171ddea8d1c7db7c9ac64c00089..6e81fd99e4b0f019fb19016e47ca300f71897a03 100644 (file)
@@ -42,31 +42,96 @@ AC_DEFUN([DRUNTIME_LIBRARIES_DLOPEN],
 ])
 
 
+# DRUNTIME_LIBRARIES_NET
+# -----------------------
+# Autodetect and add networking library to LIBS if necessary.
+AC_DEFUN([DRUNTIME_LIBRARIES_NET],
+[
+  dnl Test for -lsocket and -lnsl.  Copied from libjava/configure.ac.
+  AC_CACHE_CHECK([for socket libraries], druntime_cv_lib_sockets,
+    [druntime_cv_lib_sockets=
+     druntime_check_both=no
+     AC_CHECK_FUNC(connect, druntime_check_socket=no, druntime_check_socket=yes)
+     if test "$druntime_check_socket" = "yes"; then
+       unset ac_cv_func_connect
+       AC_CHECK_LIB(socket, main, druntime_cv_lib_sockets="-lsocket",
+                   druntime_check_both=yes)
+     fi
+     if test "$druntime_check_both" = "yes"; then
+       druntime_old_libs=$LIBS
+       LIBS="$LIBS -lsocket -lnsl"
+       unset ac_cv_func_accept
+       AC_CHECK_FUNC(accept,
+                    [druntime_check_nsl=no
+                     druntime_cv_lib_sockets="-lsocket -lnsl"])
+       unset ac_cv_func_accept
+       LIBS=$druntime_old_libs
+     fi
+     unset ac_cv_func_gethostbyname
+     druntime_old_libs="$LIBS"
+     AC_CHECK_FUNC(gethostbyname, ,
+                  [AC_CHECK_LIB(nsl, main,
+                   [druntime_cv_lib_sockets="$druntime_cv_lib_sockets -lnsl"])])
+  ])
+  LIBS="$LIBS $druntime_cv_lib_sockets"
+])
+
 # DRUNTIME_LIBRARIES_ZLIB
 # -----------------------
 # Allow specifying whether to use the system zlib or
-# compiling the zlib included in GCC. Define
-# DRUNTIME_ZLIB_SYSTEM conditional and add zlib to
-# LIBS if necessary.
+# compiling the zlib included in GCC.  Adds substitute
+# for LIBZ or adds zlib to LIBS if necessary.
 AC_DEFUN([DRUNTIME_LIBRARIES_ZLIB],
 [
-  AC_ARG_WITH(target-system-zlib,
-    AS_HELP_STRING([--with-target-system-zlib],
-                   [use installed libz (default: no)]))
+  AC_LANG_PUSH([C])
+  LIBZ=""
 
-  system_zlib=false
-  AS_IF([test "x$with_target_system_zlib" = "xyes"], [
-    AC_CHECK_LIB([z], [deflate], [
-      system_zlib=yes
-    ], [
-      AC_MSG_ERROR([System zlib not found])
-    ])
-  ], [
-    AC_MSG_CHECKING([for zlib])
+  AC_ARG_WITH(target-system-zlib,
+    AS_HELP_STRING([--with-target-system-zlib={yes,no,auto}],
+                   [use installed libz (default: no)]),,
+              [with_target_system_zlib=no])
+
+  case "$with_target_system_zlib" in
+    yes|no|auto) ;;
+    *) AC_MSG_ERROR([Invalid argument for --with-target-system-zlib]) ;;
+  esac
+
+  AC_MSG_CHECKING([for system zlib])
+  save_LIBS=$LIBS
+  LIBS="$LIBS -lz"
+  dnl the link test is not good enough for ARM32 multilib detection,
+  dnl first check to link, then to run
+  AC_LINK_IFELSE(
+    [AC_LANG_PROGRAM([#include <zlib.h>],[gzopen("none", "rb")])],
+    [
+      AC_RUN_IFELSE([AC_LANG_SOURCE([[
+        #include <zlib.h>
+        int main() {
+          gzFile file = gzopen("none", "rb");
+          return 0;
+        }
+        ]])],
+        [system_zlib_found=yes],
+        [system_zlib_found=no],
+        dnl no system zlib for cross builds ...
+        [system_zlib_found=no]
+      )
+    ],
+    [system_zlib_found=no])
+  LIBS=$save_LIBS
+
+  if test x$system_zlib_found = xyes && test x$with_target_system_zlib != xno; then
+    AC_MSG_RESULT([found])
+    LIBS="$LIBS -lz"
+  elif test x$system_zlib_found = xno && test x$with_target_system_zlib = xyes; then
+    AC_MSG_ERROR([system zlib required but not found])
+  else
     AC_MSG_RESULT([just compiled])
-  ])
+    LIBZ=../../zlib/libz_convenience.la
+  fi
 
-  AM_CONDITIONAL([DRUNTIME_ZLIB_SYSTEM], [test "$with_target_system_zlib" = yes])
+  AC_SUBST(LIBZ)
+  AC_LANG_POP([C])
 ])
 
 # DRUNTIME_LIBRARIES_ATOMIC