# 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
UTIL=$(srcdir)/../util
BUDB=$(srcdir)/../budb

RXOBJS= rx_pthread.o rxkad_errs.o

UTILOBJS=uuid.o serverLog.o fileutil.o netutils.o dirpath.o \
     volparse.o flipbase64.o softsig.o hostparse.o pthread_glock.o


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=${RXOBJS} ${UTILOBJS} \
	${TOP_LIBDIR}/libbubasics.a \
	${TOP_LIBDIR}/libubik_pthread.a \
	${TOP_LIBDIR}/libafsauthent.a \
	${TOP_LIBDIR}/libafsrpc.a \
	${TOP_LIBDIR}/libcmd.a \
	$(TOP_LIBDIR)/libopr.a \
	${TOP_LIBDIR}/libafsutil.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_client.h budb_server ${INCLS}

budb_errs.h: budb_errs.c

budb_errs.c: ${BUDB}/budb_errs.et
	$(RM) -f budb_errs.c
	${COMPILE_ET} -p ${srcdir}/${BUDB} budb_errs

#
# Build targets
#

rx_pthread.o: ${RX}/rx_pthread.c
	$(AFS_CCRULE) $(RX)/rx_pthread.c

rxkad_errs.o: ../rxkad/rxkad_errs.c
	$(AFS_CCRULE) ../rxkad/rxkad_errs.c

# get the pthreaded util stuff compiled here.  we do this instead of
# using the non-pthreaded libutil.a.  There probably should be a
# pthreaded version of this library, as we are doing with ubik itself, but...
#

uuid.o: ${UTIL}/uuid.c
	$(AFS_CCRULE) $(UTIL)/uuid.c

serverLog.o: ${UTIL}/serverLog.c
	$(AFS_CCRULE) $(UTIL)/serverLog.c

fileutil.o: ${UTIL}/fileutil.c
	$(AFS_CCRULE) $(UTIL)/fileutil.c

volparse.o: ${UTIL}/volparse.c
	$(AFS_CCRULE) $(UTIL)/volparse.c

flipbase64.o: ${UTIL}/flipbase64.c
	$(AFS_CCRULE) $(UTIL)/flipbase64.c

netutils.o: ${UTIL}/netutils.c
	$(AFS_CCRULE) $(UTIL)/netutils.c

dirpath.o: ${UTIL}/dirpath.c
	$(AFS_CCRULE) $(UTIL)/dirpath.c

softsig.o: ${UTIL}/softsig.c
	$(AFS_CCRULE) $(UTIL)/softsig.c

hostparse.o: ${UTIL}/hostparse.c
	$(AFS_CCRULE) $(UTIL)/hostparse.c

pthread_glock.o: ${UTIL}/pthread_glock.c
	$(AFS_CCRULE) $(UTIL)/pthread_glock.c

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
	$(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}
	$(AFS_LDRULE) $(SERVER_OBJS) ${LIBS} \
		$(LIB_hcrypto) $(LIB_roken) ${MT_LIBS} ${XLIBS}

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

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

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

budb.h: ${BUDB}/budb.rg
	${RXGEN} -u -h -o $@ ${srcdir}/${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      \
	    ${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:
	$(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

