patch 9.1.1485: missing Wayland clipboard support

Problem:  missing Wayland clipboard support
Solution: make it work (Foxe Chen)

fixes: #5157
closes: #17097

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/configure.ac b/src/configure.ac
index 8abec36..c91c841 100644
--- a/src/configure.ac
+++ b/src/configure.ac
@@ -2389,6 +2389,64 @@
 AC_MSG_RESULT($enable_fontset)
 dnl defining FEAT_XFONTSET is delayed, so that it can be disabled for no GUI
 
+AC_MSG_CHECKING(if shm_open is available)
+cppflags_save=$CPPFLAGS
+CPPFLAGS="$CPPFLAGS $X_CFLAGS"
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+		   [#include <sys/mman.h>
+		    #include <sys/stat.h>
+		    #include <fcntl.h>], [shm_open("/test", O_CREAT, 0600);])],
+		   AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SHM_OPEN),
+		   AC_MSG_RESULT(no))
+CPPFLAGS=$cppflags_save
+
+AC_MSG_CHECKING(--with-wayland argument)
+AC_ARG_WITH(wayland,
+	[  --with-wayland	  Include support for the Wayland protocol.])
+
+test -z "$with_wayland" && with_wayland=yes
+if test "$with_wayland" = yes; then
+  AC_MSG_RESULT(yes)
+  AC_MSG_CHECKING(if wayland client header files can be found)
+  cppflags_save=$CPPFLAGS
+  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
+  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <wayland-client.h>], )],
+	AC_MSG_RESULT(yes),
+	AC_MSG_RESULT(no); no_wl=yes)
+  CPPFLAGS=$cppflags_save
+
+  if test "$no_wl" = yes; then
+    with_wayland=no
+  else
+    AC_CHECK_LIB(wayland-client, wl_display_connect,[no_wl=no])
+
+    if test "$no_wl" = no; then
+      AC_DEFINE(HAVE_WAYLAND)
+      WAYLAND_LIBS="-lwayland-client";
+      AC_SUBST(WAYLAND_LIBS)
+      WAYLAND_SRC=" \
+	      auto/wayland/wlr-data-control-unstable-v1.c \
+	      auto/wayland/ext-data-control-v1.c \
+	      auto/wayland/xdg-shell.c \
+	      auto/wayland/primary-selection-unstable-v1.c \
+	      wayland.c"
+      AC_SUBST(WAYLAND_SRC)
+      WAYLAND_OBJ=" \
+	      objects/wlr-data-control-unstable-v1.o \
+	      objects/ext-data-control-v1.o \
+	      objects/xdg-shell.o \
+	      objects/primary-selection-unstable-v1.o \
+	      objects/wayland.o"
+      AC_SUBST(WAYLAND_OBJ)
+
+    else
+      with_wayland=no
+    fi
+  fi
+else
+  AC_MSG_RESULT(no)
+fi
+
 test -z "$with_x" && with_x=yes
 test "${enable_gui-yes}" != no -a "x$MACOS_X" != "xyes" -a "x$QNX" != "xyes" && with_x=yes
 if test "$with_x" = no; then