# rpcrot_xdr.c rpcrot_svc.c rpcrot_clnt.c and rpcrot.h are generated by rpcgen
# have to provide: rpcrot_proc.c rpcrotd.c rpcrot_backend.c
#
# Note: automake complains rpcrot_xdr.c is generated both with and
#  without libtool, hence the copy rpcrot_xdr_lt.c

LDADD = $(top_builddir)/src/libhamlib.la $(top_builddir)/lib/libmisc.la @NET_LIBS@
DEPENDENCIES = $(top_builddir)/src/libhamlib.la 

BUILT_SOURCES  = rpcrot_xdr.c rpcrot_svc.c  rpcrot_xdr_lt.c rpcrot_clnt.c  rpcrot.h
DISTCLEANFILES = $(BUILT_SOURCES)

# needed for backward compatibility on Solaris.
AM_CFLAGS = $(CFLAGS) -DPORTMAP

# The RPC backend
lib_LTLIBRARIES = hamlib-rpcrot.la
hamlib_rpcrot_la_SOURCES = rpcrot_backend.c rpcrot_backend.h
nodist_hamlib_rpcrot_la_SOURCES = rpcrot_clnt.c rpcrot_xdr_lt.c rpcrot.h
hamlib_rpcrot_la_LDFLAGS = -no-undefined -module -avoid-version
hamlib_rpcrot_la_LIBADD = $(top_builddir)/src/libhamlib.la @NET_LIBS@

# The RPC server
sbin_PROGRAMS = rpc.rotd
rpc_rotd_DEPENDENCIES = $(DEPENDENCIES) @ROT_BACKENDEPS@ hamlib-rpcrot.la
rpc_rotd_SOURCES = rpcrotd.c rpcrot_proc.c
nodist_rpc_rotd_SOURCES = rpcrot_svc.c rpcrot_xdr.c rpcrot.h
rpc_rotd_LDFLAGS = @ROT_BACKENDLNK@
man_MANS = rpc.rotd.8


EXTRA_DIST = rpcrot.x $(man_MANS)

RPCGEN = rpcgen

rpcrot.h: Makefile rpcrot.x
	rm -f $@
	$(RPCGEN) -h -C `test -f rpcrot.x || echo '$(srcdir)/'`rpcrot.x -o $@


# Need to chdir in source dir, otherwise rpcgen hardcodes header path. sigh.
rpcrot_clnt.c: Makefile rpcrot.x
	rm -f $@
	abs_builddir=`pwd` ; \
	cd $(srcdir) && $(RPCGEN) -l -C rpcrot.x -o $$abs_builddir/$@

rpcrot_svc.c: Makefile rpcrot.x
	rm -f $@
	abs_builddir=`pwd` ; \
	cd $(srcdir) && $(RPCGEN) -m -C rpcrot.x -o $$abs_builddir/$@

# note:
# we need 2 rpcrot_xdr.c's: one for static rpcrot deamon, one for lt backend

rpcrot_xdr.c: Makefile rpcrot.x
	rm -f $@
	abs_builddir=`pwd` ; \
	cd $(srcdir) && $(RPCGEN) -c -C rpcrot.x -o $$abs_builddir/$@

rpcrot_xdr_lt.c: Makefile rpcrot.x
	rm -f $@
	abs_builddir=`pwd` ; \
	cd $(srcdir) && $(RPCGEN) -c -C rpcrot.x -o $$abs_builddir/$@

