# 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

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 vlclient.h vldbint.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}/libdes.a \
	${TOP_LIBDIR}/libcom_err.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/libafsutil.a

OBJS=vldbint.xdr.o vldbint.cs.o vl_errors.o


all: \
	vlserver vlclient cnvldb vlserver cnvldb vldb_check \
	Kvldbint.cs.c Kvldbint.xdr.c vldbint.h \
	${TOP_LIBDIR}/libvldb.a depinstall

depinstall: \
	Kvldbint.cs.c Kvldbint.xdr.c vldbint.h \
	${TOP_INCDIR}/afs/vl_opcodes.h \
	${TOP_INCDIR}/afs/vlserver.h \
	${TOP_INCDIR}/afs/vldbint.h \
	${TOP_INCDIR}/afs/cnvldb.h 

vldb_check: vldb_check.o ${LIBS}
	$(CC) ${CFLAGS} -o vldb_check vldb_check.o ${LIBS} ${XLIBS} 

vldb_check.o: vldb_check.c AFS_component_version_number.o

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

cnvldb.o: cnvldb.c cnvldb.h AFS_component_version_number.o

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

sascnvldb.o: sascnvldb.c cnvldb.h AFS_component_version_number.o

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

vlserver.o: vlserver.c ${INCLS} AFS_component_version_number.o
vlutils.o: vlutils.c ${INCLS}
vlprocs.o: vlprocs.c ${INCLS}
vldbint.ss.o: vldbint.ss.c vldbint.xdr.c
vldbint.cs.o: vldbint.cs.c vldbint.xdr.c
vldbint.xdr.o: vldbint.xdr.c vldbint.h

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

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

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

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

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

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

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

libvldb.a: $(OBJS) AFS_component_version_number.o
	$(RM) -f $@
	$(AR) crv $@ $(OBJS) AFS_component_version_number.o
	$(RANLIB) $@

vlclient: vlclient.o libvldb.a $(LIBS)
	$(CC) ${CFLAGS} -o vlclient vlclient.o libvldb.a $(LIBS) ${XLIBS} ${TOP_LIBDIR}/libcmd.a

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

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

system: install

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

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

${TOP_LIBDIR}/libvldb.a: libvldb.a
	${INSTALL} $? $@

${TOP_INCDIR}/afs/vl_opcodes.h: vl_opcodes.h
	${INSTALL} $? $@

${TOP_INCDIR}/afs/vlserver.h: vlserver.h
	${INSTALL} $? $@

${TOP_INCDIR}/afs/vldbint.h: vldbint.h
	${INSTALL} $? $@

${TOP_INCDIR}/afs/cnvldb.h: cnvldb.h
	${INSTALL} $? $@

install: \
	${DESTDIR}${afssrvlibexecdir}/vlserver \
	${DESTDIR}${afssrvsbindir}/vldb_convert \
	${DESTDIR}${libdir}/afs/libvldb.a \
	${DESTDIR}${includedir}/afs/vl_opcodes.h \
	${DESTDIR}${includedir}/afs/vlserver.h \
	${DESTDIR}${includedir}/afs/vldbint.h \
	${DESTDIR}${includedir}/afs/cnvldb.h \
	${DESTDIR}${afssrvsbindir}/vldb_check

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

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

${DESTDIR}${libdir}/afs/libvldb.a: libvldb.a
	${INSTALL} $? $@

${DESTDIR}${includedir}/afs/vl_opcodes.h: vl_opcodes.h
	${INSTALL} $? $@

${DESTDIR}${includedir}/afs/vlserver.h: vlserver.h
	${INSTALL} $? $@

${DESTDIR}${includedir}/afs/vldbint.h: vldbint.h
	${INSTALL} $? $@

${DESTDIR}${includedir}/afs/cnvldb.h: cnvldb.h
	${INSTALL} $? $@

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

dest: \
	${DEST}/root.server/usr/afs/bin/vlserver \
	${DEST}/etc/vldb_convert \
	${DEST}/lib/afs/libvldb.a \
	${DEST}/include/afs/vl_opcodes.h \
	${DEST}/include/afs/vlserver.h \
	${DEST}/include/afs/vldbint.h \
	${DEST}/include/afs/cnvldb.h \
	${DEST}/etc/vldb_check

${DEST}/lib/afs/libvldb.a: libvldb.a
	${INSTALL} $? $@

${DEST}/include/afs/vl_opcodes.h: vl_opcodes.h
	${INSTALL} $? $@

${DEST}/include/afs/vlserver.h: vlserver.h
	${INSTALL} $? $@

${DEST}/include/afs/vldbint.h: vldbint.h
	${INSTALL} $? $@

${DEST}/include/afs/cnvldb.h: cnvldb.h
	${INSTALL} $? $@

${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
