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


INCLS=\
	${TOP_INCDIR}/lock.h \
	${TOP_INCDIR}/ubik.h \
	${TOP_INCDIR}/lwp.h \
	${TOP_INCDIR}/rx/rx.h \
	${TOP_INCDIR}/rx/xdr.h \
	${TOP_INCDIR}/rx/rxkad.h \
	${TOP_INCDIR}/afs/auth.h \
	${TOP_INCDIR}/afs/cellconfig.h \
	${TOP_INCDIR}/afs/com_err.h \
	${TOP_INCDIR}/afs/bubasics.h \
	${TOP_INCDIR}/afs/budb_client.h \
	${TOP_INCDIR}/afs/budb_errs.h \
	budb.h budb_client.h database.h

# library ordering defined by top level makefile
LIBS=${TOP_LIBDIR}/libbubasics.a \
	${TOP_LIBDIR}/libaudit.a \
	${TOP_LIBDIR}/libprot.a \
	${TOP_LIBDIR}/libkauth.a \
	${TOP_LIBDIR}/libubik.a \
	${TOP_LIBDIR}/libauth.a \
	${TOP_LIBDIR}/librxkad.a \
	${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/librx.a \
	${TOP_LIBDIR}/libsys.a \
	${TOP_LIBDIR}/liblwp.a \
	${TOP_LIBDIR}/libcmd.a \
	${TOP_LIBDIR}/libafscom_err.a \
	${TOP_LIBDIR}/util.a \
	${TOP_LIBDIR}/libopr.a \
	${TOP_LIBDIR}/libafsrfc3961.a \
	${TOP_LIBDIR}/libafshcrypto_lwp.a

COMMON_OBJS = database.o db_alloc.o db_dump.o db_hash.o struct_ops.o ol_verify.o

SERVER_OBJS = ${COMMON_OBJS} budb.ss.o budb.xdr.o dbs_dump.o db_lock.o db_text.o \
	procs.o server.o budb_errs.o

all: ${TOP_LIBDIR}/libbudb.a ${TOP_INCDIR}/afs/budb.h ${TOP_INCDIR}/afs/budb_errs.h ${TOP_INCDIR}/afs/budb_prototypes.h budb_server

generated: \
	budb_errs.c budb_errs.h \
	budb.cs.c budb.ss.c budb.xdr.c budb.h

${TOP_LIBDIR}/libbudb.a: libbudb.a
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/budb.h: budb.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/budb_errs.h: budb_errs.h
	${INSTALL_DATA} budb_errs.h $@

${TOP_INCDIR}/afs/budb_client.h: budb_client.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/budb_prototypes.h: budb_prototypes.h
	${INSTALL_DATA} $? $@

budb_errs.c: budb_errs.et
	${COMPILE_ET_C} -p ${srcdir} budb_errs

budb_errs.h: budb_errs.et
	${COMPILE_ET_H} -p ${srcdir} budb_errs

database.o: budb_errs.h
db_alloc.o: budb_errs.h
db_dump.o: budb_errs.h
db_hash.o: budb_errs.h
db_lock.o: budb_errs.h
dbs_dump.o: budb_errs.h
db_text.o: budb_errs.h
ol_verify.o: budb_errs.h
procs.o: budb_errs.h
server.o: budb_errs.h
struct_ops.o: budb_errs.h

database.o: database.c budb_errs.h globals.h ${INCLS}
db_alloc.o: db_alloc.c budb_errs.h ${INCLS}
dbs_dump.o: dbs_dump.c budb_errs.h ${INCLS}
db_dump.o: db_dump.c budb_errs.h ${INCLS}
db_lock.o:  db_lock.c budb_errs.h ${INCLS}
db_text.o:  db_text.c budb_errs.h ${INCLS}
db_hash.o: db_hash.c budb_errs.h ${INCLS}
ol_verify.o:	ol_verify.c budb_errs.h ${INCLS}
procs.o: procs.c budb_errs.h globals.h ${INCLS}
struct_ops.o: budb_errs.h ${INCLS}
server.o: server.c budb_errs.h ${INCLS} AFS_component_version_number.c

budb_server: $(SERVER_OBJS) ${LIBS} ${TOP_INCDIR}/afs/budb_client.h
	$(AFS_LDRULE) $(SERVER_OBJS) ${LIBS} $(LIB_roken) ${XLIBS}

budb.cs.c: budb.rg
	${RXGEN} -A -u -C -o $@ ${srcdir}/budb.rg

budb.ss.c: budb.rg
	${RXGEN} -A -S -o $@ ${srcdir}/budb.rg

budb.xdr.c: budb.rg
	${RXGEN} -A -c -o $@ ${srcdir}/budb.rg

budb.h: budb.rg
	${RXGEN} -A -u -h -o $@ ${srcdir}/budb.rg

budb.cs.c: budb.h
budb.xdr.c: budb.h
budb.ss.c: budb.h

libbudb.a: budb_errs.o budb.cs.o budb.xdr.o struct_ops.o AFS_component_version_number.o
	-$(RM) -f $@
	$(AR) crv $@ budb_errs.o budb.cs.o budb.xdr.o struct_ops.o AFS_component_version_number.o
	$(RANLIB) $@

#
# Install targets
#
install: libbudb.a budb.h budb_errs.h budb_client.h budb_server
	${INSTALL} -d ${DESTDIR}${libdir}/afs
	${INSTALL} -d ${DESTDIR}${includedir}/afs
	${INSTALL} -d ${DESTDIR}${afssrvlibexecdir}
	${INSTALL_DATA} libbudb.a ${DESTDIR}${libdir}/afs/libbudb.a
	${INSTALL_DATA} budb.h ${DESTDIR}${includedir}/afs/budb.h
	${INSTALL_DATA} budb_errs.h ${DESTDIR}${includedir}/afs/budb_errs.h
	${INSTALL_DATA} ${srcdir}/budb_client.h ${DESTDIR}${includedir}/afs/budb_client.h
	${INSTALL_PROGRAM} budb_server ${DESTDIR}${afssrvlibexecdir}/buserver

dest: libbudb.a budb.h budb_errs.h budb_client.h budb_server
	${INSTALL} -d ${DEST}/lib/afs
	${INSTALL} -d ${DEST}/include/afs
	${INSTALL} -d ${DEST}/root.server/usr/afs/bin
	${INSTALL_DATA} libbudb.a ${DEST}/lib/afs/libbudb.a
	${INSTALL_DATA} budb.h ${DEST}/include/afs/budb.h
	${INSTALL_DATA} budb_errs.h ${DEST}/include/afs/budb_errs.h
	${INSTALL_DATA} ${srcdir}/budb_client.h ${DEST}/include/afs/budb_client.h
	${INSTALL_PROGRAM} budb_server ${DEST}/root.server/usr/afs/bin/buserver

#
# Misc targets
#
clean:
	$(RM) -f *.o *~ budb_errs.[ch] budb.h *.a *.xdr.c \
		*.ss.c *.cs.c core budb_server AFS_component_version_number.c

include ../config/Makefile.version
