#
# Makefile for all the SSL related library routines and utilities
VERSION	= 0.6.4
#
# make install will install:
#   libraries into $INSTALLTOP/lib
#   headers   into $INSTALLTOP/include
#   utilities into $INSTALLTOP/bin
#
# By default INSTALLTOP is set to /usr/local/ssl
# If you want things install elsewere, consider running
# perl util/ssldir.pl /new/path
#
# Interesting Mailing Lists:
#     ssl-bugs@mincom.oz.au
#     ssl-users@mincom.oz.au
#
# To join the Mailing Lists:
#     ssl-bugs-request@mincom.oz.au
#     ssl-users-request@mincom.oz.au
#
# If you must get hold of people directly (we much prefer the above
# lists to be used if the question is of general interest!):
#	Eric Young <eay@mincom.oz.au>
#	Tim Hudson <tjh@mincom.oz.au>
#	or both    <ssleay@mincom.oz.au>
#
# The primary distribution of SSLeay is from
# ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL
#
# NOCONST - Define for C compilers that don't like the const key word.
# NOPROTO - Define in if your compiler does not support prototypes.
# RSAref  - Define if we are to link with RSAref.
# NOIDEA  - Define to build without the IDEA algorithm
# NORC4   - Define to build without the RC4 algorithm
# NORC2   - Define to build without the RC2 algorithm
# THREADS - Define when building with threads, you will probably also need any
#	    system defines as well, i.e. _REENTERANT for Solaris 2.[34]
# TERMIO  - Define the termio terminal subsystem, needed if sgtty is missing.
# TERMIOS - Define the termios terminal subsystem, Silicon Graphics.
# LOCK_DEBUG - turns on lots of lock debug output :-)
# REF_CHECK - turn on some xyz_free() assertions.
# CRYPTO_MDEBUG - turns on my 'memory leak' detecting stuff

CC= cc
CFLAG= -O -DNOPROTO
PEX_LIBS= -L. -L.. -L../.. -L../../..
EX_LIBS= 
BN_MULW= bn_mulw.o

# If you change the INSTALLTOP, make sure to also change the values
# in crypto/location.h
INSTALLTOP=/usr/local/ssl

MAKEFILE= Makefile.ssl
MAKE=	  make -f $(MAKEFILE)

MAN1=1
MAN3=3
SHELL=/bin/sh

TOP=	.
DIRS=	crypto ssl rsaref apps test tools
ONEDIRS=out tmp
EDIRS=	times doc bugs util include certs ms shlib ssl3 mt
MISC=	COPYRIGHT Configure INSTALL Makefile.ssl Makefile \
	README README.050 README.051 README.052 TODO \
	README.060 README.061 README.062 README.063 README.064 \
	VERSION PROBLEMS MINFO makefile.one e_os.h \
	MICROSOFT makevms.com
WDIRS=	windows
LIB=	libcrypto.a
LIBS=	libcrypto.a libssl.a 

GENERAL=	Makefile
BASENAME=	SSLeay
NAME=		$(BASENAME)-$(VERSION)
TARFILE=	$(NAME).tar
WTARFILE=	$(NAME)-win.tar
EX_HEADER=
HEADER=		e_os.h

