# SKIP Source Code License Statement:
# ------------------------------------------------------------------
#   Copyright
#   Sun Microsystems, Inc.
# 
# 
#   Copyright (C) 1994, 1995 Sun Microsystems, Inc.  All Rights
#   Reserved.
# 
#   Permission is hereby granted, free of charge, to any person
#   obtaining a copy of this software and associated documentation
#   files (the "Software"), to deal in the Software without
#   restriction, including without limitation the rights to use,
#   copy, modify, merge, publish, distribute, sublicense, and/or sell
#   copies of the Software or derivatives of the Software, and to 
#   permit persons to whom the Software or its derivatives is furnished 
#   to do so, subject to the following conditions:
# 
#   The above copyright notice and this permission notice shall be
#   included in all copies or substantial portions of the Software.
# 
#   The Software must not be transferred to persons who are not US
#   citizens or permanent residents of the US or exported outside
#   the US (except Canada) in any form (including by electronic
#   transmission) without prior written approval from the US
#   Government. Non-compliance with these restrictions constitutes
#   a violation of the U.S. Export Control Laws.
# 
#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
#   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#   NONINFRINGEMENT.  IN NO EVENT SHALL SUN MICROSYSTEMS, INC., BE LIABLE
#   FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
#   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
#   CONNECTION WITH THE SOFTWARE OR DERIVATES OF THIS SOFTWARE OR 
#   THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# 
#   Except as contained in this notice, the name of Sun Microsystems, Inc.
#   shall not be used in advertising or otherwise to promote
#   the sale, use or other dealings in this Software or its derivatives 
#   without prior written authorization from Sun Microsystems, Inc.

# pragma ident "@(#)Makefile	1.31 95/11/24 Sun Microsystems"
#

include ../../Makefile.defs

COMM_OBJS	=	$(U_DIR)/asn1_der_decode.o $(U_DIR)/asn1_der_encode.o \
			$(U_DIR)/Bstream.o $(U_DIR)/Time.o \
      			$(U_DIR)/ObjId.o $(U_DIR)/Name.o \
			$(U_DIR)/X509Cert.o $(U_DIR)/Sig.o \
			$(U_DIR)/Bigint.o $(U_DIR)/randseed.o \
			$(U_DIR)/Signed.o $(U_DIR)/CRL.o \
			$(U_DIR)/cafuncs.o $(U_DIR)/utils.o \
			$(U_DIR)/userfuncs.o $(U_DIR)/passwd.o \
			$(U_DIR)/HashCert.o \
			$(U_DIR)/X509skip.o $(U_DIR)/SkipCert.o \
			$(U_DIR)/cert_bn_glue.o $(U_DIR)/md5.o $(U_DIR)/md2.o \
			$(U_DIR)/passwd_subr.o $(U_DIR)/descbc.o \
			$(U_DIR)/des.o $(U_DIR)/dessp.o	\
			$(U_DIR)/sha.o $(U_DIR)/dsa_subr.o


OBJS		=	$(COMM_OBJS) $ $(OBJS_$(CRYPTO))
	
TMEM_OBJS	=	$(U_DIR)/t_mem.o

FASTDES		=	../../skip/bdcmod/fast_des_cbc
DES_ECB		=	../../skip/bdcmod/des_ecb

SKIPINC		=	-I$(COMM_INC) -I$(DES_ECB)

DES_HFILES	=	$(COMM_INC)/bdcmod.h $(COMM_INC)/skip_proto.h \
			$(COMM_INC)/skip_crypt.h $(COMM_INC)/skip_types.h \
			$(DES_ECB)/des.h $(SYSINC)


GLOBAL		= 	$(GLOBAL_$(CRYPTO))

HDRS		=	$(GLOBAL)

