Project:Toolchain/Glibc 2.26 porting notes/RPC implementation

This page provides a guideline and example code snippets to port packages away from SunRPC - necessary for everything listed in tracker. The snippets are taken from the first package on the tracker that I encountered, net-analyzer/dsniff, from which I prepared a reference implementation in my overlay.

Strategies
Two strategies are possible: either switch your package already now to hard-require libtirpc, or make the RPC implementation controllable via a use-flag. For applications (leaf packages), a hard switch may make more sense, for libraries a controllable implementation (since things may explode when different object files linked into the same application use different implementations).

Use flag(s)
If RPC support is optional, please use a use-flag  to enable / disable it entirely.

For switching between implementations, please use :
 * if unset, use glibc's SunRPC,
 * if set, pull in net-lib/libtirpc.

IUSE="+libtirpc"

It makes sense to default this flag to "on", for two reasons:
 * libtirpc is the more modern and likely faster implementation
 * libtirpc works independent of the installed glibc, while SunRPC will go away with glibc-2.26.

Dependencies
!libtirpc? ( sys-libs/glibc[rpc(-)] ) libtirpc? ( net-libs/rpcsvc-proto net-libs/libtirpc )

(Depending on the package you may need rpcsvc-proto or not. It provides the rpcgen binary.)

Patching the build system
Here's an example  snippet for providing switchable RPC implementation:

AC_ARG_WITH([libtirpc],           AS_HELP_STRING([--with-libtirpc], [Use libtirpc as RPC implementation (instead of sunrpc)]),            [], [ with_libtirpc=no ]) AS_IF([test "x$with_libtirpc" != xno],       [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)

And here is a corresponding  example snippet:

INCS  = -I. @RPC_CFLAGS@ LIBS  = @LIBS@ -L$(srcdir) @RPC_LIBS@

(When automake is used, you may want to patch  instead.)

src_configure
econf $(use_with libtirpc)

Nuff said.