#
# test/Makefile.ssl
#

DIR=		test
TOP=		..
CC=		cc
INCLUDES=	-I../include
CFLAG=		-g
INSTALLTOP=	/usr/local/ssl
MAKEFILE=	Makefile.ssl
MAKE=		make -f $(MAKEFILE)
MAKEDEPEND=	makedepend -f$(MAKEFILE)

PEX_LIBS=
EX_LIBS= -lnsl -lsocket

CFLAGS= $(INCLUDES) $(CFLAG)

GENERAL=Makefile.ssl

DLIBCRYPTO= ../libcrypto.a
DLIBSSL= ../libssl.a
LIBCRYPTO= -L.. -lcrypto
LIBSSL= -L.. -lssl

BNTEST=		bntest
EXPTEST=	exptest
IDEATEST=	ideatest
SHATEST=	shatest
SHA1TEST=	sha1test
MDC2TEST=	mdc2test
MD2TEST=	md2test
MD5TEST=	md5test
RC4TEST=	rc4test
RC2TEST=	rc2test
BFTEST=		bftest
DESTEST=	destest
RANDTEST=	randtest
DHTEST=		dhtest
DSATEST=	dsatest
METHTEST=	methtest
SSLTEST=	ssltest

EXE=	$(BNTEST) $(IDEATEST) $(MD2TEST)  $(MD5TEST)  $(RC4TEST) \
	$(DESTEST) $(SHATEST) $(SHA1TEST) $(MDC2TEST) $(RANDTEST) $(DHTEST) \
	$(RC2TEST) $(BFTEST) $(SSLTEST) $(EXPTEST) $(DSATEST)

# $(METHTEST)

OBJ=	$(BNTEST).o $(IDEATEST).o $(MD2TEST).o  $(MD5TEST).o  $(RC4TEST).o \
	$(DESTEST).o $(SHATEST).o $(SHA1TEST).o $(MDC2TEST).o \
	$(RANDTEST).o $(DHTEST).o \
	$(RC2TEST).o $(BFTEST).o  $(SSLTEST).o  $(DSATEST).o  $(EXPTEST).o
SRC=	$(BNTEST).c $(IDEATEST).c $(MD2TEST).c  $(MD5TEST).c  $(RC4TEST).c \
	$(DESTEST).c $(SHATEST).c $(SHA1TEST).c $(MDC2TEST).c \
	$(RANDTEST).c $(DHTEST).c \
	$(RC2TEST).c $(BFTEST).c  $(SSLTEST).c $(DSATEST).c   $(EXPTEST).c

EXHEADER= 
HEADER=	$(EXHEADER)

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

top:
	(cd ..; $(MAKE) DIRS=$(DIR) all)

all:	exe

exe:	$(EXE)

files:
	perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO

links:
	/bin/rm -f Makefile
	$(TOP)/util/point.sh Makefile.ssl Makefile ;

errors:

install:

tags:
	ctags $(SRC)

tests:	exe apps \
	test_des test_idea test_sha test_md5 test_md2 test_mdc2 \
	test_rc2 test_rc4 test_bf \
	test_rand test_enc test_x509 test_rsa test_crl test_sid test_req \
	test_pkcs7 test_bn test_verify test_dh test_dsa test_reqgen \
	test_ss test_ssl test_ca

apps:
	@(cd ../apps; $(MAKE)  CC='${CC}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' all)

test_des:
	./$(DESTEST)

test_idea:
	./$(IDEATEST)

test_sha:
	./$(SHATEST)
	./$(SHA1TEST)

test_mdc2:
	./$(MDC2TEST)

test_md5:
	./$(MD5TEST)

test_md2:
	./$(MD2TEST)

test_rc2:
	./$(RC2TEST)

test_bf:
	./$(BFTEST)

test_rc4:
	./$(RC4TEST)

test_rand:
	./$(RANDTEST)

test_enc:
	@sh ./testenc

test_x509:
	echo test normal x509v1 certificate
	sh ./tx509 2>/dev/null
	echo test first x509v3 certificate
	sh ./tx509 v3-cert1.pem 2>/dev/null
	echo test second x509v3 certificate
	sh ./tx509 v3-cert2.pem 2>/dev/null

test_rsa:
	@sh ./trsa 2>/dev/null

test_crl:
	@sh ./tcrl 2>/dev/null

test_sid:
	@sh ./tsid 2>/dev/null

test_req:
	@sh ./treq 2>/dev/null
	@sh ./treq testreq2.pem 2>/dev/null