all:
	@for i in $(DIRS) ;\
	do \
	(cd $$i; echo "making $$i..."; \
	$(MAKE) CC='${CC}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_MULW='${BN_MULW}' all ); \
	done;

sub_all:
	@for i in $(DIRS) ;\
	do \
	(cd $$i; echo "making $$i..."; \
	$(MAKE) CC='${CC}' CFLAG='${CFLAG}' SDIRS='$(SDIRS)' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_MULW='${BN_MULW}' all ); \
	done;

clean:
	/bin/rm -f *.o core a.out fluff
	@for i in $(DIRS) ;\
	do \
	(cd $$i; echo "cleaning $$i..."; \
	$(MAKE) clean ); \
	/bin/rm -f $(LIB); \
	done;
	/bin/rm -f *.a *.o speed.* *.map *.so .pure core
	/bin/rm -f $(TARFILE)
	@for i in $(ONEDIRS) ;\
	do \
	/bin/rm -f $$i/*; \
	done

makefile.one: files
	perl util/mk1mf.pl >makefile.one; \
	sh util/do_ms.sh

files:	MINFO
	perl $(TOP)/util/files.pl Makefile.ssl > $(TOP)/MINFO
	@for i in $(DIRS) ;\
	do \
	(cd $$i; echo "making 'files' in $$i..."; \
	$(MAKE) files ); \
	done;

links:
	/bin/rm -f Makefile;
	./util/point.sh Makefile.ssl Makefile;
	@for i in $(DIRS) ;\
	do \
	(cd $$i; echo "making links in $$i..."; \
	$(MAKE) links ); \
	done;
	# @(cd apps; sh ./mklinks)
	sh tools/c_rehash certs

dclean:
	/bin/rm -f *.bak
	@for i in $(DIRS) ;\
	do \
	(cd $$i; echo "undoing makedepend in $$i..."; \
	$(MAKE) dclean ); \
	done;

rehash:
	@(PATH="`pwd`/apps:${PATH}"; sh tools/c_rehash certs)

test:	tests

tests:
	(cd test; echo "testing $$i..."; \
	$(MAKE) CC='${CC}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_MULW='${BN_MULW}' tests );
	@apps/ssleay version -a

depend:
	@for i in $(DIRS) ;\
	do \
	(cd $$i; echo "making dependancies $$i..."; \
	$(MAKE) depend ); \
	done;

lint:
	@for i in $(DIRS) ;\
	do \
	(cd $$i; echo "making lint $$i..."; \
	$(MAKE) lint ); \
	done;

tags:
	@for i in $(DIRS) ;\
	do \
	(cd $$i; echo "making tags $$i..."; \
	$(MAKE) tags ); \
	done;

errors:
	@for i in $(DIRS) ;\
	do \
	(cd $$i; echo "making errors in $$i..."; \
	$(MAKE) errors ); \
	done;

tar:
	@(cd ..;\
	mv $(BASENAME) $(NAME); \
	export STUFF; \
	for i in $(MISC) $(DIRS) $(EDIRS) $(ONEDIRS) ;\
	do \
		STUFF="$$STUFF $(NAME)/$$i"; \
	done; \
	tar cf $(NAME)/$(TARFILE) $$STUFF; \
	mv $(NAME) $(BASENAME) ) 
	gzip -f $(TARFILE)

dist:	
	perl Configure dist
	@$(MAKE) dist_pem_h
	@$(MAKE) clean
	@$(MAKE) dclean
	@(cd apps; sh ./rmlinks)
	@$(MAKE) files
	@$(MAKE) makefile.one
	@$(MAKE) tar

dist_pem_h:
	(cd crypto/pem; $(MAKE) CFLAG='${CFLAG}' pem.h; $(MAKE) clean)

install: all
	@-mkdir -p $(INSTALLTOP)/bin 2>/dev/null
	@-mkdir -p $(INSTALLTOP)/lib 2>/dev/null
	@-mkdir -p $(INSTALLTOP)/include 2>/dev/null
	@-mkdir -p $(INSTALLTOP)/certs 2>/dev/null
	@-mkdir -p $(INSTALLTOP)/private 2>/dev/null
	@for i in $(DIRS) ;\
	do \
	(cd $$i; echo "installing $$i..."; \
	$(MAKE) CC='${CC}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' EX_LIBS='${EX_LIBS}' install ); \
	done
	@for i in $(LIBS) ;\
	do \
	(	echo installing $$i; \
		cp $$i $(INSTALLTOP)/lib; \
		util/ranlib.sh $(INSTALLTOP)/lib/$$i; \
		chmod 644 $(INSTALLTOP)/lib/$$i ) \
	done

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