# 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

ENABLE_PTHREADED_UBIK=@ENABLE_PTHREADED_UBIK@

INCLS=${TOP_INCDIR}/ubik.h \
	${TOP_INCDIR}/lock.h  \
	${TOP_INCDIR}/lwp.h \
	${TOP_INCDIR}/rx/rx.h \
	${TOP_INCDIR}/rx/xdr.h \
	${TOP_INCDIR}/afs/keys.h \
	${TOP_INCDIR}/afs/cellconfig.h \
	ptserver.h ptclient.h ptuser.h ptint.h pterror.h map.h ptprototypes.h

LINCLS=${TOP_INCDIR}/ubik.h \
	${TOP_INCDIR}/lock.h \
	${TOP_INCDIR}/rx/rx.h \
	${TOP_INCDIR}/rx/xdr.h  \
	${TOP_INCDIR}/rx/rxkad.h \
	${TOP_INCDIR}/afs/auth.h \
	${TOP_INCDIR}/afs/cellconfig.h \
	ptclient.h ptuser.h ptint.h pterror.h

LIBS=   ${TOP_LIBDIR}/libubik.a \
	${TOP_LIBDIR}/libauth.a \
	${TOP_LIBDIR}/librxkad.a \
	${TOP_LIBDIR}/librxstat.a \
	${TOP_LIBDIR}/librx.a \
	${TOP_LIBDIR}/liblwp.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/libafscom_err.a \
	${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/libaudit.a \
	${TOP_LIBDIR}/libafsutil.a \
	${TOP_LIBDIR}/libopr.a \
	${TOP_LIBDIR}/libafsrfc3961.a \
	${TOP_LIBDIR}/libafshcrypto_lwp.a

LT_objs = ptuser.lo pterror.lo ptint.cs.lo ptint.xdr.lo display.lo

LT_deps = $(top_builddir)/src/opr/liboafs_opr.la \
	  $(top_builddir)/src/rx/liboafs_rx.la \
	  $(top_builddir)/src/ubik/liboafs_ubik.la \
	  $(top_builddir)/src/auth/liboafs_auth.la
LT_libs =

all: ptserver pts pt_util db_verify liboafs_prot.la libprot_pic.la \
     ${TOP_LIBDIR}/libprot.a depinstall readgroup readpwd testpt ptclient

generated: \
	pterror.h pterror.c \
	ptint.cs.c ptint.ss.c ptint.xdr.c ptint.h

depinstall: \
	ptint.cs.c ptint.xdr.c \
	${TOP_INCDIR}/afs/prclient.h \
	${TOP_INCDIR}/afs/prerror.h \
	${TOP_INCDIR}/afs/print.h \
	${TOP_INCDIR}/afs/prserver.h \
	${TOP_INCDIR}/afs/ptclient.h \
	${TOP_INCDIR}/afs/ptuser.h \
	${TOP_INCDIR}/afs/pterror.h \
	${TOP_INCDIR}/afs/ptint.h \
	${TOP_INCDIR}/afs/ptserver.h

${TOP_LIBDIR}/libprot.a: libprot.a
	${INSTALL_DATA} $? $@

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

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

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

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

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

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

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

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

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

#
# Build targets
#
ptserver: ptserver.o ptutils.o ptprocs.o ptint.ss.o ptint.xdr.lo utils.o $(LIBS) map.o
	$(AFS_LDRULE) ptserver.o ptutils.o ptprocs.o ptint.ss.o .lwp/ptint.xdr.o \
		utils.o map.o $(LIBS) $(LIB_roken) ${XLIBS}

ptserver.o: ptserver.c ${INCLS} AFS_component_version_number.c

# When supergroups is enabled, some parts of ptserver cast between
# incompatible structs.
CFLAGS_ptutils.o = @CFLAGS_NOSTRICT@
CFLAGS_ptprocs.o = @CFLAGS_NOSTRICT@

ptutils.o: ptutils.c ${INCLS}
ptprocs.o: ptprocs.c ${INCLS}
utils.o: utils.c ${INCLS}
map.o: map.c ${INCLS}
ptint.ss.o: ptint.ss.c ptint.xdr.c ptint.xg
ptint.cs.lo: ptint.cs.c ptint.xdr.c ptint.xg
ptint.xdr.lo: ptint.xdr.c ptint.h ptint.xg

ptint.cs.c: ptint.xg
	${RXGEN} -A -x -C -u -o $@ ${srcdir}/ptint.xg

ptint.ss.c: ptint.xg
	${RXGEN} -A -x -S -o $@ ${srcdir}/ptint.xg

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

ptint.h: ptint.xg
	${RXGEN} -A -x -h -u -o $@ ${srcdir}/ptint.xg

ptint.cs.c: ptint.h
ptint.ss.c: ptint.h
ptint.xdr.c: ptint.h

Kptint.cs.c: ptint.xg Kptint.h
	${RXGEN} -A -x -k -C -o Kptint.cs.c ${srcdir}/ptint.xg

Kptint.xdr.c: ptint.xg
	${RXGEN} -A -x -k -c -o Kptint.xdr.c ${srcdir}/ptint.xg

Kptint.h: ptint.xg
	${RXGEN} -A -x -k -h -o Kptint.h ${srcdir}/ptint.xg

db_verify.o: db_verify.c ${INCLS} AFS_component_version_number.c

db_verify: db_verify.o libprot.a $(LIBS)
	$(AFS_LDRULE) db_verify.o libprot.a \
		$(LIBS) $(LIB_roken) ${XLIBS}

ptclient: ptclient.o libprot.a $(LIBS)
	$(AFS_LDRULE) ptclient.o libprot.a \
		$(LIBS) $(LIB_roken) ${XLIBS}

ptclient.o: ptclient.c ${INCLS} AFS_component_version_number.c

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

pterror.h: pterror.et
	${COMPILE_ET_H} -p ${srcdir} pterror

db_verify.o db_verify.lo: pterror.h
ptclient.o ptclient.lo: pterror.h
ptprocs.o ptprocs.lo: pterror.h
pts.o pts.lo: pterror.h
ptuser.o ptuser.lo: pterror.h
pt_util.o pt_util.lo: pterror.h
ptutils.o ptutils.lo: pterror.h
readgroup.o readgroup.lo: pterror.h
testpt.o testpt.lo: pterror.h
utils.o utils.lo: pterror.h

display.lo: $(INCLS)
ptuser.lo: $(LINCLS)

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

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

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

pts: pts.o libprot.a ${TOP_LIBDIR}/libcmd.a $(LIBS)
	$(AFS_LDRULE) pts.o ${TOP_LIBDIR}/libcmd.a libprot.a \
		${LIBS} $(LIB_roken) ${XLIBS}

pts.o: pts.c ${LINCLS} ${TOP_INCDIR}/afs/cmd.h AFS_component_version_number.c

readgroup: readgroup.o libprot.a $(LIBS)
	$(AFS_LDRULE) readgroup.o libprot.a \
		${LIBS} $(LIB_roken) ${XLIBS}

readgroup.o: readgroup.c ${LINCLS} AFS_component_version_number.c

readpwd: readpwd.o libprot.a $(LIBS)
	$(AFS_LDRULE) readpwd.o libprot.a \
		${LIBS} $(LIB_roken) ${XLIBS}

readpwd.o: readpwd.c ${LINCLS} AFS_component_version_number.c

testpt: testpt.o libprot.a ${TOP_LIBDIR}/libcmd.a $(LIBS)
	case "$(SYS_NAME)" in \
	*_darwin_12 ) \
		$(AFS_LDRULE_NOQ) testpt.o ${TOP_LIBDIR}/libcmd.a \
			libprot.a $(LIBS) $(LIB_roken) ;; \
	* ) \
		$(AFS_LDRULE_NOQ) testpt.o -lm ${TOP_LIBDIR}/libcmd.a \
			libprot.a $(LIBS) $(LIB_roken) ${XLIBS} ;; \
	esac

