# 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
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@


  LIBSA = ${TOP_LIBDIR}/libprot.a ${TOP_LIBDIR}/libubik.a
AFSLIBS = ${TOP_LIBDIR}/librxkad.a ${TOP_LIBDIR}/libsys.a \
	  ${TOP_LIBDIR}/libdes.a ${TOP_LIBDIR}/librx.a \
	  ${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/libaudit.a \
          ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/libafscom_err.a \
	  ${TOP_LIBDIR}/util.a

LDFLAGS = ${SHLIB_LDFLAGS}
   LIBS = ${TOP_LIBDIR}/libafsauthent_pic.a ${TOP_LIBDIR}/libafsrpc_pic.a \
	  ${PAM_LIBS} @LIB_AFSDB@ ${MT_LIBS}
  KLIBS = ktc_krb.o ${TOP_LIBDIR}/libafsauthent_pic.a \
	  ${TOP_LIBDIR}/libafsrpc_pic.a ${PAM_LIBS} @LIB_AFSDB@ ${MT_LIBS}
 SHOBJS = afs_account.o afs_session.o afs_password.o \
	  afs_pam_msg.o afs_message.o AFS_component_version_number.o
   OBJS = $(SHOBJS) test_pam.o
INCLUDES=-I${TOP_OBJDIR}/src/config -I${TOP_INCDIR} 
CFLAGS =  ${PAM_DBG} ${PAM_OPTMZ} ${INCLUDES} ${PAM_CFLAGS}

all: test_pam pam_afs.so.1 pam_afs.krb.so.1

afs_setcred.o: afs_setcred.c afs_pam_msg.h afs_message.h afs_util.h
	${CC} ${CFLAGS} -c ${srcdir}/afs_setcred.c -o afs_setcred.o

afs_setcred_krb.o: afs_setcred.c afs_pam_msg.h afs_message.h afs_util.h
	${CC} ${CFLAGS} -DAFS_KERBEROS_ENV -c ${srcdir}/afs_setcred.c -o afs_setcred_krb.o

afs_auth.o: afs_auth.c afs_pam_msg.h afs_message.h afs_util.h
	${CC} ${CFLAGS} -c ${srcdir}/afs_auth.c -o afs_auth.o

afs_auth_krb.o: afs_auth.c afs_pam_msg.h afs_message.h afs_util.h
	${CC} ${CFLAGS} -DAFS_KERBEROS_ENV -c ${srcdir}/afs_auth.c -o afs_auth_krb.o

afs_util.o: afs_util.c afs_pam_msg.h afs_message.h afs_util.h
	${CC} ${CFLAGS} -c ${srcdir}/afs_util.c -o afs_util.o

afs_util_krb.o: afs_util.c afs_pam_msg.h afs_message.h afs_util.h
	${CC} ${CFLAGS} -DAFS_KERBEROS_ENV -c ${srcdir}/afs_util.c -o afs_util_krb.o

ktc_krb.o: ${srcdir}/../auth/ktc.c ${TOP_INCDIR}/afs/cellconfig.h \
		${TOP_INCDIR}/afs/auth.h ${srcdir}/../auth/keys.h \
		${TOP_INCDIR}/afs/vice.h
	${CC} ${CFLAGS} -DAFS_KERBEROS_ENV -c ${srcdir}/../auth/ktc.c -o $@

pam_afs.so.1: $(SHOBJS) afs_setcred.o afs_auth.o afs_util.o \
		${TOP_LIBDIR}/libafsauthent_pic.a \
		${TOP_LIBDIR}/libafsrpc_pic.a \
		pam_afs.map
	../config/shlib-build -d $(srcdir) -f pam_afs.so.1 -l pam_afs -- \
		afs_setcred.o afs_auth.o afs_util.o ${SHOBJS} ${LIBS}

pam_afs.krb.so.1: $(SHOBJS) afs_setcred_krb.o afs_auth_krb.o afs_util_krb.o \
		ktc_krb.o ${TOP_LIBDIR}/libafsauthent_pic.a \
		${TOP_LIBDIR}/libafsrpc_pic.a \
		pam_afs.map
	../config/shlib-build -d $(srcdir) -f pam_afs.krb.so.1 -l pam_afs -- \
		afs_setcred_krb.o afs_auth_krb.o afs_util_krb.o \
		${SHOBJS} ${KLIBS}

test_pam: test_pam.o
	set -x; \
	case "$(SYS_NAME)" in \
	hp_ux* | ia64_hpux*) \
		$(CC) $(CFLAGS) -o $@ test_pam.o ${PAM_LIBS};; \
	sun*_5*) \
		$(CC) $(CFLAGS) -o $@ test_pam.o ${PAM_LIBS};; \
	*linux*) \
		$(CC) $(CFLAGS) -rdynamic -o $@ test_pam.o -lpam -ldl;; \
	*fbsd*| *nbsd*) \
		$(CC) $(CFLAGS) -rdynamic -o $@ test_pam.o -lpam ;; \
	*) \
		echo No link line for system $(SYS_NAME). ;; \
	esac

install: pam_afs.so.1 pam_afs.krb.so.1
	${INSTALL} -d ${DESTDIR}${libdir}
	${INSTALL_DATA} pam_afs.so.1 ${DESTDIR}${libdir}/pam_afs.so.1
	${INSTALL_DATA} pam_afs.krb.so.1 ${DESTDIR}${libdir}/pam_afs.krb.so.1

dest: pam_afs.so.1 pam_afs.krb.so.1
	${INSTALL} -d ${DEST}/lib
	${INSTALL_DATA} pam_afs.so.1 ${DEST}/lib/pam_afs.so.1
	${INSTALL_DATA} pam_afs.krb.so.1 ${DEST}/lib/pam_afs.krb.so.1

afs_pam_msg.o: afs_pam_msg.c afs_pam_msg.h afs_message.h
afs_message.o: afs_message.c afs_message.h

#
# Misc. targets
#
clean:
	$(RM) -f *.a *.o *.so.1 test_pam core *~ \
		AFS_component_version_number.c pam_afs.exp

include ../config/Makefile.version
