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

HELPER_SPLINT=@HELPER_SPLINT@
ENABLE_PTHREADED_UBIK=@ENABLE_PTHREADED_UBIK@

RX=$(srcdir)/../rx
UTIL=$(srcdir)/../util
PTSERVER=$(srcdir)/../ptserver

RXOBJS= rx_pthread.o rxkad_errs.o

UTILOBJS=uuid.o serverLog.o fileutil.o netutils.o dirpath.o \
     volparse.o flipbase64.o softsig.o hostparse.o pthread_glock.o \
     pthread_threadname.o

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 \
	ptint.h \
	pterror.h

LIBS=${RXOBJS} ${UTILOBJS}\
	${TOP_LIBDIR}/libubik_pthread.a \
	${TOP_LIBDIR}/libafsauthent.a \
	${TOP_LIBDIR}/libafsrpc.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/libopr.a \
	${TOP_LIBDIR}/libafsutil.a 

PTOBJS=ptuser.o pterror.o ptint.cs.o ptint.xdr.o

all: ptserver pts pt_util db_verify \
	depinstall readgroup readpwd testpt

depinstall: 

#
# Build targets
#

rx_pthread.o: ${RX}/rx_pthread.c
	$(AFS_CCRULE) $(RX)/rx_pthread.c

rxkad_errs.o: ../rxkad/rxkad_errs.c
	$(AFS_CCRULE) ../rxkad/rxkad_errs.c

#
# get the pthreaded util stuff compiled here.  we do this instead of
# using the non-pthreaded libutil.a.  There probably should be a
# pthreaded version of this library, as we are doing with ubik itself, but...
#

assert.o: ${UTIL}/assert.c
	$(AFS_CCRULE) $(UTIL)/assert.c

uuid.o: ${UTIL}/uuid.c
	$(AFS_CCRULE) $(UTIL)/uuid.c

serverLog.o: ${UTIL}/serverLog.c
	$(AFS_CCRULE) $(UTIL)/serverLog.c

fileutil.o: ${UTIL}/fileutil.c
	$(AFS_CCRULE) $(UTIL)/fileutil.c

volparse.o: ${UTIL}/volparse.c
	$(AFS_CCRULE) $(UTIL)/volparse.c

flipbase64.o: ${UTIL}/flipbase64.c
	$(AFS_CCRULE) $(UTIL)/flipbase64.c

netutils.o: ${UTIL}/netutils.c
	$(AFS_CCRULE) $(UTIL)/netutils.c

dirpath.o: ${UTIL}/dirpath.c
	$(AFS_CCRULE) $(UTIL)/dirpath.c

softsig.o: ${UTIL}/softsig.c
	$(AFS_CCRULE) $(UTIL)/softsig.c

hostparse.o: ${UTIL}/hostparse.c
	$(AFS_CCRULE) $(UTIL)/hostparse.c

pthread_glock.o: ${UTIL}/pthread_glock.c
	$(AFS_CCRULE) $(UTIL)/pthread_glock.c

pthread_threadname.o: ${UTIL}/pthread_threadname.c
	$(AFS_CCRULE) $(UTIL)/pthread_threadname.c

ptserver.o: ${PTSERVER}/ptserver.c ${INCLS}
	$(AFS_CCRULE) $(PTSERVER)/ptserver.c

ptutils.o: ${PTSERVER}/ptutils.c ${INCLS}
	$(AFS_CCRULE) $(PTSERVER)/ptutils.c

ptprocs.o: ${PTSERVER}/ptprocs.c ${INCLS}
	$(AFS_CCRULE) $(PTSERVER)/ptprocs.c

utils.o: ${PTSERVER}/utils.c ${INCLS}
	$(AFS_CCRULE) $(PTSERVER)/utils.c

map.o: ${PTSERVER}/map.c ${INCLS}
	$(AFS_CCRULE) $(PTSERVER)/map.c

ptint.ss.o: ptint.ss.c
ptint.cs.o: ptint.cs.c
ptint.xdr.o: ptint.xdr.c

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

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

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

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

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

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

display.o: ${PTSERVER}/display.c ${INCLS}
	${AFS_CCRULE} ${PTSERVER}/display.c

