CC = gcc
RPCGEN = rpcgen -C
CFLAGS =  -g -DHAVE_XDRPROC_T -DHAVE_SYS_TIME_H

OWNER = root
GROUP = bin
SBINDIR = /usr/sbin
MANDIR = /usr/man


RPCGENERED = xattr.h xattr_xdr.c xattr_svc.c
SRCS = xattr_subs.o xattr_xdr.o xattr_svc.o xattrd.o auth.o auth_clnt.o \
       auth_init.o faccess.o xmalloc.o xstrdup.o ugid_map.o

INSTALL = /usr/bin/install

.PHONY: clean all

all: xattrd 

xattr.h: xattr.x
	$(RPCGEN) -h -o xattr.h xattr.x

xattr_xdr.c: xattr.x xattr.h
	$(RPCGEN) -c xattr.x | \
		sed -e 's;^#include ".*/mount.h"$$;#include "mount.h";' >$@

xattr_svc.c: xattr.x xattr.h
	$(RPCGEN) -s tcp -s udp xattr.x | \
		sed -e 's;^#include ".*/mount.h"$$;#include "mount.h";' \
                    -e 's;main;real_main;' \
		    -e 's;RPC_ANYSOCK;xattrd_socket;' >$@

xattr_subs.o: xattr.h

xattrd: $(SRCS)
	$(CC) $(LDFLAGS) -o xattrd $(SRCS) $(LOADLIBES)

clean:
	rm -f *.o *~ xattrd $(RPCGENERED)

install: all
	$(INSTALL) -d -m 755 -g $(OWNER) -o $(GROUP) $(SBINDIR)
	$(INSTALL) -d -m 755 -g $(OWNER) -o $(GROUP) $(MANDIR)
	$(INSTALL) -m 755 -g $(OWNER) -o $(GROUP) -s xattrd $(SBINDIR)
	$(INSTALL) -m 755 -g $(OWNER) -o $(GROUP) xattrd.8 $(MANDIR)/man8
