all: rstatd
include ../MCONFIG
include ../MRULES

ifeq ($(USE_GLIBC),1)
CFLAGS += -DGNU_LIBC -D_GNU_SOURCE
endif

#LIBS += -lproc
# XXX FIXME!
LIBS += /lib/$(shell cd /lib && echo libproc.so.*)

RPCGEN=rpcgen

# Warning, do not put this in the current directory without updating
# the clean target.
RSTATX=/usr/include/rpcsvc/rstat.x

rstatd: rstatd.o rstat_proc.o rstat_xdr.o
	$(CC) $(LDFLAGS) $^ $(LIBS) -o $@

install: rstatd
	install -s -m$(DAEMONMODE) rstatd $(INSTALLROOT)$(SBINDIR)/rpc.rstatd
	install -m$(MANMODE) rpc.rstatd.8 $(INSTALLROOT)$(MANDIR)/man8
	ln -sf rpc.rstatd.8 $(INSTALLROOT)$(MANDIR)/man8/rstatd.8

clean:
	rm -f *.o rstatd rstat_xdr.c rstat.h rstat.x

rstat.x:
	ln -s $(RSTATX) rstat.x

rstat.h: $(RSTATX) rstat.x
	$(RPCGEN) -h -o rstat.h rstat.x

rstat_xdr.c: $(RSTATX) rstat.x
	$(RPCGEN) -c -C -o rstat_xdr.c rstat.x

rstat_xdr.o: rstat_xdr.c rstat.h