testpt.o: testpt.c ${INCLS} ${TOP_INCDIR}/afs/cmd.h AFS_component_version_number.c

pt_util: pt_util.o ptutils.o ptubik.o utils.o map.o libprot.a $(LIBS)
	$(AFS_LDRULE) pt_util.o ptutils.o ptubik.o utils.o map.o libprot.a \
		${TOP_LIBDIR}/libcmd.a $(LIBS) $(LIB_roken) ${XLIBS}

ptubik.o: ptubik.c ${INCLS}

prerror.h: pterror.h
	${INSTALL_DATA} $? $@
	echo '#define ERROR_TABLE_BASE_pr ERROR_TABLE_BASE_PT' >> $@

#
# Installation targets
#
install: ptserver pts pt_util db_verify libprot.a ptclient.h pterror.h \
		ptint.h ptserver.h
	${INSTALL} -d ${DESTDIR}${afssrvlibexecdir}
	${INSTALL} -d ${DESTDIR}${afssrvbindir}
	${INSTALL} -d ${DESTDIR}${afssrvsbindir}
	${INSTALL} -d ${DESTDIR}${bindir}
	${INSTALL} -d ${DESTDIR}${libdir}/afs
	${INSTALL} -d ${DESTDIR}${includedir}/afs
	if [ "x$(ENABLE_PTHREADED_UBIK)" != "xyes" ] ; then \
		${INSTALL_PROGRAM} ptserver ${DESTDIR}${afssrvlibexecdir}/ptserver; \
		${INSTALL_PROGRAM} pts ${DESTDIR}${afssrvbindir}/pts; \
		${INSTALL_PROGRAM} pts ${DESTDIR}${bindir}/pts; \
		${INSTALL_PROGRAM} pt_util ${DESTDIR}${afssrvsbindir}/pt_util; \
		${INSTALL_PROGRAM} db_verify ${DESTDIR}${afssrvsbindir}/prdb_check; \
	fi
	${INSTALL_DATA} libprot.a ${DESTDIR}${libdir}/afs/libprot.a
	${INSTALL_DATA} ${srcdir}/ptclient.h ${DESTDIR}${includedir}/afs/prclient.h
	${INSTALL_DATA} pterror.h ${DESTDIR}${includedir}/afs/prerror.h
	${INSTALL_DATA} ptint.h ${DESTDIR}${includedir}/afs/print.h
	${INSTALL_DATA} ${srcdir}/ptserver.h ${DESTDIR}${includedir}/afs/prserver.h
	${INSTALL_DATA} ${srcdir}/ptclient.h ${DESTDIR}${includedir}/afs/ptclient.h
	${INSTALL_DATA} ${srcdir}/ptuser.h ${DESTDIR}${includedir}/afs/ptuser.h
	${INSTALL_DATA} pterror.h ${DESTDIR}${includedir}/afs/pterror.h
	${INSTALL_DATA} ptint.h ${DESTDIR}${includedir}/afs/ptint.h
	${INSTALL_DATA} ${srcdir}/ptserver.h ${DESTDIR}${includedir}/afs/ptserver.h

