CC=    cc
INCLUDES= -I../md -I../lhash -I../des
CFLAGS= -g $(INCLUDES) -DDG_GCC_BUG -DIRIX_CC_BUG

LIBS=   -L.. -L../des -ldes $(EX_LIBS) #../libefence.a

INSTALLTOP=/usr/local/ssl

LIB= ../libcrypto.a

LIBDIR=/usr/local/lib
BINDIR=/usr/local/bin
INCDIR=/usr/local/include
MANDIR=/usr/local/man
MAN1=1
MAN3=3
SHELL=/bin/sh

BNTEST= bntest
GENRSA= genrsa
X509=   x509
RSA=    rsa
VERIFY= verify
PARSE=	der_parse

EXE=	$(GENRSA) $(X509) $(RSA) $(VERIFY) $(PARSE)

OBJS=	bn.o bn_regs.o der.o rsa_lib.o rsa_gen.o PEM.o Buffer.o \
	X509_lib.o X509_i2D.o X509_i2f.o X509_D2i.o X509_f2i.o \
	X509_obj.o X509_vrf.o X509_def.o \
	errno.o errstr.o

GENERAL=Makefile bn_prime.pl

LIBSRC=	bn.c bn_regs.c der.c rsa_lib.c rsa_gen.c PEM.c Buffer.c \
	X509_lib.c X509_i2D.c X509_i2f.c X509_D2i.c X509_f2i.c \
	X509_obj.c X509_vrf.c X509_def.c \
	errno.c errstr.c

SRC=	$(BNTEST).c $(GENRSA).c $(X509).c $(RSA).c $(PARSE) \
	$(VERIFY).c \
	${LIBSRC}

EXHEADER=Buffer.h PEM.h X509.h X509_obj.h bn.h der.h
HEADER= PEM_locl.h bn_prime.h location.h $(EXHEADER)


ALL=    $(GENERAL) $(SRC) $(HEADER)

all: bn_prime.h $(LIB) $(BNTEST) $(EXE)

tags:
	-ctags $(SRC) $(HEADER)

bn_prime.h:
	./bn_prime.pl 1024 >bn_prime.h

test:	all
	@echo starting big number library test, could take a while...
	@./$(BNTEST)|bc| awk '{ \
if ($$0 != "0") {print "error"; exit; } \
if (((NR+1)%64) == 0) print NR+1," tests done"; }'
	@echo "The following command should have some OK's and some failures"
	SSL_CERT_DIR="./hash"; export SSL_CERT_DIR; ./$(VERIFY) hash/*
	@echo "The following command should end up with less that 2 lines of output"
	@echo "If there are several lines of dots, something is wrong."
	./$(GENRSA) 300

$(LIB): $(OBJS)
	ar r $(LIB) $(OBJS)
	-if test -s /bin/ranlib; then /bin/ranlib $(LIB); \
	else if test -s /usr/bin/ranlib; then /usr/bin/ranlib $(LIB); \
	else exit 0; fi; fi

$(BNTEST): $(BNTEST).o $(LIB)
	$(CC) $(CFLAGS) -o $(BNTEST) $(BNTEST).o $(LIB) $(LIBS)

$(GENRSA): $(GENRSA).o $(LIB)
	$(CC) $(CFLAGS) -o $(GENRSA) $(GENRSA).o $(LIB) $(LIBS)

$(X509): $(X509).o $(LIB)
	$(CC) $(CFLAGS) -o $(X509) $(X509).o $(LIB) $(LIBS)

$(RSA): $(RSA).o $(LIB)
	$(CC) $(CFLAGS) -o $(RSA) $(RSA).o $(LIB) $(LIBS)

$(VERIFY): $(VERIFY).o $(LIB)
	$(CC) $(CFLAGS) -o $(VERIFY) $(VERIFY).o $(LIB) $(LIBS)

$(PARSE): $(PARSE).o $(LIB)
	$(CC) $(CFLAGS) -o $(PARSE) $(PARSE).o $(LIB) $(LIBS)

lint:
	lint $(INCLUDES) $(SRC)>fluff

tar:
	tar cf librsa.tar $(ALL)

shar:
	shar $(ALL) >librsa.shar

clean:
	/bin/rm -f *.o core fluff $(BNTEST) $(EXE) tags core

install: $(LIB) $(EXE) 
	for i in $(EXE) make_cert ;\
	do \
	cp $$i ${INSTALLTOP}/bin; \
	chmod 755 ${INSTALLTOP}/bin/$$i; \
	done;
	for i in $(EXHEADER) ;\
	do \
	cp $$i ${INSTALLTOP}/include; \
	chmod a+r ${INSTALLTOP}/include/$$i; \
	done;

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

