# 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}

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

CFLAGS=${OPTMZ} -I${TOP_SRCDIR}/config -I${TOP_INCDIR} ${XCFLAGS}
LDFLAGS = ${OPTMZ} ${XLDFLAGS}
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}/util.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}/util.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

include ../config/Makefile.version

noversion: install

all: ukinstall kaserver kas kpwvalid klog klog.krb knfs kpasswd ${TOP_LIBDIR}/libkauth.a ${TOP_LIBDIR}/libkauth.krb.a rebuild kdb ${TOP_INCDIR}/afs/kautils.h ${TOP_INCDIR}/afs/kauth.h ${TOP_INCDIR}/afs/kaport.h

test tests: all
	cd test; $(MAKE)

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

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 kadatabase.c 

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

authclient.o: authclient.c ${INCLS}


#authserver.o: authserver.c ${INCLS}

kaerrors.o: kaerrors.c

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

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

kauth.ss.c kauth.cs.c kauth.xdr.c kauth.h: kauth.rg
	${RXGEN} -x kauth.rg

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

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

Kkauth.h: kauth.rg
	${RXGEN} -x -k -h -o Kkauth.h 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
	echo These changes to read_password.c need to be mailed to the Kerberos people; ${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 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 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 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
	${CC} ${CFLAGS} -DAFS_KERBEROS_ENV -c user.c -o user.krb.o

user.o: user.c ${INCLS} ${TOP_INCDIR}/afs/vice.h
	${CC} ${CFLAGS} -c 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
	${CC} ${LDFLAGS} -o krb_udp krb_udp.o libkauth.a ${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/libdes.a ${TOP_LIBDIR}/librxkad.a ${TOP_LIBDIR}/libcom_err.a ${TOP_LIBDIR}/libutil.a ${TOP_LIBDIR}/libaudit.a

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

rebuild: rebuild.o kautils.o ${TOP_LIBDIR}/libcom_err.a ${TOP_LIBDIR}/util.a ${TOP_LIBDIR}/libdes.a
	${CC} ${LDFLAGS} -o rebuild rebuild.o kautils.o \
		${TOP_LIBDIR}/libcom_err.a ${TOP_LIBDIR}/util.a ${TOP_LIBDIR}/libdes.a ${XLIBS} ${TOP_LIBDIR}/libcmd.a

${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 $? $@

ukinstall webinstall: ${UKERNELDIR}/afs ${UKERNELDIR}/afsint ${UKSRCS} Kkauth.h Kkauth.xdr.c Kkauth.cs.c kauth.h
	${INSTALL} Kkauth.h ${UKERNELDIR}/afsint/kauth.h
	${INSTALL} Kkauth.xdr.c ${UKERNELDIR}/afsint/kauth.xdr.c
	${INSTALL} Kkauth.cs.c ${UKERNELDIR}/afsint/kauth.cs.c
	${INSTALL} ${UKSRCS} ${UKERNELDIR}/afs

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

${UKERNELDIR}/afsint:
	mkdir -p $@

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} $? $@

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

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

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

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

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

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

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


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


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

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


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


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

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


${TOP_INCDIR}/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

