# 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

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}/libdes.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/libcom_err.a \
	${TOP_LIBDIR}/libafsutil.a \
	$(DBM)

UKSRCS=authclient.c user.c kautils.h kaserver.h kaaux.c token.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}/libdes.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/libcom_err.a \
	${TOP_LIBDIR}/libafsutil.a

OBJS=kauth.xdr.o kauth.cs.o kaaux.o client.o authclient.o token.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 token.o kautils.o kalocalcell.o kaerrors.o user.krb.o krb_tf.o


all: kaserver kas kpwvalid klog klog.krb knfs kpasswd rebuild kdb \
	${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 

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) 
	${CC} ${LDFLAGS} -o kaserver 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) ${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}
	${CC} ${CFLAGS} -c ${srcdir}/kadatabase.c 

kaprocs.o: kaprocs.c ${INCLS} kaport.h
	${CC} ${CFLAGS} -c ${srcdir}/kaprocs.c 

authclient.o: authclient.c ${INCLS}

kaerrors.o: kaerrors.c

kaerrors.c kautils.h: 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} -x -C -o $@ ${srcdir}/kauth.rg

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

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

kauth.h: kauth.rg
	${RXGEN} -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} -x -k -C -o Kkauth.cs.c ${srcdir}/kauth.rg

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

Kkauth.h: kauth.rg
	${RXGEN} -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) $@

read_passwd.o: read_passwd.c
	${CC} ${CFLAGS} -c read_passwd.c

token.o: token.c ${INCLS}

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

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

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
	${CC} ${LDFLAGS} -o kas kas.o admin_tools.o kkids.o libkauth.a \
			${LIBS} ${XLIBS}

