diff --git a/configure.ac b/configure.ac
index 4a609f83a5ce864e83d412a3f77c5e599fc38638..abeecabe4661fc3b1d2726c059db2151428d8db6 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 0000000000000000000000000000000000000000..ccb362aab6088f2b522eb42065a35f6e9106cc00
--- /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)
+  ])
+])