test_pkcs7:
	@sh ./tpkcs7 2>/dev/null
	@sh ./tpkcs7d 2>/dev/null

test_bn:
	@echo 'test a^b%c implementations'
	./$(EXPTEST)
	@echo starting big number library test, could take a while...
	@(./$(BNTEST)|bc) | awk '{ \
if ($$0 != "0") {print "error"; exit(1); } \
if (((NR+1)%64) == 0) print NR+1," tests done"; }'

test_verify:
	@echo "The following command should have some OK's and some failures"
	@echo "There are definitly a few expired certificates"
	../apps/ssleay verify -CApath ../certs ../certs/*.pem

test_dh:
	@echo "Generate as set of DH parameters"
	./$(DHTEST)

test_dsa:
	@echo "Generate as set of DSA parameters"
	./$(DSATEST)

test_reqgen:
	@echo "Generate and verify a certificate request"
	@sh ./testgen

test_ss:
	@echo "Generate and certify a test certificate"
	@sh ./testss

test_ssl:
	@echo "test SSL protocol"
	@sh ./testssl

test_ca:
	@echo "Generate and certify a test certificate via the 'ca' program"
	@sh ./testca

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

depend:
	$(MAKEDEPEND) $(INCLUDES) $(PROGS) $(SRC)

dclean:
	perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
	mv -f Makefile.new $(MAKEFILE)

clean:
	/bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff $(EXE) *.ss log

$(DLIBSSL):
	(cd ../ssl; $(MAKE))

$(DLIBCRYPTO):
	(cd ../crypto; $(MAKE))

$(BNTEST): $(BNTEST).o $(DLIBCRYPTO)
	$(CC) -o $(BNTEST) $(CFLAGS) $(BNTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(EXPTEST): $(EXPTEST).o $(DLIBCRYPTO)
	$(CC) -o $(EXPTEST) $(CFLAGS) $(EXPTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(IDEATEST): $(IDEATEST).o $(DLIBCRYPTO)
	$(CC) -o $(IDEATEST) $(CFLAGS) $(IDEATEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(MD2TEST): $(MD2TEST).o $(DLIBCRYPTO)
	$(CC) -o $(MD2TEST) $(CFLAGS) $(MD2TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(SHATEST): $(SHATEST).o $(DLIBCRYPTO)
	$(CC) -o $(SHATEST) $(CFLAGS) $(SHATEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(SHA1TEST): $(SHA1TEST).o $(DLIBCRYPTO)
	$(CC) -o $(SHA1TEST) $(CFLAGS) $(SHA1TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(MDC2TEST): $(MDC2TEST).o $(DLIBCRYPTO)
	$(CC) -o $(MDC2TEST) $(CFLAGS) $(MDC2TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(MD5TEST): $(MD5TEST).o $(DLIBCRYPTO)
	$(CC) -o $(MD5TEST) $(CFLAGS) $(MD5TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(RC2TEST): $(RC2TEST).o $(DLIBCRYPTO)
	$(CC) -o $(RC2TEST) $(CFLAGS) $(RC2TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(BFTEST): $(BFTEST).o $(DLIBCRYPTO)
	$(CC) -o $(BFTEST) $(CFLAGS) $(BFTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)


$(RC4TEST): $(RC4TEST).o $(DLIBCRYPTO)
	$(CC) -o $(RC4TEST) $(CFLAGS) $(RC4TEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(DESTEST): $(DESTEST).o $(DLIBCRYPTO)
	$(CC) -o $(DESTEST) $(CFLAGS) $(DESTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(RANDTEST): $(RANDTEST).o $(DLIBCRYPTO)
	$(CC) -o $(RANDTEST) $(CFLAGS) $(RANDTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(DHTEST): $(DHTEST).o $(DLIBCRYPTO)
	$(CC) -o $(DHTEST) $(CFLAGS) $(DHTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(DSATEST): $(DSATEST).o $(DLIBCRYPTO)
	$(CC) -o $(DSATEST) $(CFLAGS) $(DSATEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(METHTEST): $(METHTEST).o $(DLIBCRYPTO)
	$(CC) -o $(METHTEST) $(CFLAGS) $(METHTEST).o $(PEX_LIBS) $(LIBCRYPTO) $(EX_LIBS)

$(SSLTEST): $(SSLTEST).o $(DLIBSSL) $(DLIBCRYPTO)
	$(CC) -o $(SSLTEST) $(CFLAGS) $(SSLTEST).o $(PEX_LIBS) $(LIBSSL) $(LIBCRYPTO) $(EX_LIBS)

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