1# $Id: rpc.m4,v 12.1 2006/05/08 20:52:36 bostic Exp $
2
3# Try and configure RPC support.
4AC_DEFUN(AM_RPC_CONFIGURE, [
5	AC_DEFINE(HAVE_RPC)
6	AH_TEMPLATE(HAVE_RPC, [Define to 1 if building RPC client/server.])
7
8	# We use the target's rpcgen utility because it may be architecture
9	# specific, for example, 32- or 64-bit specific.
10	XDR_FILE=$srcdir/../rpc_server/db_server.x
11
12	# Prefer the -C option to rpcgen which generates ANSI C-conformant
13	# code.
14	RPCGEN="rpcgen -C"
15	AC_MSG_CHECKING(["$RPCGEN" build of db_server.h])
16	$RPCGEN -h $XDR_FILE > db_server.h 2>/dev/null
17	if test $? -ne 0; then
18		AC_MSG_RESULT([no])
19
20		# Try rpcgen without the -C option.
21		RPCGEN="rpcgen"
22		AC_MSG_CHECKING(["$RPCGEN" build of db_server.h])
23		$RPCGEN -h $XDR_FILE > db_server.h 2>/dev/null
24		if test $? -ne 0; then
25			AC_MSG_RESULT([no])
26			AC_MSG_ERROR(
27			    [Unable to build RPC support: $RPCGEN failed.])
28		fi
29	fi
30
31	# Some rpcgen programs generate a set of client stubs called something
32	# like __db_env_create_4003 and functions on the server to handle the
33	# request called something like __db_env_create_4003_svc.  Others
34	# expect client and server stubs to both be called __db_env_create_4003.
35	#
36	# We have to generate code in whichever format rpcgen expects, and the
37	# only reliable way to do that is to check what is in the db_server.h
38	# file we just created.
39	if grep "env_create_[[0-9]]*_svc" db_server.h >/dev/null 2>&1 ; then
40		sed 's/__SVCSUFFIX__/_svc/' \
41		    < $srcdir/../rpc_server/c/gen_db_server.c > gen_db_server.c
42	else
43		sed 's/__SVCSUFFIX__//' \
44		    < $srcdir/../rpc_server/c/gen_db_server.c > gen_db_server.c
45	fi
46
47	AC_MSG_RESULT([yes])
48
49	$RPCGEN -l $XDR_FILE |
50	sed -e 's/^#include.*db_server.h.*/#include "db_server.h"/' \
51	    -e '1,/^#include/s/^#include/#include "db_config.h"\
52&/' > db_server_clnt.c
53
54	$RPCGEN -s tcp $XDR_FILE |
55	sed -e 's/^#include.*db_server.h.*/#include "db_server.h"/' \
56	    -e 's/^main *()/__dbsrv_main()/' \
57	    -e 's/^main *(.*argc.*argv.*)/__dbsrv_main(int argc, char *argv[])/' \
58	    -e '/^db_rpc_serverprog/,/^}/{' \
59	    -e 's/return;//' \
60	    -e 's/^}/__dbsrv_timeout(0);}/' \
61	    -e '}' \
62	    -e '1,/^#include/s/^#include/#include "db_config.h"\
63&/' > db_server_svc.c
64
65	$RPCGEN -c $XDR_FILE |
66	sed -e 's/^#include.*db_server.h.*/#include "db_server.h"/' \
67	    -e '1,/^#include/s/^#include/#include "db_config.h"\
68&/' > db_server_xdr.c
69
70	RPC_SERVER_H=db_server.h
71	RPC_CLIENT_OBJS="\$(RPC_CLIENT_OBJS)"
72	ADDITIONAL_PROGS="berkeley_db_svc $ADDITIONAL_PROGS"
73
74	# Solaris and HPUX need the nsl library to build RPC.
75	AC_CHECK_FUNC(svc_run,,
76	    AC_HAVE_LIBRARY(nsl, LIBSO_LIBS="$LIBSO_LIBS -lnsl"))
77])
78