# For standard 4.3BSD systems with sunrpc3.9 installed
#LIB=-lrpclib
# For SunOS and other systems with rpc in the c library
LIB=

# Client authorization file
EXPORTSFILE=/etc/unfsd_exports

# Try -DDEBUG for a copious debug log to be written to /tmp/unfsd.log
CFLAGS= -O -DREAD_ONLY -DEXPORTSFILE='"${EXPORTSFILE}"'
LDFLAGS= -O

RPCGEN=	rpcgen
CC=	cc
#------------------------------End of configuration section.

NFSOBJS= nfs_prot_svc.o nfs_prot_xdr.o unfsd.o init.o \
	fh.o ugid_map.o ugid_xdr.o ugid_clnt.o

all: unfsd unfsmntd

install: unfsd unfsmntd
	cp unfsd ${INSDIR}/unfsd
	cp unfsmntd ${INSDIR}/unfsmntd

unfsd:	${NFSOBJS}
	${CC} $(LDFLAGS) -o unfsd ${NFSOBJS} ${LIB}

unfsmntd: mount_svc.o mount_xdr.o unfsmntd.o fh.o
	${CC} $(LDFLAGS) -o unfsmntd mount_svc.o mount_xdr.o unfsmntd.o fh.o ${LIB}

ugidd:	ugid_svc.o ugid_xdr.o ugidd.o
	${CC} $(LDFLAGS) -o ugidd ugid_svc.o ugid_xdr.o ugidd.o ${LIB}
mprobe: mprobe.o mount_xdr.o nfs_prot_xdr.o
	${CC} ${LDFLAGS} -o mprobe mprobe.o mount_xdr.o nfs_prot_xdr.o \
		rpc/rpc/librpclib.a

nfs_prot.h: nfs_prot.x
	${RPCGEN} -h -o $@ $?

nfs_prot_svc.c: nfs_prot.x
	${RPCGEN} -s udp $? | \
	sed \
		-e 's/main()/main(argc,argv) int argc; char **argv;/' \
		-e 's/RPC_ANYSOCK/makesock(NFS_PORT, NFS_MAXDATA)/' \
		-e 's/svc_run();/unfsd_init(argc,argv); svc_run();/' \
	    > $@

nfs_prot_xdr.c: nfs_prot.x
	${RPCGEN} -c -o $@ $?

mount.h: mount.x
	${RPCGEN} -h -o $@ $?

mount_svc.c: mount.x
	${RPCGEN} -s udp $? | \
	sed \
		-e 's/main()/main(argc,argv) int argc; char **argv;/' \
		-e 's/svc_run();/unfsmntd_init(argc,argv); svc_run();/' \
	    > $@

mount_xdr.c: mount.x
	${RPCGEN} -c -o $@ $?

ugid.h:	ugid.x
	${RPCGEN} -h -o $@ $?

ugid_svc.c: ugid.x 
	${RPCGEN} -s udp $? | \
	sed \
		-e 's/main()/main(argc,argv) int argc; char **argv;/' \
		-e 's/RPC_ANYSOCK/run_mode_from_args(argc,argv)/' \
	    > $@

ugid_xdr.c: ugid.x
	${RPCGEN} -c -o $@ $?

ugid_clnt.c: ugid.x
	${RPCGEN} -l -o $@ $?
clean:
	rm -rf *.o nfs_prot_svc.c nfs_prot_xdr.c nfs_prot.h \
		mount_svc.c mount_xdr.c mount.h \
		ugid_svc.c ugid_xdr.c ugid_clnt.c ugid.h \
		unfsd unfsmntd ugidd mprobe

# include dependencies
nfs_prot_svc.o nfs_prot_xdr.o unfsd.o fh.o init.o: nfs_prot.h

mount_svc.o mount_xdr.o unfsmntd.o: mount.h

ugid_map.o ugid_svc.o ugid_xdr.o ugidd.o unfsd.o init.o: ugid.h

mprobe.o: mount.h

fh.o unfsd.o: fh.h

unfsd.o ugid_map.o init.o: unfsd.h
