# 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


CCRULE=${MT_CC} ${CFLAGS} ${MT_CFLAGS} -c $?

RX=../rx
UTIL=../util
PTSERVER=../ptserver

RXOBJS= rx_pthread.o rxkad_errs.o

UTILOBJS=assert.o uuid.o serverLog.o fileutil.o netutils.o dirpath.o \
     volparse.o flipbase64.o softsig.o hostparse.o snprintf.o pthread_glock.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 \
	${PTSERVER}/ptserver.h \
	${PTSERVER}/ptclient.h \
	${PTSERVER}/ptuser.h \
	ptint.h \
	pterror.h \
	${PTSERVER}/map.h \
	${PTSERVER}/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 \
	${PTSERVER}/ptclient.h \
	${PTSERVER}/ptuser.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}/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
	${CCRULE}

rxkad_errs.o: ../rxkad/rxkad_errs.c
	${CCRULE}

#
# 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
	${CCRULE}

uuid.o: ${UTIL}/uuid.c
	${CCRULE}

serverLog.o: ${UTIL}/serverLog.c
	${CCRULE}

fileutil.o: ${UTIL}/fileutil.c
	${CCRULE}

volparse.o: ${UTIL}/volparse.c
	${CCRULE}

flipbase64.o: ${UTIL}/flipbase64.c
	${CCRULE}

netutils.o: ${UTIL}/netutils.c
	${CCRULE}

dirpath.o: ${UTIL}/dirpath.c
	${CCRULE}

softsig.o: ${UTIL}/softsig.c
	${CCRULE}

hostparse.o: ${UTIL}/hostparse.c
	${CCRULE}

snprintf.o: ${UTIL}/snprintf.c
	${CCRULE}

pthread_glock.o: ${UTIL}/pthread_glock.c
	${CCRULE}


ptserver.o: ${PTSERVER}/ptserver.c
	${CCRULE}

ptutils.o: ${PTSERVER}/ptutils.c
	${CCRULE}

ptprocs.o: ${PTSERVER}/ptprocs.c
	${CCRULE}

utils.o: ${PTSERVER}/utils.c
	${CCRULE}

map.o: ${PTSERVER}/map.c
	${CCRULE}

ptint.ss.o: ptint.ss.c
	${CCRULE}

ptint.cs.o: ptint.cs.c
	${CCRULE}

ptint.xdr.o: ptint.xdr.c
	${CCRULE}

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

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

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

ptint.h: ${PTSERVER}/ptint.xg
	${RXGEN} -x -h -u -o $@ ${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} -x -k -C -o Kptint.cs.c ${PTSERVER}/ptint.xg
 
Kptint.xdr.c: ${PTSERVER}/ptint.xg
	${RXGEN} -x -k -c -o Kptint.xdr.c ${PTSERVER}/ptint.xg
 
Kptint.h: ${PTSERVER}/ptint.xg
	${RXGEN} -x -k -h -o Kptint.h ${PTSERVER}/ptint.xg

display.o: ${PTSERVER}/display.c
	${CCRULE}

ptserver: ptserver.o ptutils.o ptprocs.o ptint.ss.o ptint.xdr.o utils.o $(LIBS) ${TOP_LIBDIR}/libaudit.a map.o
	${CC} ${LDFLAGS} -o ptserver ptserver.o ptutils.o ptprocs.o ptint.ss.o ptint.xdr.o utils.o map.o $(LIBS) ${MT_LIBS} ${XLIBS} ${TOP_LIBDIR}/libaudit.a

db_verify.o: ${PTSERVER}/db_verify.c
	${CCRULE}

db_verify: db_verify.o pterror.o display.o $(LIBS)
	$(CC) ${LDFLAGS} -o db_verify db_verify.o display.o pterror.o $(LIBS) ${MT_LIBS} ${XLIBS}