dest: ptserver pts pt_util db_verify libprot.a ptclient.h pterror.h \
		ptint.h ptserver.h
	${INSTALL} -d ${DEST}/root.server/usr/afs/bin
	${INSTALL} -d ${DEST}/bin
	${INSTALL} -d ${DEST}/etc
	${INSTALL} -d ${DEST}/lib/afs
	${INSTALL} -d ${DEST}/include/afs
	if [ "x$(ENABLE_PTHREADED_UBIK)" != "xyes" ] ; then \
		${INSTALL_PROGRAM} ptserver ${DEST}/root.server/usr/afs/bin/ptserver; \
		${INSTALL_PROGRAM} pts ${DEST}/root.server/usr/afs/bin/pts; \
		${INSTALL_PROGRAM} pts ${DEST}/bin/pts; \
		${INSTALL_PROGRAM} pt_util ${DEST}/root.server/usr/afs/bin/pt_util; \
		${INSTALL_PROGRAM} db_verify ${DEST}/etc/prdb_check; \
	fi;
	${INSTALL_DATA} libprot.a ${DEST}/lib/afs/libprot.a
	${INSTALL_DATA} ${srcdir}/ptclient.h ${DEST}/include/afs/prclient.h
	${INSTALL_DATA} pterror.h ${DEST}/include/afs/prerror.h
	${INSTALL_DATA} ptint.h ${DEST}/include/afs/print.h
	${INSTALL_DATA} ${srcdir}/ptserver.h ${DEST}/include/afs/prserver.h
	${INSTALL_DATA} ${srcdir}/ptclient.h ${DEST}/include/afs/ptclient.h
	${INSTALL_DATA} ${srcdir}/ptuser.h ${DEST}/include/afs/ptuser.h
	${INSTALL_DATA} pterror.h ${DEST}/include/afs/pterror.h
	${INSTALL_DATA} ptint.h ${DEST}/include/afs/ptint.h
	${INSTALL_DATA} ${srcdir}/ptserver.h ${DEST}/include/afs/ptserver.h

#
# Misc. targets
#
clean:
	$(LT_CLEAN)
	$(RM) -f *.a *.o ptserver ptint.cs.c ptint.ss.c ptclient ptint.xdr.c ptint.h \
	libprot.a pts readgroup readpwd db_verify testpt pt_util pterror.h pterror.c \
	core AFS_component_version_number.c Kptint.cs.c Kptint.h Kptint.xdr.c

include ../config/Makefile.version
