# 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

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

RX=../rx
UTIL=../util
VLSERVER=../vlserver

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 get_krbrlm.o

INCLS=${TOP_INCDIR}/ubik.h \
             ${TOP_INCDIR}/lwp.h \
             ${TOP_INCDIR}/lock.h  \
             ${TOP_INCDIR}/rx/rx.h \
             ${TOP_INCDIR}/rx/xdr.h \
             ${TOP_INCDIR}/afs/keys.h \
             ${TOP_INCDIR}/afs/cellconfig.h \
	vlserver.h ${VLSERVER}/vlclient.h vldbint.h

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

OBJS=vldbint.xdr.o vldbint.cs.o vl_errors.o ${RXOBJS} ${UTILOBJS} 


all: \
	vlserver vlclient vlserver cnvldb vldb_check \
	Kvldbint.cs.c Kvldbint.xdr.c vldbint.h 

depinstall:

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}

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

#
# Other stuff
#


vldb_check: vldb_check.o ${LIBS} AFS_component_version_number.o
	$(CC) ${LDFLAGS} -o vldb_check vldb_check.o AFS_component_version_number.o ${LIBS} ${MT_LIBS} ${XLIBS} 

vldb_check.o: ${VLSERVER}/vldb_check.c 
	${CCRULE}

cnvldb: cnvldb.o ${LIBS} 
	$(CC) ${LDFLAGS} -o cnvldb cnvldb.o ${LIBS} ${MT_LIBS} ${XLIBS}

cnvldb.o: ${VLSERVER}/cnvldb.c
	${CCRULE}

sascnvldb: sascnvldb.o ${LIBS} 
	$(CC) ${LDFLAGS} -o sascnvldb sascnvldb.o ${LIBS} ${MT_LIBS} ${XLIBS}

sascnvldb.o: ${VLSERVER}/sascnvldb.c
	${CCRULE}

vlserver: vlserver.o vlutils.o vlprocs.o vldbint.ss.o vldbint.xdr.o $(LIBS)
	$(CC) ${LDFLAGS} -o vlserver vlserver.o vlutils.o vlprocs.o vldbint.ss.o \
		vldbint.xdr.o $(LIBS) ${MT_LIBS} ${XLIBS} ${TOP_LIBDIR}/libaudit.a

vlserver.o: ${VLSERVER}/vlserver.c 
	${CCRULE}

vlutils.o: ${VLSERVER}/vlutils.c 
	${CCRULE}

vlprocs.o: ${VLSERVER}/vlprocs.c 
	${CCRULE}

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

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

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

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

vldbint.ss.c: ${VLSERVER}/vldbint.xg
	${RXGEN} -x -S -o $@ ${VLSERVER}/vldbint.xg

vldbint.xdr.c: ${VLSERVER}/vldbint.xg
	${RXGEN} -x -c -o $@ ${VLSERVER}/vldbint.xg

vldbint.h: ${VLSERVER}/vldbint.xg
	${RXGEN} -u -x -h -o $@ ${VLSERVER}/vldbint.xg

vldbint.cs.c: vldbint.h
vldbint.ss.c: vldbint.h
vldbint.xdr.c: vldbint.h

Kvldbint.cs.c: ${VLSERVER}/vldbint.xg
	${RXGEN} -x -k -C -o $@ ${VLSERVER}/vldbint.xg

Kvldbint.xdr.c: ${VLSERVER}/vldbint.xg
	${RXGEN} -x -k -c -o $@ ${VLSERVER}/vldbint.xg

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

vlclient.o: ${VLSERVER}/vlclient.c
	${CCRULE}

vl_errors.o: vl_errors.c
	${CCRULE}

vlserver.h vl_errors.c: ${VLSERVER}/vl_errors.et ${VLSERVER}/vlserver.p.h
	$(RM) -f vlserver.h vl_errors.c; ${COMPILE_ET} -p ${VLSERVER} vl_errors -h vlserver

system: install

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

${DEST}/etc/vldb_convert: cnvldb
	${INSTALL} -f $? $@

install: \
	${DESTDIR}${afssrvlibexecdir}/vlserver \
	${DESTDIR}${afssrvsbindir}/vldb_convert \
	${DESTDIR}${afssrvsbindir}/vldb_check

${DESTDIR}${afssrvlibexecdir}/vlserver: vlserver
	${INSTALL} $? $@

${DESTDIR}${afssrvsbindir}/vldb_convert: cnvldb
	${INSTALL} -f $? $@

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

dest: \
	${DEST}/root.server/usr/afs/bin/vlserver \
	${DEST}/etc/vldb_convert \
	${DEST}/etc/vldb_check

${DEST}/etc/vldb_check: vldb_check
	${INSTALL} $? $@

#
# Misc targets
#
include ../config/Makefile.version

clean:
	$(RM) -f *.o *.a *.otl *.xdr.c *.cs.c *.ss.c core \
		vlserver vlclient cnvldb vldbint.h vlserver.h vldb_check \
		vl_errors.c AFS_component_version_number.c
