# 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@
COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et
RXGEN=${TOP_SRCDIR}/rxgen/rxgen
TOP_SRCDIR=@TOP_SRCDIR@
SYS_NAME=@AFS_SYSNAME@
SHELL=/bin/sh
KERNELDIR = ../libafs/

include ../config/Makefile.${SYS_NAME}

  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 = ${SHARE_LDFLAGS}
   LIBS = ${TOP_LIBDIR}/libkauth.a ${LIBSA} ${TOP_LIBDIR}/libauth.a \
	  ${AFSLIBS} ${PAMLIBS} @LIB_AFSDB@
  KLIBS = ${TOP_LIBDIR}/libkauth.krb.a ${LIBSA} ${TOP_LIBDIR}/libauth.krb.a \
	  ${AFSLIBS} ${PAMLIBS} @LIB_AFSDB@
 SHOBJS = afs_auth.o afs_account.o afs_session.o afs_password.o \
	  afs_pam_msg.o afs_message.o afs_util.o AFS_component_version_number.o
   OBJS = $(SHOBJS) test_pam.o
INCLUDES=-I${TOP_SRCDIR}/config -I${TOP_INCDIR} \
	-I/usr/include -I/usr/include/sys
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 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 afs_setcred.c -o afs_setcred_krb.o

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

pam_afs.krb.so.1: $(SHOBJS) afs_setcred_krb.o
	set -x; \
	case "$(SYS_NAME)" in \
	hp_ux*) \
		$(LD) $(LDFLAGS) -c mapfile.hp -o $@ \
			afs_setcred_krb.o $(SHOBJS) $(LDFLAGS) $(KLIBS) ;; \
	sun*_5*) \
		$(LD) $(LDFLAGS) -M mapfile -o $@ \
			afs_setcred_krb.o $(SHOBJS) $(LDFLAGS) $(KLIBS) ;; \
	*linux*) \
		$(CC) $(LDFLAGS) -o $@ afs_setcred_krb.o $(SHOBJS) $(KLIBS) ;;\
	*fbsd*) \
		$(CC) $(LDFLAGS) -o $@ afs_setcred_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*) \
		$(CC) $(CFLAGS) -o $@ test_pam.o ${PAMLIBS};; \
	sun*_5*) \
		$(CC) $(CFLAGS) -o $@ test_pam.o ${PAMLIBS};; \
	*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_auth.o: afs_auth.c afs_pam_msg.h afs_message.h afs_util.h
afs_pam_msg.o: afs_pam_msg.c afs_pam_msg.h afs_message.h
afs_message.o: afs_message.c afs_message.h
afs_util.o: afs_util.c afs_util.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

