# 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.shared

  OPTMZ = ${PAM_OPTMZ}
    DBG = ${PAM_DBG}
   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


MODULE_CFLAGS=${PAM_CFLAGS}

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

CFLAGS_afs_setcred_krb.o = -DAFS_KERBEROS_ENV
CFLAGS_afs_auth_krb.o   = -DAFS_KERBEROS_ENV
CFLAGS_afs_util_krb.o   = -DAFS_KERBEROS_ENV
CFLAGS_ktc_krb.o        = -DAFS_KERBEROS_ENV -I../auth

afs_setcred.o: afs_setcred.c afs_pam_msg.h afs_message.h afs_util.h

afs_setcred_krb.o: afs_setcred.c afs_pam_msg.h afs_message.h afs_util.h
	$(AFS_CCRULE) $(srcdir)/afs_setcred.c

afs_auth.o: afs_auth.c afs_pam_msg.h afs_message.h afs_util.h

afs_auth_krb.o: afs_auth.c afs_pam_msg.h afs_message.h afs_util.h
	$(AFS_CCRULE) $(srcdir)/afs_auth.c

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

afs_util_krb.o: afs_util.c afs_pam_msg.h afs_message.h afs_util.h
	$(AFS_CCRULE) $(srcdir)/afs_util.c

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
	$(AFS_CCRULE) $(srcdir)/../auth/ktc.c

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} $(LDFLAGS_hcrypto) $(LDFLAGS_roken) \
		$(LIB_hcrypto) $(LIB_roken)

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} $(LDFLAGS_hcrypto) $(LDFLAGS_roken) \
		$(LIB_hcrypto) $(LIB_roken)

test_pam: test_pam.o
	$(Q)set -x; \
	case "$(SYS_NAME)" in \
	hp_ux* | ia64_hpux*) \
		$(AFS_LDRULE_NOQ) test_pam.o ${PAM_LIBS};; \
	sun*_5*) \
		$(AFS_LDRULE_NOQ) test_pam.o ${PAM_LIBS};; \
	*linux*) \
		$(AFS_LDRULE_NOQ) -rdynamic test_pam.o -lpam -ldl;; \
	*fbsd*| *nbsd*) \
		$(AFS_LDRULE_NOQ) -rdynamic 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
