# 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
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

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}/libafsutil.a

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

generated: \
	rxkad_errs.c rxkad.h

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

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

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

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

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

#
# 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: rxkad_server.c fcrypt.h private_data.h  ${INCLS}
	$(CC) $(CFLAGS) -c ${srcdir}/rxkad_server.c

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}
	$(CC) $(CFLAGS) -c ${srcdir}/ticket.c

ticket5.o: ticket5.c v5gen.c v5der.c v5gen-rewrite.h ${INCLS}
	$(CC) -I${srcdir} $(CFLAGS) -c ${srcdir}/ticket5.c

crc.o: crc.c ${INCLS}

md4.o: md4.c ${INCLS}

md5.o: md5.c ${INCLS}

fcrypt.o: fcrypt.c fcrypt.h sboxes.h rxkad.h rxkad_prototypes.h

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

tcrypt.o: tcrypt.c AFS_component_version_number.o

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}

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

dest: librxkad.a fcrypt.h rxkad.h rxkad_prototypes.h
	${INSTALL} -d ${DEST}/lib
	${INSTALL} -d ${DEST}/include/rx
	${INSTALL_DATA} librxkad.a ${DEST}/lib/librxkad.a
	${INSTALL_DATA} ${srcdir}/fcrypt.h ${DEST}/include/rx/fcrypt.h
	${INSTALL_DATA} rxkad.h ${DEST}/include/rx/rxkad.h
	${INSTALL_DATA} ${srcdir}/rxkad_prototypes.h \
		${DEST}/include/rx/rxkad_prototypes.h

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

test:
	cd test; $(MAKE)

include ../config/Makefile.version
