From eb8bdf52ec64e69d8611b50c291fe643bc190aa3 Mon Sep 17 00:00:00 2001
From: Karl Fleischmann <karl.fleischmann@open-xchange.com>
Date: Mon, 8 Aug 2022 15:52:58 +0200
Subject: [PATCH] configure: Use TEST_WITH macro from dovecot/core

Drop the inline definition of the TEST_WITH macro in favor of using a
verbatim copy of the file that contains the macro from the dovecot/core
project. This allows easier tracking of changes to the macro that happen
upstream.
---
 configure.ac    | 22 ----------------------
 m4/test_with.m4 | 18 ++++++++++++++++++
 2 files changed, 18 insertions(+), 22 deletions(-)
 create mode 100644 m4/test_with.m4

diff --git a/configure.ac b/configure.ac
index 4a609f83a..abeecabe4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -77,28 +77,6 @@ if test "$want_unfinished_features" = "yes"; then
 		[Define to build unfinished features/extensions.])
 fi
 
-#
-#
-
-dnl TEST_WITH(name, value, [plugin])
-AC_DEFUN([TEST_WITH], [
-  want=want_`echo $1|sed s/-/_/g`
-  if test $2 = yes || test $2 = no || test $2 = auto; then
-    eval $want=$2
-  elif test $2 = plugin; then
-    if test "$3" = plugin; then
-      eval $want=plugin
-    else
-      AC_MSG_ERROR([--with-$1=plugin not supported])
-    fi
-  elif `echo $2|grep '^/' >/dev/null`; then
-    AC_MSG_ERROR([--with-$1=path not supported. You may want to use instead:
-CPPFLAGS=-I$2/include LDFLAGS=-L$2/lib ./configure --with-$1])
-  else
-    AC_MSG_ERROR([--with-$1: Unknown value: $2])
-  fi
-])
-
 AC_ARG_WITH(docs,
 [  --with-docs             Install documentation (default)],
     if test x$withval = xno; then
diff --git a/m4/test_with.m4 b/m4/test_with.m4
new file mode 100644
index 000000000..ccb362aab
--- /dev/null
+++ b/m4/test_with.m4
@@ -0,0 +1,18 @@
+dnl TEST_WITH(name, value, [plugin])
+AC_DEFUN([TEST_WITH], [
+  want=want_`echo $1|sed s/-/_/g`
+  AS_IF([test "$2" = yes || test "$2" = no || test "$2" = auto], [
+    eval $want=$2
+  ], [test "$2" = plugin], [
+    AS_IF([test "$3" = "plugin"], [
+      eval $want=plugin
+    ], [
+      AC_MSG_ERROR(--with-$1=plugin not supported)
+    ])
+  ], [test "$(echo $2|grep -c '^/' 2>/dev/null)" -gt 0], [
+    AC_MSG_ERROR(--with-$1=path not supported. You may want to use instead:
+CPPFLAGS=-I$2/include LDFLAGS=-L$2/lib ./configure --with-$1)
+  ], [
+    AC_MSG_ERROR(--with-$1: Unknown value: $2)
+  ])
+])
-- 
GitLab