ptclient: ptclient.o display.o ptuser.o pterror.o ptint.cs.o ptint.xdr.o AFS_component_version_number.o $(LIBS)
	$(CC) ${LDFLAGS} -o ptclient ptclient.o display.o $(PTOBJS) $(LIBS) ${MT_LIBS} ${XLIBS}

ptclient.o: ${PTSERVER}/ptclient.c
	${CCRULE}

ptuser.o: ${PTSERVER}/ptuser.c
	${CCRULE}

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

pts: pts.o $(PTOBJS) ${TOP_LIBDIR}/libcmd.a $(LIBS)
	$(CC) ${LDFLAGS} -o pts pts.o ${TOP_LIBDIR}/libcmd.a $(PTOBJS) ${LIBS} ${MT_LIBS} ${XLIBS}

pts.o: ${PTSERVER}/pts.c
	${CCRULE}

readgroup: readgroup.o $(PTOBJS) $(LIBS)
	$(CC) ${CFLAGS} -o readgroup readgroup.o $(PTOBJS) ${LIBS} ${MT_LIBS} ${XLIBS}

readgroup.o: ${PTSERVER}/readgroup.c
	${CCRULE}

readpwd: readpwd.o $(PTOBJS) $(LIBS)
	$(CC) ${CFLAGS} -o readpwd readpwd.o $(PTOBJS) ${LIBS} ${MT_LIBS} ${XLIBS}

readpwd.o: ${PTSERVER}/readpwd.c
	${CCRULE}

testpt: testpt.o $(PTOBJS) ${TOP_LIBDIR}/libcmd.a $(LIBS)
	$(CC) ${CFLAGS} -o testpt testpt.o -lm ${TOP_LIBDIR}/libcmd.a $(PTOBJS) $(LIBS) ${MT_LIBS} ${XLIBS}

testpt.o: ${PTSERVER}/testpt.c
	${CCRULE}

pt_util: pt_util.o ptutils.o ubik.o utils.o map.o $(PTOBJS) $(LIBS)
	$(CC) ${CFLAGS} -o pt_util pt_util.o ptutils.o ubik.o utils.o map.o $(PTOBJS) ${TOP_LIBDIR}/libcmd.a $(LIBS) ${MT_LIBS} ${XLIBS}

pt_util.o: ${PTSERVER}/pt_util.c
	${CCRULE}

ubik.o: ${PTSERVER}/ubik.c
	${CCRULE}

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

#
# Installation targets
#
install: \
	${DESTDIR}${afssrvlibexecdir}/ptserver \
	${DESTDIR}${afssrvbindir}/pts \
	${DESTDIR}${bindir}/pts \
	${DESTDIR}${afssrvsbindir}/pt_util \
	${DESTDIR}${afssrvsbindir}/prdb_check 

${DEST}/root.server/usr/afs/bin/ptserver: ptserver
	${INSTALL} $? $@

${DEST}/bin/pts ${DEST}/root.server/usr/afs/bin/pts: pts
	${INSTALL} $? $@

${DEST}/root.server/usr/afs/bin/pt_util: pt_util
	${INSTALL} $? $@

${DEST}/etc/prdb_check: db_verify
	${INSTALL} -f $? $@

#
# 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
${DESTDIR}${afssrvlibexecdir}/ptserver: ptserver
	${INSTALL} $? $@

${DESTDIR}${afssrvbindir}/pts: pts
	${INSTALL} $? $@

${DESTDIR}${bindir}/pts: pts
	${INSTALL} $? $@

${DESTDIR}${afssrvsbindir}/pt_util: pt_util
	${INSTALL} $? $@

${DESTDIR}${afssrvsbindir}/prdb_check: db_verify
	${INSTALL} -f $? $@

dest: \
	${DEST}/root.server/usr/afs/bin/ptserver \
	${DEST}/root.server/usr/afs/bin/pts \
	${DEST}/bin/pts \
	${DEST}/root.server/usr/afs/bin/pt_util \
	${DEST}/etc/prdb_check