HFILES		=	Bigint.h Bstream.h CRL.h X509Cert.h \
			Name.h ObjId.h Sig.h Signed.h \
			Time.h asn1_der.h ca.h encrypt.h \
			my_types.h trusted_certs.h userfuncs.h \
			utils.h  SkipCert.h HashCert.h X509skip.h \
			bn_glue.h md2.h md5.h Passwd.h des_user.h \
			sha.h dsa.h

BNDIR		=	../../bnlib
BNINC		=	-I$(BNDIR)
BNLIB		=	$(BNDIR)/$(U_DIR)/libbn.a

CRYPTO_DEFS	= -D$(CRYPTO) -D$(CLASS) $(CRYPTOINC)
CFLAGS		=  $(OPTIM) $(OS) $(D_TEMPLATES) $(CRYPTO_DEFS) $(BNINC) $(U_DEBUG)

SCC		= $(CC) $(OS) $(CRYPTO_DEFS) $(U_DEBUG)

.INIT:
	@[ -d $(U_DIR) ] || mkdir -p $(U_DIR)

all:	$(U_DIR)/libcert.a $(U_DIR)/libtmem.a	\
	$(U_DIR)/test $(U_DIR)/test_passwd $(U_DIR)/test_ca

clean:
	@$(RM) -rf $(U_DIR)
	@$(RM) -rf *.DB
	@-$(SCCSCLEAN)

cleanall:
	@$(RM) -rf *bin.*
	@$(RM) -rf *.DB
	@-$(SCCSCLEAN)

$(U_DIR)/libcert.a: $(OBJS)
	$(AR_CC)  $@ $(OBJS)
	$(RANLIB) $@

$(U_DIR)/libtmem.a: $(TMEM_OBJS)
	$(AR_CC)  $@ $(TMEM_OBJS)
	$(RANLIB) $@

# SOLARIS2 version

$(U_DIR)/t_mem.o: t_mem.c
	$(SCC) -c t_mem.c -o $@

$(U_DIR)/asn1_der_decode.o: asn1_der_decode.C $(HFILES)
	$(C++) $(CFLAGS) -c asn1_der_decode.C -o $@

$(U_DIR)/asn1_der_encode.o: asn1_der_encode.C $(HFILES)
	$(C++) $(CFLAGS) -c asn1_der_encode.C -o $@

$(U_DIR)/Bstream.o: Bstream.C Bstream.h
	$(C++) $(CFLAGS) -c Bstream.C -o $@

$(U_DIR)/Time.o: Time.C Time.h
	$(C++) $(CFLAGS) -c Time.C -o $@

$(U_DIR)/ObjId.o: ObjId.C $(HFILES)
	$(C++) $(CFLAGS) -c ObjId.C -o $@

$(U_DIR)/Name.o: Name.C $(HFILES)
	$(C++) $(CFLAGS) -c Name.C -o $@

$(U_DIR)/Sig.o: Sig.C $(HFILES)
	$(C++) $(CFLAGS) -c Sig.C -o $@

$(U_DIR)/encrypt.o: encrypt.C $(HFILES)
	$(C++) $(CFLAGS) -c encrypt.C -o $@

$(U_DIR)/X509Cert.o: X509Cert.C $(HFILES)
	$(C++) $(CFLAGS) -c  X509Cert.C -o $@

$(U_DIR)/X509skip.o: X509skip.C $(HFILES)
	$(C++) $(CFLAGS) -c  X509skip.C -o $@

$(U_DIR)/randseed.o: randseed.C $(HFILES)
	$(C++) $(CFLAGS) -c randseed.C -o $@

$(U_DIR)/CRL.o: CRL.C $(HFILES)
	$(C++) $(CFLAGS) -c CRL.C -o $@

$(U_DIR)/Signed.o: Signed.C $(HFILES)
	$(C++) $(CFLAGS) -c Signed.C -o $@

$(U_DIR)/cafuncs.o: cafuncs.C $(HFILES) $(HDRS)
	$(C++) $(CFLAGS) -c cafuncs.C -o $@

