From: Markus Koschany <apo@debian.org>
Date: Fri, 20 Jan 2023 21:32:29 +0100
Subject: fix_ftbfs_rpc

---
 configure.in | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)

diff --git a/configure.in b/configure.in
index b885cf0..0061ffa 100644
--- a/configure.in
+++ b/configure.in
@@ -1016,13 +1016,70 @@ if test -f /etc/fedora-release ; then
             echo
             echo " ERROR! tirpc not found, get it by running "
             echo " yum install libtirpc-devel "
-            exit
+            exit 1
         fi
         LIBS="${LIBS} -ltirpc"
         extra_incl="-I/usr/include/tirpc"
     fi
 fi
 
+###########################################################
+# Debian and Ubuntu do not have inbuilt SunRPC support    #
+# in glibc 2.26 and later and is separately available     #
+# in the libtirpc-dev package.                            #
+# Make sure we've got the library and link it             #
+###########################################################
+
+if test -f /etc/os-release ; then
+    DISTRO_ID=$(cat /etc/os-release |grep ^ID | awk -F = '{print $2}')
+    DISTRO_LIKE=$(cat /etc/os-release |grep ^ID_LIKE | awk -F = '{print $2}')
+    # Only continue if /usr/include/rpc/rpc.h does not exist or it exist but it is not provided by libc6
+    if test -f /usr/include/rpc/rpc.h ||  dpkg -S /usr/include/rpc/rpc.h 2>&1 |grep ^libc6 >/dev/null; then
+            echo " Found RPC (provided by glibc, via libc6-dev package)"
+    else
+        if test $DISTRO_ID = "debian" || test $DISTRO_LIKE = "debian" ; then
+            TIRPC=""
+            AC_CHECK_LIB(tirpc,bindresvport,, TIRPC="no")
+            echo "$TIRPC"
+            if test "x$TIRPC" = "xno"; then
+                echo
+                echo " ERROR! tirpc not found, get it by running "
+                echo " apt install libtirpc-devel "
+                exit 1
+            fi
+            LIBS="${LIBS} -ltirpc"
+            extra_incl="-I/usr/include/tirpc"
+        fi
+    fi
+fi
+
+
+# Alternative code to providing switchable RPC implementation
+# from https://wiki.gentoo.org/wiki/Glibc_2.26_porting_notes/RPC_implementation
+#AC_ARG_WITH([libtirpc],
+#      [AS_HELP_STRING([--with-libtirpc], [Use libtirpc as RPC implementation (instead of sunrpc)])])
+#
+#AS_IF([test "x$with_libtirpc" = xyes],
+#      [PKG_CHECK_MODULES([TIRPC],
+#                         [libtirpc],
+#                         [RPC_CFLAGS=$TIRPC_CFLAGS; RPC_LIBS=$TIRPC_LIBS;],
+#                        [AC_MSG_ERROR([libtirpc requested, but library not found.])]
+#                       )],
+#      [AC_CHECK_HEADER(rpc/rpc.h,
+#                      [RPC_CFLAGS=""; RPC_LIBS="";],
+#                      [AC_MSG_ERROR([sunrpc requested, but headers are not present.])]
+#                     )]
+#)
+#
+
+#AC_SUBST(RPC_CFLAGS)
+#AC_SUBST(RPC_LIBS)
+#
+# or
+# CFLAGS="$CFLAGS $RPC_CFLAGS"
+# LIBS="${LIBS} $RPC_LIBS"
+
+
 ##################################################
 # Centos 8+ does not have inbuilt SunRPC support  #
 # in glibc and is separately availble in tirpc   #
