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

RX=$(srcdir)/../rx
BUDB=$(srcdir)/../budb

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)/budb_client.h

# library ordering defined by top level makefile
LIBS= \
	${TOP_LIBDIR}/libbubasics.a \
	$(top_builddir)/src/ubik/liboafs_ubik.la \
	$(top_builddir)/src/sys/liboafs_sys.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/opr/liboafs_opr.la \
	$(top_builddir)/src/util/liboafs_util.la

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_client.h budb_server ${INCLS}

budb_errs.c: ${BUDB}/budb_errs.et
	${COMPILE_ET_C} -p ${BUDB} budb_errs

budb_errs.h: ${BUDB}/budb_errs.et
	${COMPILE_ET_H} -p ${BUDB} 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

#
# Build targets
#

database.o: ${BUDB}/database.c budb_errs.h ${INCLS}
	$(AFS_CCRULE) $(BUDB)/database.c

db_alloc.o: ${BUDB}/db_alloc.c budb_errs.h ${INCLS}
	$(AFS_CCRULE) $(BUDB)/db_alloc.c

db_dump.o: ${BUDB}/db_dump.c budb_errs.h ${INCLS}
	$(AFS_CCRULE) $(BUDB)/db_dump.c

dbs_dump.o: ${BUDB}/dbs_dump.c budb_errs.h ${INCLS}
	$(AFS_CCRULE) $(BUDB)/dbs_dump.c

db_lock.o:  ${BUDB}/db_lock.c budb_errs.h ${INCLS}
	$(AFS_CCRULE) $(BUDB)/db_lock.c

db_text.o:  ${BUDB}/db_text.c budb_errs.h ${INCLS}
	$(AFS_CCRULE) $(BUDB)/db_text.c

db_hash.o: ${BUDB}/db_hash.c budb_errs.h ${INCLS}
	$(AFS_CCRULE) $(BUDB)/db_hash.c

ol_verify.o: ${BUDB}/ol_verify.c budb_errs.h ${INCLS}
	$(AFS_CCRULE) $(BUDB)/ol_verify.c

procs.o: ${BUDB}/procs.c budb_errs.h ${INCLS}
	$(AFS_CCRULE) $(BUDB)/procs.c

struct_ops.o: ${BUDB}/struct_ops.c budb_errs.h ${INCLS}
	$(AFS_CCRULE) $(BUDB)/struct_ops.c

server.o: ${BUDB}/server.c budb_errs.h ${INCLS}
	$(AFS_CCRULE) $(BUDB)/server.c

budb_server: $(SERVER_OBJS) ${LIBS}
	$(LT_LDRULE_static) $(SERVER_OBJS) ${LIBS} \
		$(LIB_hcrypto) $(LIB_roken) ${MT_LIBS}

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

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

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

budb.h: ${BUDB}/budb.rg
	${RXGEN} -u -h -o $@ ${BUDB}/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: budb_server
	if [ "x$(ENABLE_PTHREADED_UBIK)" = "xyes" ] ; then      \
	    ${LT_INSTALl_PROGRAM} budb_server                      \
		${DESTDIR}${afssrvlibexecdir}/buserver;         \
	fi

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

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