$(U_DIR)/Bigint.o: Bigint.C Bigint.h 
	$(C++) $(CFLAGS) -c Bigint.C -o $@

$(U_DIR)/utils.o: utils.C $(HFILES) utils.h
	$(C++) $(CFLAGS) -c utils.C -o $@

$(U_DIR)/userfuncs.o: userfuncs.C $(HFILES)
	$(C++) $(CFLAGS) -c userfuncs.C -o $@

$(U_DIR)/passwd.o: passwd.C $(HFILES)
	$(C++) $(CFLAGS) -c passwd.C -o $@

$(U_DIR)/HashCert.o: HashCert.C $(HFILES)
	$(C++) $(CFLAGS) -c HashCert.C -o $@

$(U_DIR)/SkipCert.o: SkipCert.C $(HFILES)
	$(C++) $(CFLAGS) -c SkipCert.C -o $@

$(U_DIR)/cert_bn_glue.o: cert_bn_glue.C $(HFILES)
	$(C++) $(CFLAGS) -c cert_bn_glue.C -o $@

$(U_DIR)/passwd_subr.o: passwd_subr.C $(HFILES)
	$(C++) $(CFLAGS) -c passwd_subr.C -o $@

$(U_DIR)/dsa_subr.o: dsa_subr.C $(HFILES)
	$(C++) $(CFLAGS) -c dsa_subr.C -o $@

$(U_DIR)/md5.o: md5.c $(HFILES)
	$(CC) -c md5.c -o $@

$(U_DIR)/md2.o: md2.c $(HFILES)
	$(CC) -c md2.c -o $@

$(U_DIR)/sha.o: sha.c $(HFILES)
	$(CC) -c $(BNINC) sha.c -o $@

$(U_DIR)/des.o: $(DES_ECB)/des.c $(DES_HFILES)
	$(CC) $(SKIPINC) $(OS) -c $(DES_ECB)/des.c -o $@

$(U_DIR)/dessp.o: $(DES_ECB)/dessp.c $(DES_HFILES)
	$(CC) $(SKIPINC) $(OS) -c $(DES_ECB)/dessp.c -o $@

$(U_DIR)/descbc.o: $(FASTDES)/descbc.c $(DES_HFILES)
	$(CC) $(SKIPINC) $(OS) -c $(FASTDES)/descbc.c -o $@

#
# Test targets
#
$(U_DIR)/test.o: test.C $(HFILES) 
	$(C++) $(CFLAGS) -c test.C -o $@

$(U_DIR)/test: $(U_DIR)/test.o $(U_DIR)/libcert.a $(CRYPTOLIB)
	$(C++) $(CFLAGS) -o $@ $(U_DIR)/test.o \
		$(U_DIR)/libcert.a $(U_DIR)/libtmem.a \
		$(BNLIB) $(CRYPTOLIB) $(CLASSLIB) $(OS_LIB)

$(U_DIR)/test_passwd.o: test_passwd.C $(HFILES) 
	$(C++) $(CFLAGS) -c test_passwd.C -o $@

$(U_DIR)/test_passwd: $(U_DIR)/test_passwd.o $(U_DIR)/libcert.a
	$(C++) $(CFLAGS) -o $@ $(U_DIR)/test_passwd.o \
		$(U_DIR)/libcert.a $(U_DIR)/libtmem.a \
		$(BNLIB) $(CRYPTOLIB) $(CLASSLIB) $(OS_LIB)

$(U_DIR)/test_ca.o: test_ca.C $(HFILES) 
	$(C++) $(CFLAGS) -c test_ca.C -o $@

$(U_DIR)/test_ca: $(U_DIR)/test_ca.o $(U_DIR)/libcert.a
	$(C++) $(CFLAGS) -o $@ $(U_DIR)/test_ca.o \
		$(U_DIR)/libcert.a $(U_DIR)/libtmem.a \
		$(BNLIB) $(CRYPTOLIB) $(CLASSLIB) $(OS_LIB)
