# 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

DEST=@DEST@
TOP_INCDIR=@TOP_INCDIR@
TOP_LIBDIR=@TOP_LIBDIR@
prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@
sbindir=@sbindir@
libexecdir=@libexecdir@
libdir=@libdir@
includedir=@includedir@
mandir=@mandir@
afssrvbindir=@afssrvbindir@
afssrvsbindir=@afssrvsbindir@
afssrvlibexecdir=@afssrvlibexecdir@
TOP_SRCDIR=@TOP_SRCDIR@
SYS_NAME=@AFS_SYSNAME@

SHELL = /bin/sh

include ../config/Makefile.${SYS_NAME}

KERNELDIR=../libafs/
UKERNELDIR=../libuafs/
COMPILE_ET=${TOP_SRCDIR}/comerr/compile_et

CFLAGS=${DBUG} -I. -I.. -I${TOP_SRCDIR}/config -I${TOP_INCDIR} ${XCFLAGS}
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}/util.a \
	${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/util.a

auditlib=${TOP_LIBDIR}/libaudit.a

RXGEN=${TOP_SRCDIR}/rxgen/rxgen
KSRCS=Kvldbint.cs.c Kvldbint.xdr.c vl_opcodes.h vldbint.h
UKSRCS=$(KSRCS)

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

CDIR=../../../src/vlserver
include ../config/Makefile.version

noversion: install

all: kinstall ukinstall \
	vlserver vlclient cnvldb vlserver cnvldb vldb_check \
	${TOP_LIBDIR}/libvldb.a \
	${TOP_INCDIR}/afs/vl_opcodes.h \
	${TOP_INCDIR}/afs/vlserver.h \
	${TOP_INCDIR}/afs/vldbint.h \
	${TOP_INCDIR}/afs/cnvldb.h

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

vldb_check: vldb_check.c
	$(CC) ${CFLAGS} -o vldb_check vldb_check.c ${XLIBS} \
		${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/util.a

cnvldb: cnvldb.o 
	$(CC) ${CFLAGS} -o cnvldb cnvldb.o ${XLIBS} ${TOP_LIBDIR}/libcmd.a\
		 ${TOP_LIBDIR}/util.a		 

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

sascnvldb: sascnvldb.o 
	$(CC) ${CFLAGS} -o sascnvldb sascnvldb.o ${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} ${auditlib}

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.ss.c vldbint.cs.c vldbint.xdr.c vldbint.h: vldbint.xg
	${RXGEN} -x vldbint.xg

Kvldbint.cs.c: vldbint.xg
	${RXGEN} -x -k -C -o $@ vldbint.xg
Kvldbint.xdr.c: vldbint.xg
	${RXGEN} -x -k -c -o $@ 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} vl_errors -h vlserver

system: install

kinstall: $(KSRCS)
	${INSTALL} $(KSRCS) ${KERNELDIR}/afsint

ukinstall webinstall: ${UKERNELDIR}/afsint $(UKSRCS)
	${INSTALL} $(UKSRCS) ${UKERNELDIR}/afsint

${UKERNELDIR}/afsint:
	mkdir -p $@

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

libinstall: \
	${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}${afssrvlibexecdir}/vlserver: vlserver
	${INSTALL} $? $@

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

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

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


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


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

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


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


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

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


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


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

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


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


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

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


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


${DEST}/etc/vldb_check: vldb_check
	${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
