summaryrefslogtreecommitdiff
path: root/debian/patches/libphobos-zlib.diff
blob: 1aa828255018ca5a6d3cdbed7f4bdb5bc8cde388 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# DP: Build zlib in any case to have a fall back for missing libz multilibs

Index: b/src/libphobos/configure.ac
===================================================================
--- a/src/libphobos/configure.ac
+++ b/src/libphobos/configure.ac
@@ -104,6 +104,7 @@ WITH_LOCAL_DRUNTIME([
 
 DRUNTIME_LIBBACKTRACE_SETUP
 DRUNTIME_INSTALL_DIRECTORIES
+dnl fake change to regenerate the configure file
 
 # Add dependencies for libgphobos.spec file
 LIBS="$LIBS $LIBADD_DLOPEN"
Index: b/src/libphobos/m4/druntime/libraries.m4
===================================================================
--- a/src/libphobos/m4/druntime/libraries.m4
+++ b/src/libphobos/m4/druntime/libraries.m4
@@ -39,18 +39,44 @@ AC_DEFUN([DRUNTIME_LIBRARIES_ZLIB],
 [
   AC_ARG_WITH(target-system-zlib,
     AS_HELP_STRING([--with-target-system-zlib],
-                   [use installed libz (default: no)]))
+                   [use installed libz (default: no)]),
+     [system_zlib=yes],[system_zlib=no])
 
-  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_MSG_RESULT([just compiled])
-  ])
+  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_LANG_PUSH(C)
+  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 = xyes; then
+    if test x$system_zlib_found = xyes; then
+      AC_MSG_RESULT([found])
+    else
+      AC_MSG_RESULT([not found, disabled])
+      system_zlib=no
+    fi
+  else
+    AC_MSG_RESULT([not enabled])
+  fi
+  AC_LANG_POP
 
   AM_CONDITIONAL([DRUNTIME_ZLIB_SYSTEM], [test "$with_target_system_zlib" = yes])
 ])