# 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


  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}/libcom_err.a \
	  ${TOP_LIBDIR}/util.a

LDFLAGS = ${SHLIB_LDFLAGS}
   LIBS = ${TOP_LIBDIR}/libkauth.a ${LIBSA} ${TOP_LIBDIR}/libauth.a \
	  ${AFSLIBS} ${PAM_LIBS} @LIB_AFSDB@
  KLIBS = ${TOP_LIBDIR}/libkauth.krb.a ${LIBSA} ${TOP_LIBDIR}/libauth.krb.a \
	  ${AFSLIBS} ${PAM_LIBS} @LIB_AFSDB@
 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 =  ${DEBUG} ${INCLUDES} ${PAM_CFLAGS}

all: test_pam ${TOP_LIBDIR}/pam_afs.so.1 ${TOP_LIBDIR}/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

pam_afs.so.1: $(SHOBJS) afs_setcred.o afs_auth.o afs_util.o
	set -x; \
	case "$(SYS_NAME)" in \
	hp_ux* | ia64_hpux*) \
		$(LD) $(LDFLAGS) -c ${srcdir}/mapfile.hp -o $@ \
			afs_setcred.o afs_auth.o afs_util.o \
			$(SHOBJS) $(LIBS) ;; \
	sun*_5*) \
		$(LD) $(LDFLAGS) -M ${srcdir}/mapfile -o $@ \
			afs_setcred.o afs_auth.o afs_util.o \
			$(SHOBJS) $(LIBS) ;; \
	*linux*) \
		$(CC) $(LDFLAGS) -o $@ afs_setcred.o \
			afs_auth.o afs_util.o $(SHOBJS) $(LIBS) ;;\
	*fbsd*) \
		$(CC) $(LDFLAGS) -o $@ afs_setcred.o \
			afs_auth.o afs_util.o $(SHOBJS) $(LIBS) ;;\
	* ) \
		echo No link line for system $(SYS_NAME). ;; \
	esac

pam_afs.krb.so.1: $(SHOBJS) afs_setcred_krb.o afs_auth_krb.o afs_util_krb.o
	set -x; \
	case "$(SYS_NAME)" in \
	hp_ux* | ia64_hpux*) \
		$(LD) $(LDFLAGS) -c ${srcdir}/mapfile.hp -o $@ \
			afs_setcred_krb.o afs_auth_krb.o afs_util_krb.o \
			$(SHOBJS) $(LDFLAGS) $(KLIBS) ;; \
	sun*_5*) \
		$(LD) $(LDFLAGS) -M ${srcdir}/mapfile -o $@ \
			afs_setcred_krb.o afs_auth_krb.o afs_util_krb.o \
			$(SHOBJS) $(LDFLAGS) $(KLIBS) ;; \
	*linux*) \
		$(CC) $(LDFLAGS) -o $@ afs_setcred_krb.o \
			afs_auth_krb.o afs_util_krb.o $(SHOBJS) $(KLIBS) ;;\
	*fbsd*) \
		$(CC) $(LDFLAGS) -o $@ afs_setcred_krb.o \
			afs_auth_krb.o afs_util_krb.o $(SHOBJS) $(KLIBS) ;;\
	* ) \
		echo No link line for system $(SYS_NAME). ;; \
	esac

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*) \
		$(CC) $(CFLAGS) -rdynamic -o $@ test_pam.o -lpam ;; \
	*) \
		echo No link line for system $(SYS_NAME). ;; \
	esac

install:  ${DESTDIR}${libdir}/pam_afs.so.1 ${DESTDIR}${libdir}/pam_afs.krb.so.1

${DEST}/lib/pam_afs.so.1: pam_afs.so.1
	${INSTALL} $? $@

${DEST}/lib/pam_afs.krb.so.1: pam_afs.krb.so.1
	${INSTALL} $? $@

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

include ../config/Makefile.version

${DESTDIR}${libdir}/pam_afs.so.1: pam_afs.so.1
	${INSTALL} $? $@

${TOP_LIBDIR}/pam_afs.so.1: pam_afs.so.1
	${INSTALL} $? $@

${DESTDIR}${libdir}/pam_afs.krb.so.1: pam_afs.krb.so.1
	${INSTALL} $? $@

${TOP_LIBDIR}/pam_afs.krb.so.1: pam_afs.krb.so.1
	${INSTALL} $? $@

dest:  ${DEST}/lib/pam_afs.so.1 ${DEST}/lib/pam_afs.krb.so.1

