# 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
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
HELPER_SPLINT=@HELPER_SPLINT@

CCRULE=${MT_CC} ${CFLAGS} ${MT_CFLAGS} -c

RX=../rx
UTIL=../util
BUDB=../budb

RXOBJS= rx_pthread.o rxkad_errs.o

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


INCLS=\
	${TOP_INCDIR}/lock.h \
	${TOP_INCDIR}/ubik.h \
	${TOP_INCDIR}/lwp.h \
	${TOP_INCDIR}/des.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}/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
	${CCRULE} ${srcdir}/${RX}/rx_pthread.c

rxkad_errs.o: ../rxkad/rxkad_errs.c
	${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...
#

assert.o: ${UTIL}/assert.c
	${CCRULE} ${srcdir}/${UTIL}/assert.c

uuid.o: ${UTIL}/uuid.c
	${CCRULE} ${srcdir}/${UTIL}/uuid.c

serverLog.o: ${UTIL}/serverLog.c
	${CCRULE} ${srcdir}/${UTIL}/serverLog.c

fileutil.o: ${UTIL}/fileutil.c
	${CCRULE} ${srcdir}/${UTIL}/fileutil.c

volparse.o: ${UTIL}/volparse.c
	${CCRULE} ${srcdir}/${UTIL}/volparse.c

flipbase64.o: ${UTIL}/flipbase64.c
	${CCRULE} ${srcdir}/${UTIL}/flipbase64.c

netutils.o: ${UTIL}/netutils.c
	${CCRULE} ${srcdir}/${UTIL}/netutils.c

dirpath.o: ${UTIL}/dirpath.c
	${CCRULE} ${srcdir}/${UTIL}/dirpath.c

softsig.o: ${UTIL}/softsig.c
	${CCRULE} ${srcdir}/${UTIL}/softsig.c

hostparse.o: ${UTIL}/hostparse.c
	${CCRULE} ${srcdir}/${UTIL}/hostparse.c

snprintf.o: ${UTIL}/snprintf.c
	${CCRULE} ${srcdir}/${UTIL}/snprintf.c

pthread_glock.o: ${UTIL}/pthread_glock.c
	${CCRULE} ${srcdir}/${UTIL}/pthread_glock.c


database.o: ${BUDB}/database.c budb_errs.h ${INCLS}
	${CCRULE} ${srcdir}/${BUDB}/database.c

db_alloc.o: ${BUDB}/db_alloc.c budb_errs.h ${INCLS}
	${CCRULE} ${srcdir}/${BUDB}/db_alloc.c

db_dump.o: ${BUDB}/db_dump.c
	${CCRULE} ${srcdir}/${BUDB}/db_dump.c

dbs_dump.o: ${BUDB}/dbs_dump.c budb_errs.h ${INCLS}
	${CCRULE} ${srcdir}/${BUDB}/dbs_dump.c

db_lock.o:  ${BUDB}/db_lock.c budb_errs.h ${INCLS}
	${CCRULE} ${srcdir}/${BUDB}/db_lock.c

db_text.o:  ${BUDB}/db_text.c budb_errs.h ${INCLS}
	${CCRULE} ${srcdir}/${BUDB}/db_text.c

db_hash.o: ${BUDB}/db_hash.c budb_errs.h ${INCLS}
	${CCRULE} ${srcdir}/${BUDB}/db_hash.c

ol_verify.o: ${BUDB}/ol_verify.c budb_errs.h ${INCLS}
	${CCRULE} ${srcdir}/${BUDB}/ol_verify.c

procs.o: ${BUDB}/procs.c budb_errs.h ${INCLS}
	${CCRULE} ${srcdir}/${BUDB}/procs.c

struct_ops.o: ${BUDB}/struct_ops.c budb_errs.h ${INCLS}
	${CCRULE} ${srcdir}/${BUDB}/struct_ops.c

server.o: ${BUDB}/server.c budb_errs.h ${INCLS}
	${CCRULE} ${srcdir}/${BUDB}/server.c


budb_server: $(SERVER_OBJS) ${LIBS}
	${CC} ${LDFLAGS} -o budb_server $(SERVER_OBJS) ${LIBS} ${MT_LIBS} ${XLIBS} ${KRB5_LIBS}

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: \
	${DESTDIR}${afssrvlibexecdir}/buserver

${DEST}/root.server/usr/afs/bin/buserver: budb_server
	${INSTALL_PROGRAM} $? $@

#
# 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
${DESTDIR}${afssrvlibexecdir}/buserver: budb_server
	${INSTALL_PROGRAM} $? $@

dest: \
	${DEST}/root.server/usr/afs/bin/buserver

