# 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
VLSERVER=$(srcdir)/../vlserver

RXOBJS= rx_pthread.o rxkad_errs.o

UTILOBJS=uuid.o serverLog.o fileutil.o dirpath.o \
     volparse.o flipbase64.o softsig.o hostparse.o pthread_glock.o \
     pthread_threadname.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 vldbint.h

LIBS=	${TOP_LIBDIR}/libubik_pthread.a \
	${TOP_LIBDIR}/libafsauthent.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/libafsrpc.a \
	${TOP_LIBDIR}/libafsutil.a \
	${TOP_LIBDIR}/libopr.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
	$(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...
#

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

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

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

#
# Other stuff
#


vldb_check: vldb_check.o ${LIBS} AFS_component_version_number.o
	$(AFS_LDRULE) vldb_check.o AFS_component_version_number.o \
		${LIBS} $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} ${XLIBS} 

vldb_check.o: ${VLSERVER}/vldb_check.c 
	$(AFS_CCRULE) $(VLSERVER)/vldb_check.c

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

cnvldb.o: ${VLSERVER}/cnvldb.c
	$(AFS_CCRULE) $(VLSERVER)/cnvldb.c

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

sascnvldb.o: ${VLSERVER}/sascnvldb.c
	$(AFS_CCRULE) $(VLSERVER)/sascnvldb.c

vlserver: vlserver.o vlutils.o vlprocs.o vldbint.ss.o vldbint.xdr.o $(LIBS)
	$(AFS_LDRULE) vlserver.o vlutils.o vlprocs.o vldbint.ss.o \
		vldbint.xdr.o \
		$(LIBS) $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} ${XLIBS} \
		${TOP_LIBDIR}/libaudit.a

vlserver.o: ${VLSERVER}/vlserver.c ${INCLS} AFS_component_version_number.o
	$(AFS_CCRULE) $(VLSERVER)/vlserver.c

vlutils.o: ${VLSERVER}/vlutils.c ${INCLS}
	$(AFS_CCRULE) $(VLSERVER)/vlutils.c

vlprocs.o: ${VLSERVER}/vlprocs.c ${INCLS}
	$(AFS_CCRULE) $(VLSERVER)/vlprocs.c

vldbint.ss.o: vldbint.ss.c 
vldbint.cs.o: vldbint.cs.c 
vldbint.xdr.o: vldbint.xdr.c 

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

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

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

vldbint.h: ${VLSERVER}/vldbint.xg
	${RXGEN} -A -u -x -h -o $@ ${srcdir}/${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} -A -x -k -C -o $@ ${srcdir}/${VLSERVER}/vldbint.xg

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

vlclient: vlclient.o $(OBJS) $(LIBS) ${INCLS}
	$(AFS_LDRULE) vlclient.o $(OBJS) ${TOP_LIBDIR}/libcmd.a \
		$(LIBS) $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} ${XLIBS}
		
vlclient.o: ${VLSERVER}/vlclient.c
	$(AFS_CCRULE) $(VLSERVER)/vlclient.c

vl_errors.o: vl_errors.c

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

system: install

install: vlserver cnvldb vldb_check
	if [ "x$(ENABLE_PTHREADED_UBIK)" = "xyes" ] ; then \
		${INSTALL_PROGRAM} vlserver ${DESTDIR}${afssrvlibexecdir}/vlserver; \
		${INSTALL_PROGRAM} cnvldb ${DESTDIR}${afssrvsbindir}/vldb_convert; \
		${INSTALL_PROGRAM} vldb_check ${DESTDIR}${afssrvsbindir}/vldb_check; \
	fi

dest: vlserver cnvldb vldb_check
	if [ "x$(ENABLE_PTHREADED_UBIK)" = "xyes" ] ; then \
		${INSTALL_PROGRAM} vlserver ${DEST}/root.server/usr/afs/bin/vlserver; \
		${INSTALL_PROGRAM} cnvldb ${DEST}/etc/vldb_convert; \
		${INSTALL_PROGRAM} vldb_check ${DEST}/etc/vldb_check; \
	fi

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