# 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

# */

DEST=@DEST@
TOP_INCDIR=@TOP_INCDIR@
TOP_LIBDIR=@TOP_LIBDIR@
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
sbindir=@sbindir@
libexecdir=@libexecdir@
libdir=@libdir@
includedir=@includedir@
mandir=@mandir@
afssrvbindir=@afssrvbindir@
afssrvsbindir=@afssrvsbindir@
afssrvlibexecdir=@afssrvlibexecdir@
RXGEN=${TOP_SRCDIR}/rxgen/rxgen
TOP_SRCDIR=@TOP_SRCDIR@
SYS_NAME=@AFS_SYSNAME@

SHELL = /bin/sh

include ../config/Makefile.${SYS_NAME}

KERNELDIR = ../libafs/
UKERNELDIR = ../libuafs/
COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et

CFLAGS=${OPTMZ} -I${TOP_SRCDIR}/config -I${TOP_INCDIR} ${XCFLAGS}
INCLS=${TOP_INCDIR}/rx/rx.h ${TOP_INCDIR}/rx/xdr.h \
       rxkad.h

OBJS=rxkad_client.o rxkad_server.o rxkad_common.o ticket.o rxkad_errs.o \
	fcrypt.o crypt_conn.o

fc_test_OBJS=fc_test.o

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

all: kinstall ukinstall ${TOP_LIBDIR}/librxkad.a fc_test \
	${TOP_INCDIR}/rx/rxkad.h

#
# Install targets
#
kinstall: \
	${KERNELDIR}/afs/private_data.h \
	${KERNELDIR}/afs/rxkad.h \
	${KERNELDIR}/afs/sboxes.h \
	${KERNELDIR}/afs/fcrypt.h \
	${KERNELDIR}/afs/fcrypt.c \
	${KERNELDIR}/afs/crypt_conn.c \
	${KERNELDIR}/afs/rxkad_client.c \
	${KERNELDIR}/afs/rxkad_common.c 

${KERNELDIR}/afs/private_data.h: private_data.h
	${INSTALL} $? $@

${KERNELDIR}/afs/rxkad.h: rxkad.h
	${INSTALL} $? $@

${KERNELDIR}/afs/sboxes.h: sboxes.h
	${INSTALL} $? $@

${KERNELDIR}/afs/fcrypt.h: fcrypt.h
	${INSTALL} $? $@

${KERNELDIR}/afs/fcrypt.c: fcrypt.c
	${INSTALL} $? $@

${KERNELDIR}/afs/crypt_conn.c: crypt_conn.c
	${INSTALL} $? $@

${KERNELDIR}/afs/rxkad_client.c: rxkad_client.c
	${INSTALL} $? $@

${KERNELDIR}/afs/rxkad_common.c: rxkad_common.c
	${INSTALL} $? $@

ukinstall: \
	${UKERNELDIR}/afs \
	${UKERNELDIR}/rx \
	${UKERNELDIR}/afs/private_data.h \
	${UKERNELDIR}/afs/rxkad.h \
	${UKERNELDIR}/rx/rxkad.h \
	${UKERNELDIR}/afs/sboxes.h \
	${UKERNELDIR}/afs/fcrypt.h \
	${UKERNELDIR}/afs/fcrypt.c \
	${UKERNELDIR}/afs/crypt_conn.c \
	${UKERNELDIR}/afs/rxkad_client.c \
	${UKERNELDIR}/afs/rxkad_common.c \
	${UKERNELDIR}/afs/ticket.c \
	${UKERNELDIR}/afs/rxkad_server.c \
	${UKERNELDIR}/afs/lifetimes.h \
	${UKERNELDIR}/afs/rxkad_errs.c 


${UKERNELDIR}/afs:
	mkdir -p $?

${UKERNELDIR}/rx:
	mkdir -p $?

${UKERNELDIR}/afs/private_data.h: private_data.h
	${INSTALL} $? $@

${UKERNELDIR}/afs/rxkad.h: rxkad.h
	${INSTALL} $? $@

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

${UKERNELDIR}/afs/lifetimes.h: lifetimes.h
	${INSTALL} $? $@

${UKERNELDIR}/afs/ticket.c: ticket.c
	${INSTALL} $? $@

${UKERNELDIR}/afs/sboxes.h: sboxes.h
	${INSTALL} $? $@

${UKERNELDIR}/afs/fcrypt.h: fcrypt.h
	${INSTALL} $? $@

${UKERNELDIR}/afs/fcrypt.c: fcrypt.c
	${INSTALL} $? $@

${UKERNELDIR}/afs/crypt_conn.c: crypt_conn.c
	${INSTALL} $? $@

${UKERNELDIR}/afs/rxkad_client.c: rxkad_client.c
	${INSTALL} $? $@

${UKERNELDIR}/afs/rxkad_errs.c: rxkad_errs.c
	${INSTALL} $? $@

${UKERNELDIR}/afs/rxkad_server.c: rxkad_server.c
	${INSTALL} $? $@

${UKERNELDIR}/afs/rxkad_common.c: rxkad_common.c
	${INSTALL} $? $@

install:   ${DESTDIR}${libdir}/librxkad.a ${DESTDIR}${includedir}/rx/rxkad.h

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

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

#
# Build targets
#

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

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

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} rxkad_errs -h rxkad

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

fcrypt.o: fcrypt.c fcrypt.h sboxes.h rxkad.h
	${CC} ${CFLAGS} -c fcrypt.c

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

tcrypt.o: tcrypt.c AFS_component_version_number.o

fc_test: ${fc_test_OBJS}
	${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 \
		crypt_conn.c fcrypt.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.

crypt_conn.c: domestic/crypt_conn.c
	${INSTALL} $? $@

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

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

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

tcrypt.c: domestic/tcrypt.c
	${INSTALL} $? $@

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

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

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

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

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