klog: AFS_component_version_number.o kauth.h kautils.h libkauth.a $(LIBS) \
	klog.o
	${CC} ${LDFLAGS} -o klog klog.o libkauth.a ${LIBS} ${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
	${CC} ${LDFLAGS} -o klog.krb klog.o libkauth.krb.a ${KLIBS} ${XLIBS}

knfs: kauth.h kautils.h libkauth.a $(LIBS) knfs.o
	${CC} ${LDFLAGS} -o knfs knfs.o libkauth.a ${LIBS} ${XLIBS}

knfs.o: knfs.c AFS_component_version_number.o

klogin.o: klogin.c ${INCLS} AFS_component_version_number.o
	${CC} ${CFLAGS} -c ${srcdir}/klogin.c -DKAUTH

klogin: libkauth.a $(LIBS) klogin.o
	${CC} ${LDFLAGS} -o klogin klogin.o libkauth.a ${LIBS} ${XLIBS}

klogin.krb: libkauth.a $(KLIBS) klogin.o
	${CC} ${LDFLAGS} -o klogin.krb klogin.o libkauth.krb.a ${KLIBS} ${XLIBS}

kpasswd.o: kauth.h kautils.h ${INCLS} kpasswd.c AFS_component_version_number.o
	${CC} ${CFLAGS} -c ${srcdir}/kpasswd.c 

kpasswd: kauth.h kautils.h libkauth.a $(LIBS) kpasswd.o kkids.o
	${CC} ${LDFLAGS} -o kpasswd kpasswd.o kkids.o libkauth.a ${LIBS} ${XLIBS}

kpwvalid.o: kpwvalid.c AFS_component_version_number.o
	${CC} ${CFLAGS} -c ${srcdir}/kpwvalid.c

kpwvalid: kpwvalid.o $(LIBS)
	${CC} ${LDFLAGS} -o kpwvalid kpwvalid.o ${LIBS} ${XLIBS}

user.krb.o: user.c ${INCLS} ${TOP_INCDIR}/afs/vice.h
	${CCOBJ} ${CFLAGS} -DAFS_KERBEROS_ENV -c ${srcdir}/user.c -o user.krb.o

user.o: user.c ${INCLS} ${TOP_INCDIR}/afs/vice.h
	${CCOBJ} ${CFLAGS} -c ${srcdir}/user.c

kdb: kdb.o ${INCLS} ${LIBS} libkauth.a
	${CC} ${LDFLAGS} -o kdb kdb.o libkauth.a ${LIBS} ${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)
	${CC} ${LDFLAGS} -o krb_udp krb_udp.o libkauth.a $(KLIBS)

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

rebuild: rebuild.o kautils.o $(LIBS)
	${CC} ${LDFLAGS} -o rebuild rebuild.o kautils.o $(LIBS)

#
# Install targets
#
${TOP_LIBDIR}/libkauth.a: libkauth.a
	${INSTALL} $? $@

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

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

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

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

install: \
	${DESTDIR}${afssrvlibexecdir}/kaserver \
	${DESTDIR}${sbindir}/kas \
	${DESTDIR}${sbindir}/kpwvalid \
	${DESTDIR}${afssrvsbindir}/kas \
	${DESTDIR}${afssrvsbindir}/kpwvalid \
	${DESTDIR}${bindir}/klog \
	${DESTDIR}${bindir}/klog.krb \
	${DESTDIR}${afssrvbindir}/klog \
	${DESTDIR}${afssrvbindir}/klog.krb \
	${DESTDIR}${bindir}/knfs \
	${DESTDIR}${bindir}/kpasswd \
	${DESTDIR}${bindir}/kpwvalid \
	${DESTDIR}${libdir}/afs/libkauth.a \
	${DESTDIR}${libdir}/afs/libkauth.krb.a \
	${DESTDIR}${afssrvsbindir}/kadb_check \
	${DESTDIR}${afssrvsbindir}/kdb \
	${DESTDIR}${includedir}/afs/kautils.h \
	${DESTDIR}${includedir}/afs/kauth.h \
	${DESTDIR}${includedir}/afs/kaport.h

${DESTDIR}${afssrvlibexecdir}/kaserver: kaserver
	${INSTALL} -s $? $@

${DESTDIR}${sbindir}/kas: kas
	${INSTALL} -s $? $@

${DESTDIR}${sbindir}/kpwvalid: kpwvalid
	${INSTALL} $? $@

${DESTDIR}${afssrvsbindir}/kas: kas
	${INSTALL} -s $? $@

${DESTDIR}${afssrvsbindir}/kpwvalid: kpwvalid
	${INSTALL} $? $@

${DESTDIR}${bindir}/klog: klog
	${INSTALL} -s $? $@

${DESTDIR}${bindir}/klog.krb: klog.krb
	${INSTALL} -s $? $@

${DESTDIR}${afssrvbindir}/klog: klog
	${INSTALL} -s $? $@

${DESTDIR}${afssrvbindir}/klog.krb: klog.krb
	${INSTALL} -s $? $@

${DESTDIR}${bindir}/knfs: knfs
	${INSTALL} -s $? $@

${DESTDIR}${bindir}/kpasswd: kpasswd
	${INSTALL} -s $? $@

${DESTDIR}${bindir}/kpwvalid: kpwvalid
	${INSTALL} $? $@

${DESTDIR}${libdir}/afs/libkauth.a: libkauth.a
	${INSTALL} $? $@

${DESTDIR}${libdir}/afs/libkauth.krb.a: libkauth.krb.a
	${INSTALL} $? $@

${DESTDIR}${afssrvsbindir}/kadb_check: rebuild
	${INSTALL} -f $? $@

${DESTDIR}${afssrvsbindir}/kdb: kdb
	${INSTALL} -s $? $@

${DESTDIR}${includedir}/afs/kautils.h: kautils.h
	${INSTALL} $? $@

${DESTDIR}${includedir}/afs/kauth.h: kauth.h
	${INSTALL} $? $@

${DESTDIR}${includedir}/afs/kaport.h: kaport.h
	${INSTALL} $? $@

dest: \
	${DEST}/root.server/usr/afs/bin/kaserver \
	${DEST}/etc/kas \
	${DEST}/etc/kpwvalid \
	${DEST}/root.server/usr/afs/bin/kas \
	${DEST}/root.server/usr/afs/bin/kpwvalid \
	${DEST}/bin/klog \
	${DEST}/bin/klog.krb \
	${DEST}/root.server/usr/afs/bin/klog \
	${DEST}/root.server/usr/afs/bin/klog.krb \
	${DEST}/bin/knfs \
	${DEST}/bin/kpasswd \
	${DEST}/bin/kpwvalid \
	${DEST}/lib/afs/libkauth.a \
	${DEST}/lib/afs/libkauth.krb.a \
	${DEST}/etc/kdb \
	${DEST}/etc/kadb_check \
	${DEST}/include/afs/kautils.h \
	${DEST}/include/afs/kauth.h \
	${DEST}/include/afs/kaport.h

${DEST}/root.server/usr/afs/bin/kaserver: kaserver
	${INSTALL} -s $? $@

${DEST}/etc/kas ${DEST}/root.server/usr/afs/bin/kas: kas 
	${INSTALL} -s $? $@

${DEST}/bin/kpwvalid ${DEST}/etc/kpwvalid ${DEST}/root.server/usr/afs/bin/kpwvalid: kpwvalid 
	${INSTALL} $? $@

${DEST}/bin/klog ${DEST}/root.server/usr/afs/bin/klog: klog 
	${INSTALL} -s $? $@

${DEST}/bin/klog.krb ${DEST}/root.server/usr/afs/bin/klog.krb: klog.krb 
	${INSTALL} -s $? $@

${DEST}/bin/knfs: knfs 
	${INSTALL} -s $? $@

${DEST}/bin/kpasswd: kpasswd 
	${INSTALL} -s $? $@

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

${DEST}/lib/afs/libkauth.krb.a: libkauth.krb.a 
	${INSTALL} $? $@

${DEST}/etc/kadb_check: rebuild
	${INSTALL} -f $? $@

${DEST}/etc/kdb: kdb 
	${INSTALL} -s $? $@

${DEST}/include/afs/kautils.h: kautils.h
	${INSTALL} $? $@

${DEST}/include/afs/kauth.h: kauth.h
	${INSTALL} $? $@

${DEST}/include/afs/kaport.h: kaport.h
	${INSTALL} $? $@

#
# Misc. targets
#
include ../config/Makefile.version

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

