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

VLSERVER=$(srcdir)/../vlserver

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_common = \
	$(top_builddir)/src/ubik/liboafs_ubik.la \
	$(top_builddir)/src/sys/liboafs_sys.la \
	$(top_builddir)/src/rx/liboafs_rx.la \
	$(top_builddir)/src/rxstat/liboafs_rxstat.la \
	$(top_builddir)/src/rxkad/liboafs_rxkad.la \
	$(top_builddir)/src/lwp/liboafs_lwpcompat.la \
	$(top_builddir)/src/cmd/liboafs_cmd.la \
	$(top_builddir)/src/util/liboafs_util.la \
	$(top_builddir)/src/opr/liboafs_opr.la

LIBS_server= \
	$(top_builddir)/src/rxstat/liboafs_rxstat.la \
	$(top_builddir)/src/audit/liboafs_audit.la \
	$(LIBS_common)

LIBS_client= \
	$(top_builddir)/src/vlserver/liboafs_vldb.la \
	$(LIBS_common)

all: \
	vlserver vlclient vlserver cnvldb vldb_check vldbint.h

depinstall:

#
# Other stuff
#

vldb_check: vldb_check.o AFS_component_version_number.o $(LIBS_client)
	$(LT_LDRULE_static) vldb_check.o AFS_component_version_number.o \
		$(LIBS_client) $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS}

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

cnvldb: cnvldb.o $(LIBS_client)
	$(LT_LDRULE_static) cnvldb.o \
		$(LIBS_client) $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS}

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

sascnvldb: sascnvldb.o $(LIBS_client)
	$(LT_LDRULE_static) sascnvldb.o \
		$(LIBS_client) $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS}

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

vlserver: vlserver.o vlutils.o vlprocs.o vldbint.ss.o vldbint.xdr.o $(LIBS_server)
	$(LT_LDRULE_static) vlserver.o vlutils.o vlprocs.o vldbint.ss.o \
		vldbint.xdr.o \
		$(LIBS_server) $(LIB_hcrypto) $(LIB_roken) ${MT_LIBS}

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.xdr.o: vldbint.xdr.c


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

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

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

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

vlclient: vlclient.o $(LIBS_client)
	$(LT_LDRULE_static) vlclient.o $(LIBS_client) \
		$(LIB_roken) ${MT_LIBS}

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

vl_errors.o: vl_errors.c

vl_errors.c: ${VLSERVER}/vl_errors.et
	${COMPILE_ET_C} -p ${VLSERVER} vl_errors

vlserver.h: ${VLSERVER}/vl_errors.et ${VLSERVER}/vlserver.p.h
	${COMPILE_ET_H} -p ${VLSERVER} vl_errors -h vlserver

cnvldb.o cnvldb.lo: vlserver.h
vlclient.o vlclient.lo: vlserver.h
vldb_check.o vldb_check.lo: vlserver.h
vlprocs.o vlprocs.lo: vlserver.h
vlserver.o vlserver.lo: vlserver.h
vlutils.o vlutils.lo: vlserver.h

system: install

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

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

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

clean:
	$(LT_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
