# 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

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


INCLS=${TOP_INCDIR}/ubik.h \
             ${TOP_INCDIR}/lwp.h \
             ${TOP_INCDIR}/lock.h  \
             ${TOP_INCDIR}/rx/rx.h \
             ${TOP_INCDIR}/rx/xdr.h \
	     ${TOP_INCDIR}/rx/rxkad.h \
	     ${TOP_INCDIR}/afs/com_err.h \
	kaserver.h kauth.h kautils.h

LIBS=${TOP_LIBDIR}/libubik.a \
	${TOP_LIBDIR}/libprot.a \
	${TOP_LIBDIR}/libauth.a \
	${TOP_LIBDIR}/librxkad.a \
	${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/librxstat.a \
	${TOP_LIBDIR}/librx.a \
	${TOP_LIBDIR}/libsys.a  \
	${TOP_LIBDIR}/liblwp.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/libafscom_err.a \
	${TOP_LIBDIR}/libafsutil.a \
	${TOP_LIBDIR}/libopr.a \
	$(DBM) \
	${TOP_LIBDIR}/libafsrfc3961.a \
	${TOP_LIBDIR}/libafshcrypto_lwp.a

UKSRCS=authclient.c user.c kautils.h kaserver.h kaaux.c katoken.c \
       kalocalcell.c client.c kaerrors.c

KLIBS=${TOP_LIBDIR}/libubik.a \
	${TOP_LIBDIR}/libprot.a \
	${TOP_LIBDIR}/libauth.krb.a \
	${TOP_LIBDIR}/librxkad.a \
	${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/librx.a \
	${TOP_LIBDIR}/libsys.a  \
	${TOP_LIBDIR}/liblwp.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/libafscom_err.a \
	${TOP_LIBDIR}/libafsutil.a \
	${TOP_LIBDIR}/libopr.a \
	${TOP_LIBDIR}/libafsrfc3961.a \
	${TOP_LIBDIR}/libafshcrypto_lwp.a

OBJS=kauth.xdr.o kauth.cs.o kaaux.o client.o authclient.o katoken.o kautils.o kalocalcell.o kaerrors.o user.o krb_tf.o
KOBJS=kauth.xdr.o kauth.cs.o kaaux.o client.o authclient.o katoken.o kautils.o kalocalcell.o kaerrors.o user.krb.o krb_tf.o

all: kaserver kas kpwvalid klog klog.krb knfs kpasswd rebuild kdb ka-forwarder \
	${TOP_LIBDIR}/libkauth.a \
	${TOP_LIBDIR}/libkauth.krb.a \
	depinstall

depinstall: \
	kaerrors.c kauth.cs.c kauth.xdr.c \
	${TOP_INCDIR}/afs/kautils.h \
	${TOP_INCDIR}/afs/kauth.h \
	${TOP_INCDIR}/afs/kaport.h 

generated: \
	kaerrors.c kautils.h \
	kauth.cs.c kauth.ss.c kauth.xdr.c kauth.h

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

${TOP_LIBDIR}/libkauth.krb.a: libkauth.krb.a
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/kautils.h: kautils.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/kauth.h: kauth.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/kaport.h: kaport.h
	${INSTALL_DATA} $? $@

test tests: all
	cd test; $(MAKE)

kaserver: kautils.o kalocalcell.o kadatabase.o kaprocs.o kalog.o kauth.ss.o kauth.xdr.o kaserver.o kaaux.o krb_udp.o kaauxdb.o $(LIBS) 
	$(AFS_LDRULE) kaserver.o kautils.o kalocalcell.o kadatabase.o \
		krb_udp.o kaprocs.o kalog.o kauth.ss.o kauth.xdr.o kaaux.o \
		kaauxdb.o \
		$(LIBS) $(LIB_roken) $(LIB_crypt) ${XLIBS} \
		${TOP_LIBDIR}/libaudit.a

kaserver.o: kaserver.c ${INCLS} AFS_component_version_number.o

kautils.o: kautils.c ${INCLS}

kalocalcell.o: kalocalcell.c ${INCLS}

kadatabase.o: kadatabase.c ${INCLS}

kaprocs.o: kaprocs.c ${INCLS} kaport.h

authclient.o: authclient.c ${INCLS}

kaauxdb.o: kaauxdb.c

kaerrors.o: kaerrors.c

kautils.h: kaerrors.c

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

kauth.ss.o: kauth.ss.c
kauth.cs.o: kauth.cs.c
kauth.xdr.o: kauth.xdr.c kauth.h

$(UKSRCS): kauth.h

kauth.cs.c: kauth.rg
	${RXGEN} -A -u -x -C -o $@ ${srcdir}/kauth.rg

kauth.ss.c: kauth.rg
	${RXGEN} -A -x -S -o $@ ${srcdir}/kauth.rg

kauth.xdr.c: kauth.rg
	${RXGEN} -A -x -c -o $@ ${srcdir}/kauth.rg

kauth.h: kauth.rg
	${RXGEN} -A -u -x -h -o $@ ${srcdir}/kauth.rg

kauth.xdr.c: kauth.h
kauth.cs.c: kauth.h
kauth.ss.c: kauth.h

Kkauth.cs.c: kauth.rg Kkauth.h
	${RXGEN} -A -x -k -C -o Kkauth.cs.c ${srcdir}/kauth.rg

Kkauth.xdr.c: kauth.rg
	${RXGEN} -A -x -k -c -o Kkauth.xdr.c ${srcdir}/kauth.rg

Kkauth.h: kauth.rg
	${RXGEN} -A -x -k -h -o Kkauth.h ${srcdir}/kauth.rg

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

libkauth.krb.a: $(KOBJS) AFS_component_version_number.o
	-$(RM) -f $@
	$(AR) crv $@ $(KOBJS) AFS_component_version_number.o
	$(RANLIB) $@

katoken.o: katoken.c ${INCLS}

client.o: client.c ${INCLS} AFS_component_version_number.o

kas.o: kas.c ${INCLS} AFS_component_version_number.o

CFLAGS_admin_tools.o= @CFLAGS_NOERROR@
admin_tools.o: admin_tools.c ${INCLS} kaport.h

kkids.o: kkids.c ${INCLS}

krb_tf.o: krb_tf.c ${INCLS}

kas: kauth.h kautils.h admin_tools.o libkauth.a $(LIBS) kas.o kkids.o
	$(AFS_LDRULE) kas.o admin_tools.o kkids.o libkauth.a \
		${LIBS} $(LIB_roken) $(LIB_crypt) ${XLIBS}

klog: AFS_component_version_number.o kauth.h kautils.h libkauth.a $(LIBS) \
	klog.o
	$(AFS_LDRULE) klog.o libkauth.a \
		${LIBS} $(LIB_roken) $(LIB_crypt) ${XLIBS}

klog.o: klog.c kauth.h kautils.h AFS_component_version_number.o

klog.krb: kauth.h kautils.h libkauth.krb.a $(KLIBS) klog.o
	$(AFS_LDRULE) klog.o libkauth.krb.a \
		${KLIBS} $(LIB_roken) $(LIB_crypt) ${XLIBS}

knfs: kauth.h kautils.h libkauth.a $(LIBS) knfs.o
	$(AFS_LDRULE) knfs.o libkauth.a \
		${LIBS} $(LIB_roken) $(LIB_crypt) ${XLIBS}

knfs.o: knfs.c AFS_component_version_number.o

CFLAGS_klogin.o = -DKAUTH
klogin.o: klogin.c ${INCLS} AFS_component_version_number.o

klogin: libkauth.a $(LIBS) klogin.o
	$(AFS_LDRULE) klogin.o libkauth.a \
		${LIBS} $(LIB_roken) $(LIB_crypt) ${XLIBS}

klogin.krb: libkauth.a $(KLIBS) klogin.o
	$(AFS_LDRULE) klogin.o libkauth.krb.a \
		${KLIBS} $(LIB_roken) $(LIB_crypt) ${XLIBS}

kpasswd.o: kauth.h kautils.h ${INCLS} kpasswd.c AFS_component_version_number.o

kpasswd: kauth.h kautils.h libkauth.a $(LIBS) kpasswd.o kkids.o
	$(AFS_LDRULE) kpasswd.o kkids.o libkauth.a \
		${LIBS} $(LIB_roken) $(LIB_crypt) ${XLIBS}

kpwvalid.o: kpwvalid.c AFS_component_version_number.o

kpwvalid: kpwvalid.o $(LIBS)
	$(AFS_LDRULE) kpwvalid.o \
		${LIBS} $(LIB_roken) ${XLIBS}

CFLAGS_user.krb.o = -DAFS_KERBEROS_ENV
user.krb.o: user.c ${INCLS} ${TOP_INCDIR}/afs/vice.h
	$(AFS_CCRULE) $(srcdir)/user.c

user.o: user.c ${INCLS} ${TOP_INCDIR}/afs/vice.h

kdb: kdb.o ${INCLS} ${LIBS} libkauth.a
	$(AFS_LDRULE) kdb.o libkauth.a \
		${LIBS} $(LIB_roken) ${XLIBS}

kdb.o: kdb.c AFS_component_version_number.o

krb_udp.o: krb_udp.c kaserver.h kautils.h kauth.h prot.h ${TOP_INCDIR}/lwp.h AFS_component_version_number.o

krb_udp: krb_udp.o libkauth.a $(KLIBS)
	$(AFS_LDRULE) krb_udp.o libkauth.a \
		$(KLIBS) $(LIB_roken)

ka-forwarder.o: ka-forwarder.c

ka-forwarder: ka-forwarder.o
	$(AFS_LDRULE) ka-forwarder.o \
		${LIBS} $(LIB_roken) ${XLIBS}

rebuild.o: rebuild.c $(INCLS) AFS_component_version_number.o

rebuild: rebuild.o kautils.o $(LIBS)
	$(AFS_LDRULE) rebuild.o kautils.o \
		$(LIBS) $(LIB_roken) ${XLIBS}

#
# Install targets
#
install: kaserver kas kpwvalid kas klog klog.krb knfs kpasswd libkauth.a \
		libkauth.krb.a rebuild kdb ka-forwarder kautils.h kauth.h \
		kaport.h
	${INSTALL} -d ${DESTDIR}${afssrvlibexecdir}
	${INSTALL} -d ${DESTDIR}${bindir}
	${INSTALL} -d ${DESTDIR}${sbindir}
	${INSTALL} -d ${DESTDIR}${afssrvbindir}
	${INSTALL} -d ${DESTDIR}${afssrvsbindir}
	${INSTALL} -d ${DESTDIR}${libdir}/afs
	${INSTALL} -d ${DESTDIR}${includedir}/afs
	${INSTALL_PROGRAM} kaserver ${DESTDIR}${afssrvlibexecdir}/kaserver
	${INSTALL_PROGRAM} kas ${DESTDIR}${sbindir}/kas
	${INSTALL_PROGRAM} kpwvalid ${DESTDIR}${sbindir}/kpwvalid
	${INSTALL_PROGRAM} kas ${DESTDIR}${afssrvsbindir}/kas
	${INSTALL_PROGRAM} kpwvalid ${DESTDIR}${afssrvsbindir}/kpwvalid
	${INSTALL_PROGRAM} klog ${DESTDIR}${bindir}/klog
	${INSTALL_PROGRAM} klog.krb ${DESTDIR}${bindir}/klog.krb
	${INSTALL_PROGRAM} klog ${DESTDIR}${afssrvbindir}/klog
	${INSTALL_PROGRAM} klog.krb ${DESTDIR}${afssrvbindir}/klog.krb
	${INSTALL_PROGRAM} knfs ${DESTDIR}${bindir}/knfs
	${INSTALL_PROGRAM} kpasswd ${DESTDIR}${bindir}/kpasswd
	${INSTALL_PROGRAM} kpwvalid ${DESTDIR}${bindir}/kpwvalid
	${INSTALL_DATA} libkauth.a ${DESTDIR}${libdir}/afs/libkauth.a
	${INSTALL_DATA} libkauth.krb.a ${DESTDIR}${libdir}/afs/libkauth.krb.a
	${INSTALL_PROGRAM} rebuild ${DESTDIR}${afssrvsbindir}/kadb_check
	${INSTALL_PROGRAM} kdb ${DESTDIR}${afssrvsbindir}/kdb
	${INSTALL_PROGRAM} ka-forwarder ${DESTDIR}${afssrvsbindir}/ka-forwarder
	${INSTALL_DATA} kautils.h ${DESTDIR}${includedir}/afs/kautils.h
	${INSTALL_DATA} kauth.h ${DESTDIR}${includedir}/afs/kauth.h
	${INSTALL_DATA} ${srcdir}/kaport.h ${DESTDIR}${includedir}/afs/kaport.h

dest: kaserver kas kpwvalid kas klog klog.krb knfs kpasswd libkauth.a \
		libkauth.krb.a rebuild kdb ka-forwarder kautils.h kauth.h \
		kaport.h
	${INSTALL} -d ${DEST}/root.server/usr/afs/bin
	${INSTALL} -d ${DEST}/etc
	${INSTALL} -d ${DEST}/bin
	${INSTALL} -d ${DEST}/lib/afs
	${INSTALL} -d ${DEST}/include/afs
	${INSTALL_PROGRAM} kaserver ${DEST}/root.server/usr/afs/bin/kaserver
	${INSTALL_PROGRAM} kas ${DEST}/etc/kas
	${INSTALL_PROGRAM} kpwvalid ${DEST}/etc/kpwvalid
	${INSTALL_PROGRAM} kas ${DEST}/root.server/usr/afs/bin/kas
	${INSTALL_PROGRAM} kpwvalid ${DEST}/root.server/usr/afs/bin/kpwvalid
	${INSTALL_PROGRAM} klog ${DEST}/bin/klog
	${INSTALL_PROGRAM} klog.krb ${DEST}/bin/klog.krb
	${INSTALL_PROGRAM} klog ${DEST}/root.server/usr/afs/bin/klog
	${INSTALL_PROGRAM} klog.krb ${DEST}/root.server/usr/afs/bin/klog.krb
	${INSTALL_PROGRAM} knfs ${DEST}/bin/knfs
	${INSTALL_PROGRAM} kpasswd ${DEST}/bin/kpasswd
	${INSTALL_PROGRAM} kpwvalid ${DEST}/bin/kpwvalid
	${INSTALL_DATA} libkauth.a ${DEST}/lib/afs/libkauth.a
	${INSTALL_DATA} libkauth.krb.a ${DEST}/lib/afs/libkauth.krb.a
	${INSTALL_PROGRAM} kdb ${DEST}/etc/kdb
	${INSTALL_PROGRAM} rebuild ${DEST}/etc/kadb_check
	${INSTALL_PROGRAM} ka-forwarder ${DEST}/root.server/usr/afs/bin/ka-forwarder
	${INSTALL_DATA} kautils.h ${DEST}/include/afs/kautils.h
	${INSTALL_DATA} kauth.h ${DEST}/include/afs/kauth.h
	${INSTALL_DATA} ${srcdir}/kaport.h ${DEST}/include/afs/kaport.h

#
# Misc. targets
#
clean:
	$(RM) -f *.o *.a *.xdr.c *.cs.c *.ss.c core \
		kaserver kas klog multiklog kpasswd klogin rebuild \
		ka-forwarder \
		kauth.h kautils.h kaerrors.c kpwvalid \
		AFS_component_version_number.c \
		klog.krb knfs klogin.krb kdb Kkauth.h

include ../config/Makefile.version
