SHELL=/bin/sh

# on most platforms this is ok:
#ETCDIR=/usr/local/etc
#MANSECT=8
#MANDIR=/usr/local/man/man$(MANSECT)
#CDEBUGFLAGS=-O -g -DDEBUG -Wall
#INCLUDES=
#RPCLIB=
#CFLAGS= $(CDEBUGFLAGS) $(INCLUDES)

# on solaris we prefer:
ETCDIR=/usr/local/sbin
MANSECT=8
MANDIR=/usr/local/man/man$(MANSECT)
#CC=gcc
CDEBUGFLAGS=-O -g -DDEBUG -Wall
INCLUDES=
RPCLIB=
CFLAGS= -DSVR4 $(CDEBUGFLAGS) $(INCLUDES)
LDFLAGS= -lsocket -lnsl


# -b : generate code for SunOS4.1 style rpc (backward compat)
#      needed for Linux and Solaris
RPCGEN=rpcgen -b
# files that are generated by rpcgen, deleted by make clobber
RPCGENOUTS=ether_svc.c ether_xdr.c ether.h ether_client.c

OBJS=ether_svc.o ether_xdr.o packet.o etherd.o


rpc.etherd: $(OBJS) ether.h
	$(CC) $(CFLAGS) $(LDFLAGS) -o rpc.etherd $(OBJS) $(RPCLIB)

# chose one of the rules
ether_svc.c: ether.x ether.h
#	# cp ether_svc.c-dist ether_svc.c
#	#$(RPCGEN) -m -o ether_svc.c ether.x
	$(RPCGEN) -m -o ether_svc_temp.c ether.x
	-@if test "`grep -c _1_svc ether_svc_temp.c`" != 0; \
	  then echo "mv ether_svc_temp.c ether_svc.c"; \
	       mv ether_svc_temp.c ether_svc.c; \
	  else echo "sed -e 's/_1;/_1_svc;/' ether_svc_temp.c > ether_cvs.c"; \
	       sed -e 's/_1;/_1_svc;/' ether_svc_temp.c > ether_svc.c; \
	       echo "rm -f ether_svc_temp.c"; \
	       rm -f ether_svc_temp.c; \
	  fi


ether.h: ether.x
#	# cp ether.h-dist ether.h
#	#$(RPCGEN) -h -o ether.h ether.x
	$(RPCGEN) -h -o ether_temp.h ether.x
	-@if test "`grep -c _1_svc ether_temp.h`" != 0; \
	  then echo "mv ether_temp.h ether.h"; \
	       mv ether_temp.h ether.h; \
	  else echo "sed -e 's/_1(/_1_svc(/' ether_temp.h > ether.h"; \
	       sed -e 's/_1(/_1_svc(/' ether_temp.h > ether.h; \
	       echo "rm -f ether_temp.h"; \
	       rm -f ether_temp.h; \
	  fi

ether_xdr.c: ether.x ether.h
#	# cp ether_xdr.c-dist ether_xdr.c
	$(RPCGEN) -c -o ether_xdr.c ether.x


packet.o: packet.c packet-common.ic ether.h etherd.h \
	  packet.c-bpf packet.c-linux packet.c-nit packet.c-ultrix-mips 

install: rpc.etherd
	install -c -s -m 755 rpc.etherd $(ETCDIR)

install.man:
	install -c -m 644 etherd.man $(MANDIR)/etherd.$(MANSECT)

clean:
	rm -f *.o *~ ,* .c .h a.out *core rpc.etherd TAGS tags \
		ktrace.out Makefile.bak .emacs_*

clobber: clean
	rm -f $(RPCGENOUTS)

depend: # ether.h
	makedepend -- $(CFLAGS) -- *.c *.h

# DO NOT DELETE THIS LINE -- make depend depends on it.
