#
# makefile for ethernet library
#

# Compilation variables & flags
# CC = gcc -traditional
CC = cc

#
# Sun-3 floating-point options; replace 68881 with soft or fpa as appropriate
#

#FLOAT_OPTION = f68881

OPT = -O
OPTG = -g -O -W

DEFINES = 
INCLUDES = -I. # -I../enet/4.3

# Listing variables and flags

TROFF = ptroff
VGRIND = vgrind


# Suffix rules

.SUFFIXES: .ps

.c.ps:
	$(VGRIND) -lC -t $< > $@

.h.ps:
	$(VGRIND) -lC -t $< > $@


# Installation tools

INSTALL=install -c

RANLIB=ranlib
#RANLIB=ranlib -t


# Installation locations

MANDIR = /usr/local/man
BINDIR = /usr/local/bin
LIBDIR = /usr/local/lib
INCDIR = /usr/local/include

CFLAGS = $(OPT) $(DEFINES) $(INCLUDES)
#CFLAGS = $(OPTG) $(DEFINES) $(INCLUDES)

LINTFLAGS = -bhuxz


# Software components

HDRS = ether.h

CSRCS = etheraddr.c etherints.c ethere2a.c ethera2e.c etherarp.c etherlocal.c \
 ethere2ip.c etherip2e.c ethere2h.c etherh2e.c etherhe2e.c
COBJS = etheraddr.o etherints.o ethere2a.o ethera2e.o etherarp.o etherlocal.o \
 ethere2ip.o etherip2e.o ethere2h.o etherh2e.o etherhe2e.o

# SunOS 4.0
SRCS = $(CSRCS) etherblock.c etherread.c etherreadv.c \
 nitaddr.c nit4self.c nit4intaddr.c nit4open.c nit4write.c nit4writev.c
OBJS = $(COBJS) etherblock.o etherread.o etherreadv.o \
 nitaddr.o nit4self.o nit4intaddr.o nit4open.o nit4write.o nit4writev.o

# SunOS 3.x
#SRCS = $(CSRCS) etherblock.c nitaddr.c nit3self.c nit3intaddr.c \
# nit3open.c nit3read.c nit3readv.c nit3write.c nit3writev.c
#OBJS = $(COBJS) etherblock.o nitaddr.o nit3self.o nit3intaddr.o \
# nit3open.o nit3read.o nit3readv.o nit3write.o nit3writev.o

# Ultrix
#SRCS = $(CSRCS) etherblock.c dliaddr.c dliself.c dliintaddr.c \
# dliopen.c dliread.c dlireadv.c dliwrite.c dliwritev.c
#OBJS = $(COBJS) etherblock.o dliaddr.o dliself.o dliintaddr.o \
# dliopen.o dliread.o dlireadv.o dliwrite.o dliwritev.o

# Stanford enetfilter
#SRCS = $(CSRCS) etherread.c etherreadv.c enetblock.c enetaddr.c \
# enetintaddr.c enetself.c enetopen.c enetwrite.c enetwritev.c
#OBJS = $(COBJS) etherread.o etherreadv.o enetblock.o enetaddr.o \
# enetintaddr.o enetself.o enetopen.o enetwrite.o enetwritev.o


LISTS = etheraddr.ps etherints.ps ethere2a.ps ethera2e.ps etherarp.ps \
 etherlocal.ps ethere2ip.ps etherip2e.ps ethere2h.ps etherh2e.ps etherhe2e.ps \
 etherblock.ps etherread.ps etherreadv.ps nitaddr.ps \
 nit4self.ps nit4intaddr.ps nit4open.ps nit4write.ps nit4writev.ps \
 nit3self.ps nit3intaddr.ps nit3open.ps \
 nit3read.ps nit3readv.ps nit3write.ps nit3writev.ps \
 dliaddr.ps dliself.ps dliintaddr.ps dliopen.ps \
 dliread.ps dlireadv.ps dliwrite.ps dliwritev.ps \
 enetblock.ps enetaddr.ps enetself.ps enetintaddr.ps enetopen.ps \
 enetwrite.ps enetwritev.ps


# Default dependency - remake all out of date object files

default: all

all: libether.a

libether.a: $(OBJS)
	ar crv $@ $(OBJS)
	ranlib $@

etheraddr.o: etheraddr.c
	$(CC) $(CFLAGS) -R -c etheraddr.c

test: ethertest
	./ethertest

ethertest: ethertest.o libether.a
	$(CC) $(LDFLAGS) -o ethertest ethertest.o libether.a

ethertest.o:
	$(CC) $(CFLAGS) -c ../tests/ethertest.c

ctp: ctp.o libether.a
	$(CC) $(LDFLAGS) -o ctp ctp.o libether.a

ctp.o:
	$(CC) $(CFLAGS) -c ../tests/ctp.c

$(OBJS): $(HDRS)


# Fluff test

lint: $(SRCS) ../tests/ethertest.c
	-lint $(LINTFLAGS) $(DEFINES) $(INCLUDES) -I. $?


# Vgrind formatted listing

listing: index $(LISTS) index.ps

index.ps: index
	sort -fu -o index index
	$(VGRIND) -t -x index > index.ps

index: /dev/null
	ctags -tv $(SRCS) $(HDRS) >> index 2>/dev/null


# Utility operations

clean:
	rm -f $(OBJS) libether.a ethertest.o ethertest ctp.o ctp

cleanlists:
	rm -f $(LISTS) index

realclean: clean cleanlists

install: all
	$(INSTALL) ether.3n $(MANDIR)/man3
	cd src; $(INSTALL) ether.h $(INCDIR)
	$(INSTALL) $(SYSTEM)/libether.a $(LIBDIR)/libether.a
	$(RANLIB) $(LIBDIR)/libether.a
