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

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

INSTALLTOP=/usr/local/ssl

LIB=	../libcrypto.a
RSALIB=	libRSAglue.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_enc.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_enc.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

RSASRC= RSAref.c X509_vrf.c
RSAOBJS=RSAref.o X509_vrf.o

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

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


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

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

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 "Generate and certify a test certificate"
	./gentest

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

$(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)

depend:
	makedepend $(INCLUDES) $(SRC)

shar:
	shar $(ALL) >librsa.shar

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

dclean:
	perl -i -ne 'print; last if /^# DO NOT DELETE THIS LINE/;' Makefile

install: all
	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.
