# Copyright 2000, International Business Machines Corporation and others.
# All Rights Reserved.
# 
# This software has been released under the terms of the IBM Public
# License.  For details, see the LICENSE file in the top-level source
# directory or online at http://www.openafs.org/dl/license10.html
#
# Portions Copyright (c) 2003 Apple Computer, Inc.

srcdir=@srcdir@
include @TOP_OBJDIR@/src/config/Makefile.config

INCLS=${TOP_INCDIR}/rx/rx.h ${TOP_INCDIR}/rx/xdr.h \
	${TOP_INCDIR}/rx/fcrypt.h \
	rxkad.h rxkad_prototypes.h fcrypt.h v5gen.h \
	hash.h md4.h md5.h

OBJS=rxkad_client.o rxkad_server.o rxkad_common.o rxkad_errs.o \
	fcrypt.o crypt_conn.o ticket.o ticket5.o crc.o \
	md4.o md5.o

fc_test_OBJS=fc_test.o

fc_test_LIBS=\
	${TOP_LIBDIR}/librxkad.a \
	${TOP_LIBDIR}/libdes.a \
	${TOP_LIBDIR}/librx.a \
	${TOP_LIBDIR}/liblwp.a \
	${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/libafsutil.a

all: ${TOP_LIBDIR}/librxkad.a fc_test depinstall

depinstall: \
	${TOP_INCDIR}/rx/rxkad.h \
	${TOP_INCDIR}/rx/rxkad_prototypes.h \
	${TOP_INCDIR}/rx/fcrypt.h

#
# Install targets
#
install:   \
	${DESTDIR}${libdir}/librxkad.a \
	${DESTDIR}${includedir}/rx/fcrypt.h \
	${DESTDIR}${includedir}/rx/rxkad.h \
	${DESTDIR}${includedir}/rx/rxkad_prototypes.h

${DEST}/lib/librxkad.a: librxkad.a
	${INSTALL} $? $@

${DEST}/include/rx/fcrypt.h: fcrypt.h
	${INSTALL} $? $@

${DEST}/include/rx/rxkad.h: rxkad.h
	${INSTALL} $? $@

${DEST}/include/rx/rxkad_prototypes.h: rxkad_prototypes.h
	${INSTALL} $? $@

#
# Build targets
#

librxkad.a: ${OBJS} AFS_component_version_number.o
	-$(RM) -f $@
	$(AR) crv $@ ${OBJS} AFS_component_version_number.o
	$(RANLIB) $@

rxkad_client.o: fcrypt.h private_data.h rxkad_client.c ${INCLS}

rxkad_server.o: fcrypt.h private_data.h rxkad_server.c ${INCLS}

rxkad_common.o: fcrypt.h private_data.h rxkad_common.c ${INCLS}

rxkad_errs.o: rxkad_errs.c

rxkad_errs.c rxkad.h: rxkad_errs.et rxkad.p.h
	$(RM) -f rxkad.h rxkad_errs.c
	${COMPILE_ET} -p ${srcdir} rxkad_errs -h rxkad

ticket.o: ticket.c lifetimes.h ${INCLS}

ticket5.o: ticket5.c v5gen.c v5der.c v5gen-rewrite.h ${INCLS}

crc.o: crc.c ${INCLS}

md4.o: md4.c ${INCLS}
 
md5.o: md5.c ${INCLS}

fcrypt.o: ${srcdir}/domestic/fcrypt.c fcrypt.h sboxes.h rxkad.h rxkad_prototypes.h
	${CCOBJ} ${CFLAGS} -c ${srcdir}/domestic/fcrypt.c

crypt_conn.o: ${srcdir}/domestic/crypt_conn.c fcrypt.h private_data.h ${INCLS}
	${CCOBJ} ${CFLAGS} -c ${srcdir}/domestic/crypt_conn.c

tcrypt.o: ${srcdir}/domestic/tcrypt.c AFS_component_version_number.o
	${CCOBJ} ${CFLAGS} -c ${srcdir}/domestic/fcrypt.c

tcrypt: tcrypt.o librxkad.a 
	${CC} -o tcrypt tcrypt.o librxkad.a

fc_test: ${fc_test_OBJS} ${fc_test_LIBS}
	${CC} ${CFLAGS} -o fc_test ${fc_test_OBJS} ${fc_test_LIBS} ${XLIBS}

fc_test.o: ${INCLS}

#
# Misc. targets
#

clean: 
	$(RM) -f *.o *.a tcrypt core rxkad_errs.c rxkad.h \
		AFS_component_version_number.c \
		fcrypt.h sboxes.h \
		fc_test

test:
	cd test; $(MAKE)
# These sources are kept in a separate directory so that we can use an
# ACL to comply with source export restrictions.

fcrypt.h: domestic/fcrypt.h
	${INSTALL} $? $@

sboxes.h: domestic/sboxes.h
	${INSTALL} $? $@

include ../config/Makefile.version
${DESTDIR}${libdir}/librxkad.a: librxkad.a
	${INSTALL} $? $@

${TOP_LIBDIR}/librxkad.a: librxkad.a
	${INSTALL} $? $@

${DESTDIR}${includedir}/rx/fcrypt.h: fcrypt.h
	${INSTALL} $? $@

${DESTDIR}${includedir}/rx/rxkad.h: rxkad.h
	${INSTALL} $? $@

${DESTDIR}${includedir}/rx/rxkad_prototypes.h: rxkad_prototypes.h
	${INSTALL} $? $@

${TOP_INCDIR}/rx/fcrypt.h: fcrypt.h
	${INSTALL} $? $@

${TOP_INCDIR}/rx/rxkad.h: rxkad.h
	${INSTALL} $? $@

${TOP_INCDIR}/rx/rxkad_prototypes.h: rxkad_prototypes.h
	${INSTALL} $? $@

dest:   \
	${DEST}/lib/librxkad.a \
	${DEST}/include/rx/fcrypt.h \
	${DEST}/include/rx/rxkad.h \
	${DEST}/include/rx/rxkad_prototypes.h

