# 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
include @TOP_OBJDIR@/src/config/Makefile.lwptool

BASE_objs= cellconfig.lo keys.lo userok.lo writeconfig.lo authcon.lo \
	 acfg_errors.lo ktc_errors.lo netrestrict.lo token.xdr.lo token.lo \
	 realms.lo

LT_objs= ktc.lo $(BASE_objs)
KRB_objs = ktc.krb.lo $(BASE_objs)

LT_deps= $(top_builddir)/src/opr/liboafs_opr.la \
	 $(top_builddir)/src/comerr/liboafs_comerr.la \
	 $(top_builddir)/src/rx/liboafs_rx.la \
	 $(top_builddir)/src/rxkad/liboafs_rxkad.la \
	 $(top_builddir)/src/audit/liboafs_audit.la \
	 $(top_builddir)/src/util/liboafs_util.la \
	 $(top_builddir)/src/sys/liboafs_sys.la

LT_libs= $(LDFLAGS_roken) $(LIB_roken)

LIBS=libauth.a \
      ${TOP_LIBDIR}/librxkad.a \
      ${TOP_LIBDIR}/libafsrfc3961.a \
      ${TOP_LIBDIR}/librx.a \
      ${TOP_LIBDIR}/libsys.a \
      ${TOP_LIBDIR}/liblwp.a \
      ${TOP_LIBDIR}/util.a

INCLS=cellconfig.h auth.h authcon.h keys.h internal.h token.h

all: liboafs_auth.la libauth_pic.la libpam_auth.la \
     ${TOP_LIBDIR}/libauth.a ${TOP_LIBDIR}/libauth.krb.a \
     depinstall

depinstall: ${TOP_INCDIR}/afs/keys.h \
	${TOP_INCDIR}/afs/cellconfig.h \
	${TOP_INCDIR}/afs/auth.h \
	${TOP_INCDIR}/afs/authcon.h \
	${TOP_INCDIR}/afs/ktc.h \
	${TOP_INCDIR}/afs/token.h \
	token.h \
	Ktoken.xdr.c \
	token.xdr.c

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

generated: acfg_errors.c cellconfig.h ktc_errors.c auth.h

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

${TOP_INCDIR}/afs/cellconfig.h: cellconfig.h
	${INSTALL_DATA} cellconfig.h $@

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

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

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

${TOP_LIBDIR}/libauth.a: libauth.a
	${INSTALL_DATA} libauth.a $@

${TOP_LIBDIR}/libauth.krb.a: libauth.krb.a
	${INSTALL_DATA} libauth.krb.a $@

cellconfig.lo: cellconfig.c ${INCLS}
keys.lo: keys.c ${INCLS}
ktc.lo: ktc.c ${INCLS} ${TOP_INCDIR}/afs/vice.h
writeconfig.lo: writeconfig.c ${INCLS}
authcon.lo: authcon.c ${INCLS}
userok.lo: userok.c ${INCLS}
cellconfig.lo: cellconfig.c ${INCLS}
realms.lo: realms.c ${INCLS}
netrestrict.lo: ${INCLS}

copyauth.o: copyauth.c ${INCLS} AFS_component_version_number.o
setkey.o: setkey.c ${INCLS} AFS_component_version_number.o

$(LT_objs): $(INCLS)

CFLAGS_ktc.krb.lo = -DAFS_KERBEROS_ENV
ktc.krb.lo: ktc.c ${INCLS} ${TOP_INCDIR}/afs/vice.h
	$(LTLWP_CCRULE) $(srcdir)/ktc.c

libauth.a: $(LT_objs)
	$(LT_LDLIB_lwp) $(LT_objs)

libauth.krb.a: $(KRB_objs)
	$(LT_LDLIB_lwp) $(KRB_objs)

liboafs_auth.la: liboafs_auth.la.sym $(LT_objs) $(LT_deps)
	$(LT_LDLIB_shlib) $(LT_objs) $(LT_deps) $(LT_libs)

libauth_pic.la: $(LT_objs)
	$(LT_LDLIB_pic) $(LT_objs)

libpam_auth.la: $(BASE_objs)
	$(LT_LDLIB_pic) $(BASE_objs)

copyauth: copyauth.o ${LIBS}
	$(AFS_LDRULE) copyauth.o ${LIBS} ${XLIBS}

setkey: setkey.o ${LIBS}
	$(AFS_LDRULE) setkey.o ${LIBS} ${XLIBS}

acfg_errors.c: acfg_errors.et
	${COMPILE_ET_C} -p ${srcdir} acfg_errors

cellconfig.h: acfg_errors.et cellconfig.p.h
	${COMPILE_ET_H} -p ${srcdir} acfg_errors -h cellconfig

authcon.lo: cellconfig.h
cellconfig.lo: cellconfig.h
copyauth.o: cellconfig.h
keys.lo: cellconfig.h
ktc.lo: cellconfig.h
netrestrict.lo: cellconfig.h
realms.lo: cellconfig.h
setkey.o: cellconfig.h
userok.lo: cellconfig.h
writeconfig.lo: cellconfig.h

ktc_errors.c: ktc_errors.et
	${COMPILE_ET_C} -p ${srcdir} ktc_errors

auth.h: ktc_errors.et auth.p.h
	${COMPILE_ET_H} -p ${srcdir} ktc_errors -h auth

authcon.lo: auth.h
copyauth.o: auth.h
ktc.lo: auth.h
token.lo: auth.h
userok.lo: auth.h

Ktoken.xdr.c: token.xg
	$(RXGEN) -A -x -k -c -o $@ $(srcdir)/token.xg

token.xdr.c: token.xg
	$(RXGEN) -A -x -c -o $@ ${srcdir}/token.xg

token.h : token.xg
	$(RXGEN) -A -x -h -o $@ ${srcdir}/token.xg

#
# Install targets
#
install: libauth.a libauth.krb.a auth.h cellconfig.h
	${INSTALL} -d ${DESTDIR}${libdir}/afs
	${INSTALL} -d ${DESTDIR}${includedir}/afs
	${INSTALL_DATA} libauth.a ${DESTDIR}${libdir}/afs/libauth.a
	${INSTALL_DATA} libauth.krb.a ${DESTDIR}${libdir}/afs/libauth.krb.a
	${INSTALL_DATA} ${srcdir}/keys.h ${DESTDIR}${includedir}/afs/keys.h
	${INSTALL_DATA} cellconfig.h ${DESTDIR}${includedir}/afs/cellconfig.h
	${INSTALL_DATA} auth.h ${DESTDIR}${includedir}/afs/auth.h
	${INSTALL_DATA} ${srcdir}/ktc.h ${DESTDIR}${includedir}/afs/ktc.h

dest: libauth.a libauth.krb.a auth.h cellconfig.h
	${INSTALL} -d ${DEST}/lib/afs
	${INSTALL} -d ${DEST}/include/afs
	${INSTALL_DATA} libauth.a ${DEST}/lib/afs/libauth.a
	${INSTALL_DATA} libauth.krb.a ${DEST}/lib/afs/libauth.krb.a
	${INSTALL_DATA} ${srcdir}/keys.h ${DEST}/include/afs/keys.h
	${INSTALL_DATA} cellconfig.h ${DEST}/include/afs/cellconfig.h
	${INSTALL_DATA} auth.h ${DEST}/include/afs/auth.h
	${INSTALL_DATA} ${srcdir}/ktc.h ${DEST}/include/afs/ktc.h

#
# Misc. targets
#
.PHONY: test
test:
	cd test && $(MAKE)

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

include ../config/Makefile.version
