CC = gcc
AR = ar
STRIP = strip
LIB = libeps.a
BINS =

AROPTS = -cru
RANLIB = ranlib
LIBDIR = /usr/lib
INCDIR = /usr/include/eps

OBJS = line.o buffer.o unroll.o content.o eps.o int_stream.o rfc2822.o misc.o header.o \
	email.o boundary.o mime.o address.o base64.o roll.o int_buffer.o
INCS = line.h buffer.h unroll.h content.h eps.h int_stream.h rfc2822.h misc.h interface.h \
	header.h email.h boundary.h mime.h address.h base64.h roll.h int_buffer.h
SRCS = line.c buffer.c unroll.c eps.c int_stream.c rfc2822.c misc.c header.c email.c \
	boundary.c mime.c address.c base64.c roll.c int_buffer.c
DEPS = $(INCS) $(SRCS) Makefile

DEFS = -O3 -funroll-loops -Wall -I.

all: $(LIB) $(BINS)

t: $(LIB) t.c
	$(CC) $(DEFS) -o t t.c -leps-1.0 -L. -DOUTPUT

rewrite: $(LIB) rewrite.c
	$(CC) $(DEFS) -o rewrite rewrite.c -leps-1.0 -L. -DRESTART
decode: $(LIB) decode.c
	$(CC) $(DEFS) -o decode decode.c -leps-1.0 -L.
encode: $(LIB) encode.c
	$(CC) $(DEFS) -o encode encode.c -leps-1.0 -L.

$(LIB): $(OBJS)
	$(AR) $(AROPTS) $(LIB) $(OBJS)
	$(RANLIB) $(LIB)

line.o: $(DEPS)
	$(CC) $(DEFS) -o line.o -c line.c
buffer.o: $(DEPS)
	$(CC) $(DEFS) -o buffer.o -c buffer.c
unroll.o: $(DEPS)
	$(CC) $(DEFS) -o unroll.o -c unroll.c
content.o: $(DEPS)
	$(CC) $(DEFS) -o content.o -c content.c
eps.o: $(DEPS)
	$(CC) $(DEFS) -o eps.o -c eps.c
int_stream.o: $(DEPS)
	$(CC) $(DEFS) -o int_stream.o -c int_stream.c
rfc2822.o: $(DEPS)
	$(CC) $(DEFS) -o rfc2822.o -c rfc2822.c
misc.o: $(DEPS)
	$(CC) $(DEFS) -o misc.o -c misc.c
header.o: $(DEPS)
	$(CC) $(DEFS) -o header.o -c header.c
email.o: $(DEPS)
	$(CC) $(DEFS) -o email.o -c email.c
boundary.o: $(DEPS)
	$(CC) $(DEFS) -o boundary.o -c boundary.c
mime.o: $(DEPS)
	$(CC) $(DEFS) -o mime.o -c mime.c
address.o: $(DEPS)
	$(CC) $(DEFS) -o address.o -c address.c
base64.o: $(DEPS)
	$(CC) $(DEFS) -o base64.o -c base64.c
roll.o: $(DEPS)
	$(CC) $(DEFS) -o roll.o -c roll.c
int_buffer.o: $(DEPS)
	$(CC) $(DEFS) -o int_buffer.o -c int_buffer.c

clean:
	rm -f *.o *.core core $(LIB) $(BINS)

install:
	mkdir -p $(LIBDIR)
	mkdir -p $(INCDIR)	
	cp -pf $(INCS) $(INCDIR)
	cp -pf $(LIB) $(LIBDIR)
