# rpcrig_xdr.c rpcrig_svc.c rpcrig_clnt.c and rpcrig.h are generated by rpcgen
# have to provide: rpcrig_proc.c rpcrigd.c rpcrig_backend.c
#
# Note: automake complains rpcrig_xdr.c is generated both with and 
#  without libtool, hence the copy rpcrig_xdr_lt.c

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

BUILT_SOURCES  = rpcrig_xdr.c rpcrig_svc.c  rpcrig_xdr_lt.c rpcrig_clnt.c  rpcrig.h
DISTCLEANFILES = $(BUILT_SOURCES)

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

# The RPC backend
lib_LTLIBRARIES = hamlib-rpcrig.la
hamlib_rpcrig_la_SOURCES = rpcrig_backend.c rpcrig_backend.h
nodist_hamlib_rpcrig_la_SOURCES = rpcrig_clnt.c rpcrig_xdr_lt.c rpcrig.h
hamlib_rpcrig_la_LDFLAGS = -no-undefined -module -avoid-version
hamlib_rpcrig_la_LIBADD = $(top_builddir)/src/libhamlib.la @NET_LIBS@

# The RPC server
sbin_PROGRAMS = rpc.rigd
rpc_rigd_DEPENDENCIES = $(DEPENDENCIES) @BACKENDEPS@ hamlib-rpcrig.la
rpc_rigd_SOURCES = rpcrigd.c rpcrig_proc.c
nodist_rpc_rigd_SOURCES = rpcrig_svc.c rpcrig_xdr.c rpcrig.h
rpc_rigd_LDFLAGS = @BACKENDLNK@
man_MANS = rpc.rigd.8

EXTRA_DIST = rpcrig.x $(man_MANS)

RPCGEN = rpcgen

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


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

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

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

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

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