ptserver: ptserver.o ptutils.o ptprocs.o ptint.ss.o ptint.xdr.o utils.o $(LIBS) ${TOP_LIBDIR}/libaudit.a map.o
	$(AFS_LDRULE) ptserver.o ptutils.o ptprocs.o \
		ptint.ss.o ptint.xdr.o utils.o map.o \
		$(LIBS) $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} \
		${XLIBS} ${TOP_LIBDIR}/libaudit.a

db_verify.o: ${PTSERVER}/db_verify.c ${INCLS}
	$(AFS_CCRULE) $(PTSERVER)/db_verify.c

db_verify: db_verify.o pterror.o display.o $(LIBS)
	$(AFS_LDRULE) db_verify.o display.o pterror.o \
		$(LIBS) $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} ${XLIBS}

ptclient: ptclient.o display.o ptuser.o pterror.o ptint.cs.o ptint.xdr.o \
	AFS_component_version_number.o $(LIBS)
	$(AFS_LDRULE) ptclient.o display.o $(PTOBJS) \
		$(LIBS) $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} ${XLIBS}

ptclient.o: ${PTSERVER}/ptclient.c ${INCLS}
	$(AFS_CCRULE) $(PTSERVER)/ptclient.c

ptuser.o: ${PTSERVER}/ptuser.c ${INCLS}
	$(AFS_CCRULE) $(PTSERVER)/ptuser.c

pterror.h pterror.c: ${PTSERVER}/pterror.et
	$(RM) -f pterror.h pterror.c
	${COMPILE_ET} -p ${srcdir}/${PTSERVER} pterror

pts: pts.o $(PTOBJS) ${TOP_LIBDIR}/libcmd.a $(LIBS) ${INCLS}
	$(AFS_LDRULE) pts.o ${TOP_LIBDIR}/libcmd.a $(PTOBJS) \
		${LIBS} $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} ${XLIBS}

pts.o: ${PTSERVER}/pts.c
	$(AFS_CCRULE) $(PTSERVER)/pts.c

readgroup: readgroup.o $(PTOBJS) $(LIBS)
	$(AFS_LDRULE) readgroup.o $(PTOBJS) \
		${LIBS} $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} ${XLIBS}

readgroup.o: ${PTSERVER}/readgroup.c ${INCLS}
	$(AFS_CCRULE) $(PTSERVER)/readgroup.c

readpwd: readpwd.o $(PTOBJS) $(LIBS)
	$(AFS_LDRULE) readpwd.o $(PTOBJS) \
		${LIBS} $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} ${XLIBS}

readpwd.o: ${PTSERVER}/readpwd.c ${INCLS}
	$(AFS_CCRULE) $(PTSERVER)/readpwd.c

testpt: testpt.o $(PTOBJS) ${TOP_LIBDIR}/libcmd.a $(LIBS)
	$(AFS_LDRULE) testpt.o -lm ${TOP_LIBDIR}/libcmd.a $(PTOBJS) \
		$(LIBS) $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} ${XLIBS}

testpt.o: ${PTSERVER}/testpt.c ${INCLS}
	$(AFS_CCRULE) $(PTSERVER)/testpt.c

pt_util: pt_util.o ptutils.o ubik.o utils.o map.o $(PTOBJS) $(LIBS)
	$(AFS_LDRULE) pt_util.o ptutils.o ubik.o utils.o map.o $(PTOBJS) \
		${TOP_LIBDIR}/libcmd.a \
		$(LIBS) $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} ${XLIBS}

pt_util.o: ${PTSERVER}/pt_util.c
	$(AFS_CCRULE) $(PTSERVER)/pt_util.c

ubik.o: ${PTSERVER}/ubik.c ${INCLS}
	$(AFS_CCRULE) $(PTSERVER)/ubik.c

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

#
# Installation targets
#
install: ptserver pts pt_util db_verify
	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

dest: ptserver pts pt_util db_verify
	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

#
# Misc. targets
#
clean:
	$(RM) -f *.a *.o ptserver ptint.cs.c ptint.ss.c ptclient ptint.xdr.c ptint.h \
	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
