From 4d5a944869b97e320501c009b8937839d126276e Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan.bosch@dovecot.fi>
Date: Wed, 19 Oct 2016 18:38:00 +0200
Subject: [PATCH] Updated dovecot.m4.

---
 m4/dovecot.m4 | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/m4/dovecot.m4 b/m4/dovecot.m4
index af3050bd9..22dea22ec 100644
--- a/m4/dovecot.m4
+++ b/m4/dovecot.m4
@@ -6,7 +6,7 @@
 # unlimited permission to copy and/or distribute it, with or without
 # modifications, as long as this notice is preserved.
 
-# serial 23
+# serial 24
 
 AC_DEFUN([DC_DOVECOT_MODULEDIR],[
 	AC_ARG_WITH(moduledir,
@@ -137,3 +137,28 @@ AC_DEFUN([DC_DOVECOT],[
 	DC_PLUGIN_DEPS
 	DC_DOVECOT_TEST_WRAPPER
 ])
+
+AC_DEFUN([DC_CC_WRAPPER],[
+  if test "$want_shared_libs" != "yes"; then
+    # want_shared_libs=no is for internal use. the liblib.la check is for plugins
+    if test "$want_shared_libs" = "no" || echo "$LIBDOVECOT" | grep "/liblib.la" > /dev/null; then
+      if test "$with_gnu_ld" = yes; then
+	# libtool can't handle using whole-archive flags, so we need to do this
+	# with a CC wrapper.. shouldn't be much of a problem, since most people
+	# are building with shared libs.
+	cat > cc-wrapper.sh <<EOF
+#!/bin/sh
+
+if echo "\$[*]" | grep -- -ldl > /dev/null; then
+  # the binary uses plugins. make sure we include everything from .a libs
+  exec $CC -Wl,--whole-archive \$[*] -Wl,--no-whole-archive
+else
+  exec $CC \$[*]
+fi
+EOF
+	chmod +x cc-wrapper.sh
+	CC=`pwd`/cc-wrapper.sh
+      fi
+    fi
+  fi
+])
-- 
GitLab