# 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
OBJS= cellconfig.o ktc.o userok.o writeconfig.o authcon.o \
    acfg_errors.o ktc_errors.o
KOBJS= cellconfig.o ktc.krb.o userok.o writeconfig.o authcon.o \
    acfg_errors.o ktc_errors.o

CFLAGS=-g -I${TOP_SRCDIR}/config -I${TOP_INCDIR} ${XCFLAGS}
LIBS=libauth.a ${TOP_LIBDIR}/libsys.a \
      ${TOP_LIBDIR}/librxkad.a ${TOP_LIBDIR}/libdes.a \
      ${TOP_LIBDIR}/librx.a ${TOP_LIBDIR}/libsys.a \
      ${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/util.a
INCLS=cellconfig.h auth.h keys.h
KSRCS=auth.h
UKSRCS=${KSRCS} cellconfig.h acfg_errors.c keys.h cellconfig.c \
       ktc.c authcon.c ktc_errors.c

all: kinstall ukinstall ${TOP_LIBDIR}/libauth.a ${TOP_LIBDIR}/libauth.krb.a ${TOP_INCDIR}/afs/keys.h ${TOP_INCDIR}/afs/cellconfig.h ${TOP_INCDIR}/afs/auth.h copyauth setkey

cellconfig.o: cellconfig.c ${INCLS}
ktc.o: ktc.c ${INCLS} ${TOP_INCDIR}/afs/vice.h
writeconfig.o: writeconfig.c ${INCLS}
authcon.o: authcon.c ${INCLS}
userok.o: userok.c ${INCLS}
cellconfig.o: cellconfig.c ${INCLS}
copyauth.o: copyauth.c ${INCLS} AFS_component_version_number.o
setkey.o: setkey.c ${INCLS} AFS_component_version_number.o

ktc.krb.o: ktc.c ${INCLS} ${TOP_INCDIR}/afs/vice.h
	${CC} ${CFLAGS} -DAFS_KERBEROS_ENV -c ktc.c -o ktc.krb.o

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

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

copyauth: copyauth.o 
	$(CC) $(CFLAGS) -o copyauth copyauth.o ${LIBS} ${XLIBS}

setkey: setkey.o 
	${CC} $(CFLAGS) -o setkey setkey.o ${LIBS} ${XLIBS}

acfg_errors.o: acfg_errors.c

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

ktc_errors.o: ktc_errors.c

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

#
# Install targets
#
kinstall: ${KERNELDIR}/afs/auth.h

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

ukinstall: \
	${UKERNELDIR}/afs/auth.h \
	${UKERNELDIR}/afs/cellconfig.h \
	${UKERNELDIR}/afs/acfg_errors.c \
	${UKERNELDIR}/afs/keys.h \
	${UKERNELDIR}/afs/cellconfig.c \
	${UKERNELDIR}/afs/ktc.c \
	${UKERNELDIR}/afs/authcon.c \
	${UKERNELDIR}/afs/ktc_errors.c

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

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

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

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

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

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

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

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

install:   ${DESTDIR}${libdir}/afs/libauth.a ${DESTDIR}${libdir}/afs/libauth.krb.a ${DESTDIR}${includedir}/afs/keys.h ${DESTDIR}${includedir}/afs/cellconfig.h ${DESTDIR}${includedir}/afs/auth.h ${DESTDIR}${sbindir}/copyauth 

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

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

${DEST}/etc/copyauth: copyauth
	${INSTALL} $? $@

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

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

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

#
# Misc. targets
#
test: 
	cd test; $(MAKE)

clean:
	$(RM) -f *.o *.a copyauth setkey auth.h cellconfig.h acfg_errors.c ktc_errors.c core\
	AFS_component_version_number.c

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

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

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

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

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

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

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

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

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

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

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

dest:   ${DEST}/lib/afs/libauth.a ${DEST}/lib/afs/libauth.krb.a ${DEST}/include/afs/keys.h ${DEST}/include/afs/cellconfig.h ${DEST}/include/afs/auth.h ${DEST}/etc/copyauth 

